Lines Matching defs:jp
167 done(register Join_t* jp)
169 if (jp->file[0].iop && jp->file[0].iop != sfstdin)
170 sfclose(jp->file[0].iop);
171 if (jp->file[1].iop && jp->file[1].iop != sfstdin)
172 sfclose(jp->file[1].iop);
173 if (jp->outlist)
174 free(jp->outlist);
175 if (jp->file[0].fields)
176 free(jp->file[0].fields);
177 if (jp->file[1].fields)
178 free(jp->file[1].fields);
179 if (jp->same)
180 free(jp->same);
181 free(jp);
187 register Join_t* jp;
191 if (jp = newof(0, Join_t, 1, 0))
193 if (jp->mb = mbwide())
195 jp->state[i] = S_WIDE;
196 jp->state[' '] = jp->state['\t'] = S_SPACE;
197 jp->state['\n'] = S_NL;
198 jp->delim = -1;
199 jp->nullfield = 0;
200 if (!(jp->file[0].fields = newof(0, Field_t, NFIELD + 1, 0)) ||
201 !(jp->file[1].fields = newof(0, Field_t, NFIELD + 1, 0)))
203 done(jp);
206 jp->file[0].maxfields = NFIELD;
207 jp->file[1].maxfields = NFIELD;
208 jp->outmode = C_COMMON;
210 return jp;
214 getolist(Join_t* jp, const char* first, char** arglist)
224 outptr = jp->outlist = newof(0, int, NFIELD + 1, 0);
249 jp->outlist = newof(jp->outlist, int, 2 * nfield + 1, 0);
250 outptr = jp->outlist + nfield;
252 outmax = jp->outlist + nfield;
280 jp->outlist = newof(jp->outlist, int, 2 * nfield + 1, 0);
281 outptr = jp->outlist + nfield;
283 outmax = jp->outlist + nfield;
295 getrec(Join_t* jp, int index, int discard)
297 register unsigned char* sp = jp->state;
298 register File_t* fp = &jp->file[index];
305 if (sh_checksig(jp->context))
313 jp->outmode &= ~(1<<index);
318 if (jp->delim == '\n') /* handle new-line delimiter specially */
337 if (jp->delim == -1)
356 if (jp->mb)
379 if (jp->mb)
391 if (n == jp->delim)
396 if (jp->delim == -1 && iswspace(n))
421 if (jp->mb)
451 _trace_getrec(Join_t* jp, int index, int discard)
455 r = getrec(jp, index, discard);
469 outfield(Join_t* jp, int index, register int n, int last)
471 register File_t* fp = &jp->file[index];
475 register Sfio_t* iop = jp->outfile;
485 if ((n = jp->delim) == -1)
489 register unsigned char* sp = jp->state;
492 if (jp->mb)
516 else if (jp->delimstr)
528 if (jp->nullfield && sfputr(iop, jp->nullfield, -1) < 0)
533 if (sfwrite(iop, jp->delimstr, jp->delimlen) < 0)
538 if (!jp->nullfield)
540 else if (sfputr(iop, jp->nullfield, n) < 0)
560 outrec(register Join_t* jp, int mode)
569 if (mode < 0 && jp->file[0].hit++)
571 if (mode > 0 && jp->file[1].hit++)
573 if (out = jp->outlist)
580 j = jp->file[i].field;
586 jp->file[i].nfields :
589 if (outfield(jp, i, j, *out < 0) < 0)
594 k = jp->file[0].nfields;
596 k += jp->file[1].nfields - 1;
599 fp = &jp->file[i];
609 if (outfield(jp,i,n,!--k) < 0)
615 if (outfield(jp,i,j,!--k) < 0)
626 if (j!=n && outfield(jp,i,j,!--k) < 0)
636 #define outrec(p,n) (sfprintf(sfstdout, "[R#%d,%d,%lld,%lld:%-.*s{%d}:%-.*s{%d}]", __LINE__, i1=n, lo, hi, jp->file[0].fieldlen, cp1, jp->file[0].hit, jp->file[1].fieldlen, cp2, jp->file[1].hit), outrec(p, i1))
640 join(Join_t* jp)
653 if ((cp1 = getrec(jp, 0, 0)) && (cp2 = getrec(jp, 1, 0)) || (cp2 = 0))
655 n1 = jp->file[0].fieldlen;
656 n2 = jp->file[1].fieldlen;
662 if (!n && !(cmp = n1 < n2 ? -1 : (n1 > n2)) || n && !(cmp = (int)*cp1 - (int)*cp2) && !(cmp = jp->ignorecase ? strncasecmp((char*)cp1, (char*)cp2, n) : memcmp(cp1, cp2, n)))
664 sfprintf(sfstdout, "[C#%d:%d(%c-%c),%d,%lld,%lld%s]", __LINE__, cmp, *cp1, *cp2, same, lo, hi, (jp->outmode & C_COMMON) ? ",COMMON" : "");
667 if (!n && !(cmp = n1 < n2 ? -1 : (n1 > n2)) || n && !(cmp = (int)*cp1 - (int)*cp2) && !(cmp = jp->ignorecase ? strncasecmp((char*)cp1, (char*)cp2, n) : memcmp(cp1, cp2, n)) && !(cmp = n1 - n2))
670 if (!(jp->outmode & C_COMMON))
672 if (cp1 = getrec(jp, 0, 1))
674 n1 = jp->file[0].fieldlen;
678 if ((jp->ooutmode & (C_FILE1|C_FILE2)) != C_FILE2)
680 if (sfseek(jp->file[0].iop, (Sfoff_t)-jp->file[0].reclen, SEEK_CUR) < 0 || !(cp1 = getrec(jp, 0, 0)))
682 error(ERROR_SYSTEM|2, "%s: seek error", jp->file[0].name);
686 else if (outrec(jp, 0) < 0)
688 else if (lo < 0 && (jp->outmode & C_COMMON))
690 if ((lo = sfseek(jp->file[1].iop, (Sfoff_t)0, SEEK_CUR)) < 0)
692 error(ERROR_SYSTEM|2, "%s: seek error", jp->file[1].name);
695 lo -= jp->file[1].reclen;
697 if (cp2 = getrec(jp, 1, lo < 0))
699 n2 = jp->file[1].fieldlen;
712 if (n2 > jp->samesize)
714 jp->samesize = roundof(n2, 16);
715 if (!(jp->same = newof(jp->same, char, jp->samesize, 0)))
721 memcpy(jp->same, cp2, o2 = n2);
722 if (!(cp2 = getrec(jp, 1, 0)))
724 n2 = jp->file[1].fieldlen;
725 if (n2 == o2 && *cp2 == *jp->same && !memcmp(cp2, jp->same, n2))
731 if (sfseek(jp->file[1].iop, hi, SEEK_SET) != hi)
733 error(ERROR_SYSTEM|2, "%s: seek error", jp->file[1].name);
738 else if ((jp->outmode & C_FILE2) && outrec(jp, 1) < 0)
741 if (cp2 = getrec(jp, 1, 1))
743 n2 = jp->file[1].fieldlen;
753 if (!(cp1 = getrec(jp, 0, 0)))
755 n1 = jp->file[0].fieldlen;
760 if ((hi = sfseek(jp->file[1].iop, (Sfoff_t)0, SEEK_CUR)) < 0 ||
761 (hi -= jp->file[1].reclen) < 0 ||
762 sfseek(jp->file[1].iop, lo, SEEK_SET) != lo ||
763 !(cp2 = getrec(jp, 1, 0)))
765 error(ERROR_SYSTEM|2, "%s: seek error", jp->file[1].name);
768 n2 = jp->file[1].fieldlen;
770 if (jp->file[1].discard)
771 sfseek(jp->file[1].iop, (Sfoff_t)-1, SEEK_SET);
775 else if ((jp->outmode & C_FILE1) && outrec(jp, -1) < 0)
777 if (!(cp1 = getrec(jp, 0, 1)))
779 n1 = jp->file[0].fieldlen;
783 sfprintf(sfstdout, "[X#%d:?,%p,%p,%d%,%d,%d%s]", __LINE__, cp1, cp2, cmp, lo, hi, (jp->outmode & C_COMMON) ? ",COMMON" : "");
788 sfseek(jp->file[1].iop, (Sfoff_t)0, SEEK_CUR) < hi &&
789 sfseek(jp->file[1].iop, hi, SEEK_SET) != hi)
791 error(ERROR_SYSTEM|2, "%s: seek error", jp->file[1].name);
795 sfprintf(sfstdout, "[O#%d:%02o:%02o]", __LINE__, jp->ooutmode, jp->outmode);
797 cp1 = (!cp1 && cmp && hi < 0 && !jp->file[1].hit && ((jp->ooutmode ^ C_ALL) <= 1 || jp->outmode == 2)) ? cp2 : getrec(jp, 1, 0);
807 sfprintf(sfstdout, "[X#%d:%d,%p,%p,%d,%02o,%02o%s]", __LINE__, n, cp1, cp2, cmp, jp->ooutmode, jp->outmode, (jp->outmode & C_COMMON) ? ",COMMON" : "");
809 if (!cp1 || !(jp->outmode & (1<<n)))
811 if (cp1 && jp->file[n].iop == sfstdin)
815 if (outrec(jp, cmp) < 0)
819 if (!getrec(jp, n, 1))
821 } while (outrec(jp, cmp) >= 0);
830 register Join_t* jp;
836 if (!(jp = init()))
838 jp->context = context;
876 jp->file[0].field = (int)(opt_info.num-1);
884 jp->file[n-'1'].field = (int)(opt_info.num-1);
887 jp->outmode &= ~C_COMMON;
892 jp->outmode |= 1<<(opt_info.num-1);
895 jp->nullfield = opt_info.arg;
899 n = getolist(jp, opt_info.arg, argv+opt_info.index);
903 jp->state[' '] = jp->state['\t'] = 0;
904 if (jp->mb)
907 jp->delim = mbchar(cp);
910 jp->delimlen = n;
911 jp->delimstr = opt_info.arg;
916 jp->state[n] = S_DELIM;
917 jp->delim = n;
920 jp->ignorecase = !opt_info.num;
923 jp->buffered = !opt_info.num;
929 done(jp);
939 done(jp);
942 jp->ooutmode = jp->outmode;
943 jp->file[0].name = cp = *argv++;
951 jp->file[0].discard = 1;
953 jp->file[0].iop = sfstdin;
955 else if (!(jp->file[0].iop = sfopen(NiL, cp, "r")))
957 done(jp);
960 jp->file[1].name = cp = *argv;
968 jp->file[1].discard = 1;
970 jp->file[1].iop = sfstdin;
972 else if (!(jp->file[1].iop = sfopen(NiL, cp, "r")))
974 done(jp);
977 if (jp->buffered)
979 sfsetbuf(jp->file[0].iop, jp->file[0].iop, SF_UNBOUND);
980 sfsetbuf(jp->file[1].iop, jp->file[1].iop, SF_UNBOUND);
982 jp->outfile = sfstdout;
983 if (!jp->outlist)
984 jp->nullfield = 0;
985 if (join(jp) < 0)
987 done(jp);
990 else if (jp->file[0].iop==sfstdin || jp->file[1].iop==sfstdin)
992 done(jp);