Lines Matching refs:hp

71 #define hist_ind(hp,c)	((int)((c)&(hp)->histmask))
133 static int acctinit(History_t *hp)
136 Namval_t *np = nv_search("ACCTFILE",((Shell_t*)hp->histshell)->var_tree,0);
178 static int sh_checkaudit(History_t *hp, const char *name, char *logbuf, size_t len)
180 Shell_t *shp = (Shell_t*)hp->histshell;
232 register History_t *hp;
252 if(hp=wasopen)
256 shp->hist_ptr = hist_ptr = hp;
257 if(strcmp(histname,hp->histname)==0)
310 if(!(hp=new_of(History_t,(--histmask)*sizeof(off_t))))
315 shp->hist_ptr = hist_ptr = hp;
316 hp->histshell = (void*)shp;
317 hp->histsize = maxlines;
318 hp->histmask = histmask;
319 hp->histfp= sfnew(NIL(Sfio_t*),hp->histbuff,HIST_BSIZE,fd,SF_READ|SF_WRITE|SF_APPENDWR|SF_SHARE);
320 memset((char*)hp->histcmds,0,sizeof(off_t)*(hp->histmask+1));
321 hp->histind = 1;
322 hp->histcmds[1] = 2;
323 hp->histcnt = 2;
324 hp->histname = strdup(histname);
325 hp->histdisc = hist_disc;
329 sfwrite(hp->histfp,(char*)hist_stamp,2);
330 sfsync(hp->histfp);
337 hp->histind = first = hist_nearend(hp,hp->histfp,hsize-size);
338 hist_eof(hp); /* this sets histind to last command */
339 if((hist_start = (last=(int)hp->histind)-maxlines) <=0)
341 mark = hp->histmarker;
345 first = hist_nearend(hp,hp->histfp,hsize-size);
346 hp->histind = first;
349 hist_eof(hp);
352 sfseek(hp->histfp,hp->histcnt=hsize,SEEK_SET);
353 hp->histind = last;
354 hp->histmarker = mark;
369 hp = hist_trim(hp,(int)hp->histind-maxlines);
371 sfdisc(hp->histfp,&hp->histdisc);
373 (HISTCUR)->nvalue.lp = (&hp->histind);
375 sh_timeradd(1000L*(HIST_RECENT-30), 1, hist_touch, (void*)hp->histname);
378 acctinit(hp);
383 hp->auditfp = 0;
384 if(sh_isstate(SH_INTERACTIVE) && (hp->auditmask=sh_checkaudit(hp,SHOPT_AUDITFILE, buff, sizeof(buff))))
397 hp->tty = strdup(ttyname(2));
398 hp->auditfp = sfnew((Sfio_t*)0,NULL,-1,fd,SF_WRITE);
410 void hist_close(register History_t *hp)
412 Shell_t *shp = (Shell_t*)hp->histshell;
413 sfclose(hp->histfp);
415 if(hp->auditfp)
417 if(hp->tty)
418 free((void*)hp->tty);
419 sfclose(hp->auditfp);
422 free((char*)hp);
459 static History_t* hist_trim(History_t *hp, int n)
463 register History_t *hist_new, *hist_old = hp;
496 if(!sh_histinit(hp->histshell))
555 static int hist_nearend(History_t *hp, Sfio_t *iop, register off_t size)
596 hp->histmarker = hp->histcnt = size+4;
608 hp->histmarker = hp->histcnt = 2L;
622 void hist_eof(register History_t *hp)
626 register off_t count = hp->histcnt;
628 sfseek(hp->histfp,count,SEEK_SET);
629 while(cp=(char*)sfreserve(hp->histfp,SF_UNBOUND,0))
631 n = sfvalue(hp->histfp);
641 n = hist_ind(hp, ++hp->histind);
643 if(count==hp->histcmds[n])
654 hp->histcmds[n] = count;
662 hp->histmarker=count+2;
664 hp->histind--;
671 if((n<count/2) && n != (hp->histind+1))
672 errormsg(SH_DICT,2,"index=%d marker=%d", hp->histind, n);
681 hp->histind-=2;
709 hp->histcmds[hist_ind(hp,++hp->histind)] = count;
711 hp->histcnt = count;
718 void hist_cancel(register History_t *hp)
721 if(!hp)
723 sfputc(hp->histfp,HIST_UNDO);
724 sfputc(hp->histfp,0);
725 sfsync(hp->histfp);
726 hp->histcnt += 2;
727 c = hist_ind(hp,--hp->histind);
728 hp->histcmds[c] = hp->histcnt;
735 void hist_flush(register History_t *hp)
738 if(hp)
740 if(buff=(char*)sfreserve(hp->histfp,0,SF_LOCKR))
742 hp->histflush = sfvalue(hp->histfp)+1;
743 sfwrite(hp->histfp,buff,0);
746 hp->histflush=0;
747 if(sfsync(hp->histfp)<0)
749 hist_close(hp);
750 if(!sh_histinit(hp->histshell))
753 hp->histflush = 0;
769 register History_t *hp = (History_t*)handle;
775 if(!hp->histflush)
782 hp->histcnt = cur;
801 if(hp->auditfp)
803 Shell_t *shp = (Shell_t*)hp->histshell;
805 sfprintf(hp->auditfp,"%u;%u;%s;%*s%c",sh_isoption(SH_PRIVILEGED)?shp->euserid:shp->userid,t,hp->tty,size,buff,0);
806 sfsync(hp->auditfp);
828 hp->histcnt += size;
829 c = hist_ind(hp,++hp->histind);
830 hp->histcmds[c] = hp->histcnt;
831 if(hp->histflush>HIST_MARKSZ && hp->histcnt > hp->histmarker+HIST_BSIZE/2)
835 hp->histcnt += HIST_MARKSZ;
836 hist_marker(bufptr,hp->histind);
837 hp->histmarker = hp->histcmds[hist_ind(hp,c)] = hp->histcnt;
846 hp->histwfail = 0;
870 off_t hist_tell(register History_t *hp, int n)
872 return(hp->histcmds[hist_ind(hp,n)]);
878 off_t hist_seek(register History_t *hp, int n)
880 return(sfseek(hp->histfp,hp->histcmds[hist_ind(hp,n)],SEEK_SET));
889 void hist_list(register History_t *hp,Sfio_t *outfile, off_t offset,int last, char *nl)
893 if(offset<0 || !hp)
898 sfseek(hp->histfp,offset,SEEK_SET);
899 while((c = sfgetc(hp->histfp)) != EOF)
920 Histloc_t hist_find(register History_t*hp,char *string,register int index1,int flag,int direction)
929 if(!hp)
945 index2 = (int)hp->histind;
948 index2 -= hp->histsize;
959 offset = hist_tell(hp,index1);
960 if((location.hist_line=hist_match(hp,offset,string,coffset))>=0)
967 if(((Shell_t*)hp->histshell)->trapnote&SH_SIGSET)
980 int hist_match(register History_t *hp,off_t offset,char *string,int *coffset)
987 sfseek(hp->histfp,offset,SEEK_SET);
988 if(!(cp = first = (unsigned char*)sfgetr(hp->histfp,0,0)))
990 m = sfvalue(hp->histfp);
1028 register History_t *hp = sh_getinterp()->hist_ptr;
1031 if(!hp)
1033 hist_seek(hp,command);
1034 while ((c = sfgetc(hp->histfp)) && c!=EOF)
1054 sfseek(hp->histfp,(off_t)0,SEEK_END);
1073 History_t *hp = hist_ptr;
1074 if(!hp)
1076 hist_copy(string,size,(int)hp->histind-1,-1);
1108 Histloc_t hist_locate(History_t *hp,register int command,register int line,int lines)
1112 if(!hp)
1120 while(command <= hp->histind)
1131 register int least = (int)hp->histind-hp->histsize;
1160 History_t *hp = (History_t*)handle;
1163 if(errno==ENOSPC || hp->histwfail++ >= 10)
1167 if((newfd=open(hp->histname,O_BINARY|O_APPEND|O_CREAT|O_RDWR,S_IRUSR|S_IWUSR)) >= 0)
1173 if(lseek(oldfd,(off_t)0,SEEK_END) < hp->histcnt)
1175 register int index = hp->histind;
1177 hp->histcnt = 2;
1178 hp->histind = 1;
1179 hp->histcmds[1] = 2;
1180 hist_eof(hp);
1181 hp->histmarker = hp->histcnt;
1182 hp->histind = index;
1186 errormsg(SH_DICT,2,"History file write error-%d %s: file unrecoverable",errno,hp->histname);