Lines Matching refs:state

184 static State_t		state =
398 if (state.in.fp != sfstdin)
399 sfclose(state.in.fp);
400 if (state.out.fp == sfstdout)
401 sfsync(state.out.fp);
403 sfclose(state.out.fp);
404 if (!state.silent.value.number)
406 sfprintf(sfstderr, "%I*u+%I*u records in\n", sizeof(Sfulong_t), (Sfulong_t)state.in.complete, sizeof(Sfulong_t), (Sfulong_t)(state.in.partial + (state.in.remains > 0)));
407 sfprintf(sfstderr, "%I*u+%I*u records out\n", sizeof(Sfulong_t), (Sfulong_t)state.out.complete, sizeof(Sfulong_t), (Sfulong_t)(state.out.partial + (state.out.remains > 0)));
408 if (state.in.truncated)
409 sfprintf(sfstderr, "%I*u truncated record%s\n", sizeof(Sfulong_t), (Sfulong_t)state.in.truncated, state.in.truncated == 1 ? "" : "s");
429 x = r / state.obs.value.number;
430 state.out.complete += x;
431 if (x = r - x * state.obs.value.number)
433 if (state.out.special)
434 state.out.partial++;
435 else if ((state.out.remains += x) >= state.obs.value.number)
437 state.out.remains -= state.obs.value.number;
438 state.out.complete++;
471 iconv_init(&state.iconv, errorf);
472 state.from.value.string = state.to.value.string = "";
476 for (op = &state.operand_begin; op <= &state.operand_end; op++)
478 sfprintf(sp, "[%d:%s?%s", op - &state.operand_begin + 10, op->name, op->help);
494 for (vp = &state.conv_begin; vp <= &state.conv_end; vp++)
539 op = &state.operand_begin - (f + 10);
552 vp = (Operand_t*)strsearch(&state.conv_begin, &state.conv_end - &state.conv_begin + 1, sizeof(Operand_t), stracmp, v, NiL);
595 switch ((long)(state.conv.value.number & (A2E|A2I|A2N|A2O|E2A|I2A|N2A|O2A)))
600 state.from.value.string = "ascii";
601 state.to.value.string = "ebcdic-e";
604 state.from.value.string = "ascii";
605 state.to.value.string = "ebcdic-i";
608 state.from.value.string = "ascii";
609 state.to.value.string = "";
612 state.from.value.string = "ascii";
613 state.to.value.string = "ebcdic-o";
616 state.from.value.string = "ebcdic-e";
617 state.to.value.string = "ascii";
620 state.from.value.string = "ebcdic-i";
621 state.to.value.string = "ascii";
624 state.from.value.string = "";
625 state.to.value.string = "ascii";
628 state.from.value.string = "ebcdic-o";
629 state.to.value.string = "ascii";
632 error(3, "only one of %s={%s,%s,%s} may be specified", state.conv.name, state.ascii.value.string, state.ebcdic.value.string, state.ibm.value.string);
634 if (streq(state.from.value.string, state.to.value.string))
635 state.cvt = (iconv_t)(-1);
636 else if ((state.cvt = iconv_open(state.to.value.string, state.from.value.string)) == (iconv_t)(-1))
637 error(3, "cannot convert from %s to %s", *state.from.value.string ? state.from.value.string : ccmapname(CC_NATIVE), *state.to.value.string ? state.to.value.string : ccmapname(CC_NATIVE));
638 else if (state.cvt == (iconv_t)(0)) /* ast iconv identity */
639 state.cvt = (iconv_t)(-1);
640 else if (!(state.tmp = sfstropen()))
642 if ((state.conv.value.number & (BLOCK|UNBLOCK)) == (BLOCK|UNBLOCK))
643 error(3, "only one of %s=%s and %s=%s may be specified", state.conv.name, state.block.value.string, state.conv.name, state.unblock.value.string);
644 if ((state.conv.value.number & (SYNC|UNBLOCK)) == (SYNC|UNBLOCK))
646 state.conv.value.number &= ~SYNC;
647 error(1, "%s=%s ignored for %s=%s", state.conv.name, state.sync.value.string, state.conv.name, state.unblock.value.string);
649 if (state.conv.value.number & SWAP)
650 state.swap.value.number = 1;
651 else if (state.swap.value.number)
652 state.conv.value.number |= SWAP;
653 if (state.oseek.value.number && (state.conv.value.number & NOTRUNC))
655 state.oseek.value.number = 0;
656 error(1, "%s ignored for %s=%s", state.oseek.name, state.conv.name, state.notrunc.value.string);
658 if ((state.conv.value.number & (LCASE|UCASE)) == (LCASE|UCASE))
659 error(3, "only one of %s=%s and %s=%s may be specified", state.conv.name, state.lcase.value.string, state.conv.name, state.ucase.value.string);
660 if (state.conv.value.number & (BLOCK|UNBLOCK))
662 if (!state.cbs.value.number)
663 error(3, "%s must be specified for %s=%s", state.cbs.name, state.conv.name, (state.conv.value.number & BLOCK) ? state.block.value.string : state.unblock.value.string);
664 state.pad = ' ';
665 if (state.conv.value.number & UNBLOCK)
667 state.ibs.value.number = state.cbs.value.number;
668 if (state.bs.value.number)
670 state.obs.value.number = state.bs.value.number;
671 state.bs.value.number = 0;
675 else if (state.cbs.value.number)
677 state.cbs.value.number = 0;
678 error(1, "%s ignored", state.cbs.name);
680 if (n = state.bs.value.number)
681 state.ibs.value.number = state.obs.value.number = n;
682 if (n = state.iseek.value.number)
684 if (state.skip.value.number)
685 error(3, "only on of %s and %s may be specified", state.skip.name, state.iseek.name);
686 if (!state.ibs.value.number)
687 error(3, "%s requires %s or %s", state.iseek.name, state.bs.name, state.ibs.name);
688 state.skip.value.number = n;
690 if (state.oseek.value.number && !state.obs.value.number)
691 error(3, "%s requires %s or %s", state.oseek.name, state.bs.name, state.obs.name);
692 if (!(s = state.ifn.value.string))
694 state.ifn.value.string = "/dev/stdin";
695 state.in.fp = sfstdin;
701 else if (!(state.in.fp = sfopen(NiL, s, "rb")))
703 if (!(s = state.ofn.value.string))
705 state.ofn.value.string = "/dev/stdout";
706 state.out.fp = sfstdout;
708 else if (!(state.out.fp = sfopen(NiL, s, (state.conv.value.number & NOTRUNC) ? "a+b" : state.oseek.value.number ? "w+b" : "wb")))
710 if ((state.conv.value.number & ISPECIAL) || fstat(sffileno(state.in.fp), &st) || !S_ISREG(st.st_mode))
711 state.in.special = 1;
712 if (state.in.special && !(state.conv.value.number & BLOCK) && (n = state.ibs.value.number))
713 sfsetbuf(state.in.fp, NiL, n);
714 if ((state.conv.value.number & OSPECIAL) || fstat(sffileno(state.out.fp), &st) || !S_ISREG(st.st_mode))
715 state.out.special = 1;
716 if (state.out.special && !(state.conv.value.number & UNBLOCK) && (n = state.obs.value.number))
717 sfsetbuf(state.out.fp, NiL, n);
718 state.bs.value.number = state.ibs.value.number;
719 if (state.obs.value.number > state.bs.value.number)
720 state.bs.value.number = state.obs.value.number;
721 if (state.cbs.value.number > state.bs.value.number)
722 state.bs.value.number = state.cbs.value.number;
723 if (!(state.buffer = newof(0, char, state.bs.value.number, 0)))
725 if (n = state.skip.value.number)
727 if (!state.ibs.value.number)
728 error(3, "%s requires %s or %s", state.skip.name, state.bs.name, state.ibs.name);
729 n *= state.ibs.value.number;
730 if (sfseek(state.in.fp, n, SEEK_SET) != n)
734 if (!sfreserve(state.in.fp, state.in.special && state.ibs.value.number < n ? state.ibs.value.number : n, 0))
736 if (sfvalue(state.in.fp) > 0)
737 error(ERROR_SYSTEM|3, "%s: seek read error", state.ifn.value.string);
740 } while ((n -= sfvalue(state.in.fp)) > 0);
742 error(3, "%s: cannot seek past end of file", state.ifn.value.string);
745 if (n = state.oseek.value.number)
747 n *= state.obs.value.number;
748 if (sfseek(state.out.fp, n, SEEK_SET) != n)
752 if (!sfreserve(state.out.fp, state.out.special && state.obs.value.number < n ? state.obs.value.number : n, 0))
754 if (sfvalue(state.out.fp) > 0)
755 error(ERROR_SYSTEM|3, "%s: seek read error", state.ofn.value.string);
758 } while ((n -= sfvalue(state.out.fp)) > 0);
759 while (n > 0 && (c = sfwrite(state.out.fp, state.buffer, state.out.special && state.obs.value.number < n ? state.obs.value.number : n)) > 0)
762 error(ERROR_SYSTEM|3, "%s: seek 0 fill write error", state.ofn.value.string);
765 if (state.silent.value.number)
766 state.iconv.errorf = 0;
767 if (state.conv.value.number & NOERROR)
769 state.iconv.errorf = 0;
770 if (state.conv.value.number & SYNC)
771 state.iconv.fill = 0;
773 state.iconv.flags |= ICONV_OMIT;
776 state.iconv.flags |= ICONV_FATAL;
779 sfdisc(state.out.fp, &disc);
780 if (!state.obs.value.number)
781 state.obs.value.number = BS;
782 if (state.conv.value.number & BLOCK)
784 c = state.cbs.value.number;
785 memset(state.buffer, state.pad, c);
786 while ((s = sfgetr(state.in.fp, '\n', 0)) || (s = sfgetr(state.in.fp, '\n', -1)))
788 state.in.complete++;
789 n = sfvalue(state.in.fp) - 1;
792 if (sfwrite(state.out.fp, s, c) != c)
793 error(ERROR_SYSTEM|3, "%s: write error", state.ofn.value.string);
794 state.in.truncated++;
798 if (sfwrite(state.out.fp, s, n) != n)
799 error(ERROR_SYSTEM|3, "%s: write error", state.ofn.value.string);
801 if (sfwrite(state.out.fp, state.buffer, n) != n)
802 error(ERROR_SYSTEM|3, "%s: write error", state.ofn.value.string);
808 if (!(c = state.ibs.value.number))
810 f = state.conv.value.number;
811 if (!state.in.special)
813 if (!(r = state.count.value.number))
816 while (state.in.complete != r)
818 b = sfreserve(state.in.fp, SF_UNBOUND, 0);
819 m = sfvalue(state.in.fp);
824 error(ERROR_SYSTEM|((f & NOERROR) ? 2 : 3), "%s: read error", state.ifn.value.string);
825 memset(b = state.buffer, state.pad, m = c);
827 while (state.in.complete != r)
842 state.in.complete++;
857 if (state.in.complete >= r && (state.in.remains + n) >= c)
858 n -= state.in.remains;
867 if (state.in.special)
868 state.in.partial++;
874 if ((state.in.remains + n) >= c)
876 state.in.complete++;
883 if (state.in.complete >= r)
885 n = c - state.in.remains;
886 state.in.remains += m - c;
891 state.in.remains += m - c;
895 state.in.remains += n;
898 s = memcpy(state.buffer, s, n);
899 memset(s + n, state.pad, c - n);
904 swapmem(state.swap.value.number, s, s, n);
905 if (state.cvt != (iconv_t)(-1))
909 state.iconv.errors = 0;
910 if ((d = iconv_write(state.cvt, state.tmp, &cb, &cc, &state.iconv)) < 0)
912 if (!(s = sfstruse(state.tmp)))
915 if (state.iconv.errors && (state.iconv.flags & ICONV_FATAL))
939 if (sfwrite(state.out.fp, s, v - s) != (v - s) || sfputc(state.out.fp, '\n') != '\n')
940 error(ERROR_SYSTEM|3, "%s: write error", state.ofn.value.string);
942 else if (sfwrite(state.out.fp, s, n) != n)
943 error(ERROR_SYSTEM|3, "%s: write error", state.ofn.value.string);
949 if (state.in.partial)
951 state.in.complete -= partial;
952 state.in.remains = 0;
954 if (sfsync(state.out.fp))
955 error(ERROR_SYSTEM|3, "%s: write error", state.ofn.value.string);