Lines Matching refs:pp
150 register Pr_t *pp;
151 if(!(pp = (Pr_t*)stakalloc(DATESZ+sizeof(Pr_t))))
153 pp->columns = 1;
154 pp->pageskip = pp->pageno = 0;
155 pp->pagelen = PAGESZ;
156 pp->numwidth = 0;
157 pp->flags = 0;
158 pp->igap = pp->ogap = 0;
159 pp->nchar = pp->itab = pp->otab= '\t';
160 pp->schar = 0;
161 pp->numwidth = pp->width = pp->offset = 0;
162 pp->header = 0;
163 pp->date = (char*)(pp+1);
164 memset(pp->state, 0, 1<<CHAR_BIT);
165 return pp;
171 static int prheader(register Pr_t *pp)
174 if(pp->header)
175 header = pp->header;
176 else if(!(pp->flags&M_FLAG) && pp->filename)
177 header = pp->filename;
178 sfputc(pp->outfile,'\n');
179 sfputc(pp->outfile,'\n');
180 if(pp->offset)
181 sfwrite(pp->outfile,pp->margin,pp->offlen);
182 if(sfprintf(pp->outfile,"%s %s Page %d\n\n\n",pp->date,header,pp->pageno)<0)
190 static int prtrailer(register Pr_t *pp,int line)
192 register int n= pp->pagelen-line;
193 if(pp->flags&D_FLAG)
196 n = !pp->pageodd;
198 n = 2*n-pp->pageodd;
200 if(pp->flags&F_FLAG)
202 if(sfputc(pp->outfile,'\f') < 0)
207 if(sfnputc(pp->outfile, '\n',n+HDRSZ) < 0)
216 static void prpage(register Pr_t *pp)
218 register int n, tflag = !(pp->flags&T_FLAG);
222 if(pp->pageno++ >= pp->pageskip)
223 out = pp->outfile;
225 prheader(pp);
226 if((n=sfmove(pp->infile,out,pp->pagelen,'\n')) != pp->pagelen)
230 if(!sfreserve(pp->infile,0,0)||sfvalue(pp->infile)<0)
232 sfnputc(pp->outfile,'\n',HDRSZ);
236 prtrailer(pp,n);
245 static int outspaces(register Pr_t* pp,register int spaces, register int col)
248 if(pp->ogap)
250 /* changes spaces <pp->otab> */
253 if(sfputc(pp->outfile,pp->otab) < 0)
257 col = pp->ogap;
261 if(sfnputc(pp->outfile,' ',spaces) < 0)
272 static int outcol(register Pr_t *pp,char *buff, register int size, int spaces)
274 register char *state=pp->state;
278 if(pp->igap || pp->ogap)
284 if(pp->ogap)
285 omod = pp->ogap - (pp->colno-size)%pp->ogap;
288 outspaces(pp,size,omod);
296 if(pp->width && col >= pp->width)
298 size -= (col+1-pp->width);
307 if(sfwrite(pp->outfile,buff,--size)< 0)
309 if(pp->width && col >= pp->width)
312 if(pp->ogap)
313 omod = pp->ogap - (pp->colno+col)%pp->ogap;
320 n= (pp->igap-(col%pp->igap));
328 sfputc(pp->outfile,'\n');
332 if(cp>=buffend || (pp->width && col>=pp->width))
335 if(col>=pp->width)
339 sfputc(pp->outfile,'\n');
342 size -= (col-pp->width);
345 size += pp->width-col;
348 outspaces(pp,size,omod);
353 if(size>0 && sfwrite(pp->outfile,buff,size)< 0)
361 static int prline(register Pr_t *pp)
363 register int n, line = pp->pagelen;
365 pp->colno = pp->offset;
366 if(pp->pageskip > 0)
368 n = pp->pageskip*pp->pagelen;
369 if(sfmove(pp->infile, NiL, n, '\n')!=n)
372 while(cp = sfgetr(pp->infile,'\n',0))
374 n = sfvalue(pp->infile);
375 if(line >= pp->pagelen)
378 pp->pageno++;
379 if(!(pp->flags&T_FLAG) && prheader(pp)<0)
382 if(pp->offset)
383 sfwrite(pp->outfile,pp->margin,pp->offlen);
384 if(pp->numwidth)
385 sfprintf(pp->outfile,"%*d%c",pp->numwidth,++pp->lineno,pp->nchar);
386 if(outcol(pp,cp,n,0) < 0)
388 if(++line >= pp->pagelen && !(pp->flags&T_FLAG))
390 if(pp->flags&F_FLAG)
391 sfputc(pp->outfile,'\f');
393 sfnputc(pp->outfile, '\n',HDRSZ);
395 else if(pp->flags&D_FLAG)
396 sfputc(pp->outfile,'\n');
398 if(!(pp->flags&T_FLAG))
399 prtrailer(pp,line);
406 static int outpage(register Pr_t *pp,int n)
408 register char *cp,**next = pp->fieldlist;
410 if(pp->pageno++ < pp->pageskip)
412 pp->lineno += pp->pagelen;
415 if(!(pp->flags&T_FLAG))
416 prheader(pp);
417 if(pp->flags&A_FLAG)
420 incr = (n+pp->columns-1)/pp->columns;
424 if(!(pp->flags&A_FLAG))
428 next = pp->fieldlist + line;
430 else if(next >= pp->fieldlast)
432 if(pp->offset)
433 sfwrite(pp->outfile,pp->margin,pp->offlen);
434 if(pp->numwidth)
435 sfprintf(pp->outfile,"%*d%c",pp->numwidth,++pp->lineno,pp->nchar);
436 pp->colno = pp->offset;
437 for(old=0,j=pp->columns; --j>=0; )
439 if(next+incr >= pp->fieldlast)
448 if((old=outcol(pp,cp,size,old))<0)
450 pp->colno += pp->width;
451 if(j>0 && pp->schar)
453 sfputc(pp->outfile,pp->schar);
454 pp->colno = old;
455 if(pp->schar==pp->otab && pp->ogap)
456 pp->colno += pp->ogap - pp->colno%pp->ogap;
458 pp->colno++;
463 if(++line >= pp->pagelen)
465 if(pp->flags&D_FLAG)
466 sfputc(pp->outfile,'\n');
468 if(!(pp->flags&T_FLAG))
469 prtrailer(pp,line);
477 static int prcol(register Pr_t *pp)
481 register Sfio_t *fp=pp->infile;
482 int nstream,r=0, skip=pp->pageskip;
483 nextmax = pp->fieldlist + pp->columns*pp->pagelen;
486 next = pp->fieldlist;
487 *next = pp->fieldptr = pp->fieldbuff;
488 if(pp->streams)
491 fp = *pp->streams;
497 if((size=sfvalue(fp)) > pp->width)
498 size = pp->width;
500 memcpy(pp->fieldptr,cp,size);
502 else if(pp->streams)
508 pp->streams[nstream] = 0;
509 if(--pp->nopen<=0)
511 next -= (pp->columns-1);
519 pp->fieldptr +=size;
520 *++next = pp->fieldptr;
523 if(pp->streams)
525 if(++nstream>=pp->columns)
527 fp = pp->streams[nstream];
535 pp->fieldlast = next;
536 if((n = next - pp->fieldlist) > 0)
537 r=outpage(pp,n);
546 register Pr_t* pp = (Pr_t*)dp;
554 if (pp->control.cur >= pp->control.end)
556 if (n > pp->control.siz)
558 pp->control.siz = roundof(n, 1024);
559 if (!(pp->control.buf = newof(pp->control.buf, char, pp->control.siz, 0)))
562 if ((z = sfrd(fp, pp->control.buf, n, dp)) <= 0)
564 pp->control.cur = pp->control.buf;
565 pp->control.end = pp->control.buf + z;
567 while (pp->control.cur < pp->control.end && s < e)
569 if ((c = mbsize(pp->control.cur)) > 1)
574 *s++ = *pp->control.cur++;
578 c = ccmapchr(pp->control.map, *pp->control.cur);
580 *s++ = *pp->control.cur++;
585 pp->control.cur++;
597 register Pr_t* pp = (Pr_t*)dp;
604 if (pp->control.cur >= pp->control.end)
606 if (n > pp->control.siz)
608 pp->control.siz = roundof(n, 1024);
609 if (!(pp->control.buf = newof(pp->control.buf, char, pp->control.siz, 0)))
612 if ((z = sfrd(fp, pp->control.buf, n, dp)) <= 0)
614 pp->control.cur = pp->control.buf;
615 pp->control.end = pp->control.buf + z;
617 while (pp->control.cur < pp->control.end && s < e)
619 if ((c = mbsize(pp->control.cur)) > 1)
624 *s++ = *pp->control.cur++;
628 c = *pp->control.cur++;
631 t = fmtquote(pp->control.cur - 1, NiL, NiL, 1, 0);
634 pp->control.cur--;
651 register Pr_t *pp;
657 pp = prinit();
665 pp->flags |= A_FLAG;
668 pp->control.disc = &pp->disc;
669 pp->control.disc->readf = c_read;
670 pp->control.map = ccmap(CC_NATIVE, CC_ASCII);
673 pp->flags |= D_FLAG;
676 pp->flags |= (P_FLAG|F_FLAG);
679 pp->flags |= F_FLAG;
682 pp->flags |= M_FLAG;
685 pp->flags |= P_FLAG;
688 pp->flags |= R_FLAG;
692 pp->flags |= T_FLAG;
696 pp->columns = opt_info.num;
698 pp->pageskip = opt_info.num-1;
701 pp->header = opt_info.arg;
704 pp->width = opt_info.num;
707 pp->pagelen = opt_info.num;
710 pp->offset = opt_info.num;
713 pp->pageskip = opt_info.num-1;
726 pp->igap = TABSZ;
728 pp->ogap = TABSZ;
730 pp->numwidth = NWIDTH;
736 pp->itab = *opt_info.arg++;
738 pp->otab = *opt_info.arg++;
740 pp->nchar = *opt_info.arg++;
748 pp->igap = l;
750 pp->ogap = l;
752 pp->numwidth = l;
765 pp->schar = *opt_info.arg;
767 pp->schar = '\t';
770 pp->control.disc = &pp->disc;
771 pp->control.disc->readf = v_read;
774 pp->flags |= X_FLAG;
791 pp->outfile = sfstdout;
792 if(pp->pagelen<=(2*HDRSZ))
793 pp->flags |= T_FLAG;
794 if(!(pp->flags&T_FLAG))
795 pp->pagelen -= (2*HDRSZ);
796 pp->pageodd = (pp->pagelen&1);
797 if(pp->flags&D_FLAG)
798 pp->pagelen = (pp->pagelen+1)/2;
799 if(pp->flags&M_FLAG)
801 pp->columns = argc-opt_info.index;
802 pp->flags |= A_FLAG;
805 if(pp->width)
806 pp->width -= pp->offset;
808 if(pp->columns > 0)
810 if(pp->columns==1)
812 pp->columns = 0;
813 pp->flags &= ~(M_FLAG|A_FLAG);
817 if(pp->igap==0)
818 pp->igap = TABSZ;
819 if(pp->ogap==0)
820 pp->ogap = TABSZ;
821 if((n=pp->width)==0)
823 n = (pp->schar?SWIDTH:(WIDTH-pp->offset));
825 n = (pp->schar?SWIDTH:WIDTH);
827 n -= pp->numwidth;
828 if((pp->width = ((n+1)/pp->columns)) <=0)
830 n = (pp->pagelen*pp->columns+1);
831 if(!(pp->fieldlist = (char**)stakalloc(n*(sizeof(char*)+pp->width))))
833 pp->fieldbuff = pp->fieldptr = (char*)(pp->fieldlist+n);
836 if(pp->igap)
837 pp->state[pp->itab] = S_TAB;
838 pp->state[' '] |= S_SPACE;
839 pp->state['\n'] = S_NL;
840 if(pp->ogap)
841 pp->omod = (pp->numwidth+pp->numwidth>0)%pp->ogap;
842 if(pp->offset)
845 if(pp->ogap)
847 n = pp->offset/pp->ogap;
848 pp->offlen = pp->offset - n*(pp->ogap-1);
852 if(!(pp->margin = (char*)stakalloc(pp->offset)))
854 for(cp=pp->margin; cp < pp->margin+pp->offlen; cp++)
857 *cp = pp->otab;
866 pp->filename = cp;
871 if(!(pp->flags&R_FLAG))
876 if (pp->control.disc && !sfdisc(fp, pp->control.disc))
878 if(pp->streams)
879 pp->streams[n++] = fp;
882 if(!(pp->flags&T_FLAG))
884 if(pp->flags&X_FLAG)
885 strcpy(pp->date, "- Date/Time --");
887 tmfmt(pp->date, DATESZ, "%b %e %H:%M %Y", fstat(sffileno(fp), &statb) ? (time_t*)0 : &statb.st_mtime);
889 pp->lineno = pp->pageno = 0;
890 pp->infile = fp;
891 if(pp->flags&M_FLAG)
893 pp->streams = (Sfio_t**)stakalloc(pp->columns*sizeof(Sfio_t*));
894 *pp->streams = fp;
898 if(pp->columns)
899 prcol(pp);
900 else if(pp->width || pp->igap || pp->ogap || pp->offset || pp->numwidth || (pp->flags&D_FLAG))
901 prline(pp);
903 prpage(pp);
909 if(pp->streams)
911 pp->nopen = n;
912 prcol(pp);
914 if (pp->control.buf)
915 free(pp->control.buf);