head 1.17; access; symbols netbsd-10-0-RELEASE:1.17 netbsd-10-0-RC6:1.17 netbsd-10-0-RC5:1.17 netbsd-10-0-RC4:1.17 netbsd-10-0-RC3:1.17 netbsd-10-0-RC2:1.17 netbsd-10-0-RC1:1.17 netbsd-10:1.17.0.108 netbsd-10-base:1.17 netbsd-9-3-RELEASE:1.17 cjep_sun2x-base1:1.17 cjep_sun2x:1.17.0.106 cjep_sun2x-base:1.17 cjep_staticlib_x-base1:1.17 netbsd-9-2-RELEASE:1.17 cjep_staticlib_x:1.17.0.104 cjep_staticlib_x-base:1.17 netbsd-9-1-RELEASE:1.17 phil-wifi-20200421:1.17 phil-wifi-20200411:1.17 is-mlppp:1.17.0.102 is-mlppp-base:1.17 phil-wifi-20200406:1.17 netbsd-8-2-RELEASE:1.17 netbsd-9-0-RELEASE:1.17 netbsd-9-0-RC2:1.17 netbsd-9-0-RC1:1.17 phil-wifi-20191119:1.17 netbsd-9:1.17.0.100 netbsd-9-base:1.17 phil-wifi-20190609:1.17 netbsd-8-1-RELEASE:1.17 netbsd-8-1-RC1:1.17 pgoyette-compat-merge-20190127:1.17 pgoyette-compat-20190127:1.17 pgoyette-compat-20190118:1.17 pgoyette-compat-1226:1.17 pgoyette-compat-1126:1.17 pgoyette-compat-1020:1.17 pgoyette-compat-0930:1.17 pgoyette-compat-0906:1.17 netbsd-7-2-RELEASE:1.17 pgoyette-compat-0728:1.17 netbsd-8-0-RELEASE:1.17 phil-wifi:1.17.0.98 phil-wifi-base:1.17 pgoyette-compat-0625:1.17 netbsd-8-0-RC2:1.17 pgoyette-compat-0521:1.17 pgoyette-compat-0502:1.17 pgoyette-compat-0422:1.17 netbsd-8-0-RC1:1.17 pgoyette-compat-0415:1.17 pgoyette-compat-0407:1.17 pgoyette-compat-0330:1.17 pgoyette-compat-0322:1.17 pgoyette-compat-0315:1.17 netbsd-7-1-2-RELEASE:1.17 pgoyette-compat:1.17.0.96 pgoyette-compat-base:1.17 netbsd-7-1-1-RELEASE:1.17 matt-nb8-mediatek:1.17.0.94 matt-nb8-mediatek-base:1.17 perseant-stdc-iso10646:1.17.0.92 perseant-stdc-iso10646-base:1.17 netbsd-8:1.17.0.90 netbsd-8-base:1.17 prg-localcount2-base3:1.17 prg-localcount2-base2:1.17 prg-localcount2-base1:1.17 prg-localcount2:1.17.0.88 prg-localcount2-base:1.17 pgoyette-localcount-20170426:1.17 bouyer-socketcan-base1:1.17 pgoyette-localcount-20170320:1.17 netbsd-7-1:1.17.0.86 netbsd-7-1-RELEASE:1.17 netbsd-7-1-RC2:1.17 netbsd-7-nhusb-base-20170116:1.17 bouyer-socketcan:1.17.0.84 bouyer-socketcan-base:1.17 pgoyette-localcount-20170107:1.17 netbsd-7-1-RC1:1.17 pgoyette-localcount-20161104:1.17 netbsd-7-0-2-RELEASE:1.17 localcount-20160914:1.17 netbsd-7-nhusb:1.17.0.82 netbsd-7-nhusb-base:1.17 pgoyette-localcount-20160806:1.17 pgoyette-localcount-20160726:1.17 pgoyette-localcount:1.17.0.80 pgoyette-localcount-base:1.17 netbsd-7-0-1-RELEASE:1.17 netbsd-7-0:1.17.0.78 netbsd-7-0-RELEASE:1.17 netbsd-7-0-RC3:1.17 netbsd-7-0-RC2:1.17 netbsd-7-0-RC1:1.17 netbsd-5-2-3-RELEASE:1.17 netbsd-5-1-5-RELEASE:1.17 netbsd-6-0-6-RELEASE:1.17 netbsd-6-1-5-RELEASE:1.17 netbsd-7:1.17.0.76 netbsd-7-base:1.17 yamt-pagecache-base9:1.17 yamt-pagecache-tag8:1.17 netbsd-6-1-4-RELEASE:1.17 netbsd-6-0-5-RELEASE:1.17 tls-earlyentropy:1.17.0.74 tls-earlyentropy-base:1.17 riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.17 riastradh-drm2-base3:1.17 netbsd-6-1-3-RELEASE:1.17 netbsd-6-0-4-RELEASE:1.17 netbsd-5-2-2-RELEASE:1.17 netbsd-5-1-4-RELEASE:1.17 netbsd-6-1-2-RELEASE:1.17 netbsd-6-0-3-RELEASE:1.17 netbsd-5-2-1-RELEASE:1.17 netbsd-5-1-3-RELEASE:1.17 netbsd-6-1-1-RELEASE:1.17 riastradh-drm2-base2:1.17 riastradh-drm2-base1:1.17 riastradh-drm2:1.17.0.66 riastradh-drm2-base:1.17 netbsd-6-1:1.17.0.72 netbsd-6-0-2-RELEASE:1.17 netbsd-6-1-RELEASE:1.17 khorben-n900:1.17.0.70 netbsd-6-1-RC4:1.17 netbsd-6-1-RC3:1.17 agc-symver:1.17.0.68 agc-symver-base:1.17 netbsd-6-1-RC2:1.17 netbsd-6-1-RC1:1.17 yamt-pagecache-base8:1.17 netbsd-5-2:1.17.0.64 netbsd-6-0-1-RELEASE:1.17 yamt-pagecache-base7:1.17 netbsd-5-2-RELEASE:1.17 netbsd-5-2-RC1:1.17 matt-nb6-plus-nbase:1.17 yamt-pagecache-base6:1.17 netbsd-6-0:1.17.0.62 netbsd-6-0-RELEASE:1.17 netbsd-6-0-RC2:1.17 tls-maxphys:1.17.0.60 tls-maxphys-base:1.17 matt-nb6-plus:1.17.0.58 matt-nb6-plus-base:1.17 netbsd-6-0-RC1:1.17 yamt-pagecache-base5:1.17 yamt-pagecache-base4:1.17 netbsd-6:1.17.0.56 netbsd-6-base:1.17 netbsd-5-1-2-RELEASE:1.17 netbsd-5-1-1-RELEASE:1.17 yamt-pagecache-base3:1.17 yamt-pagecache-base2:1.17 yamt-pagecache:1.17.0.54 yamt-pagecache-base:1.17 cherry-xenmp:1.17.0.52 cherry-xenmp-base:1.17 bouyer-quota2-nbase:1.17 bouyer-quota2:1.17.0.50 bouyer-quota2-base:1.17 matt-mips64-premerge-20101231:1.17 matt-nb5-mips64-premerge-20101231:1.17 matt-nb5-pq3:1.17.0.48 matt-nb5-pq3-base:1.17 netbsd-5-1:1.17.0.46 netbsd-5-1-RELEASE:1.17 netbsd-5-1-RC4:1.17 matt-nb5-mips64-k15:1.17 netbsd-5-1-RC3:1.17 netbsd-5-1-RC2:1.17 netbsd-5-1-RC1:1.17 netbsd-5-0-2-RELEASE:1.17 matt-nb5-mips64-premerge-20091211:1.17 matt-premerge-20091211:1.17 matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.17 matt-nb4-mips64-k7-u2a-k9b:1.17 matt-nb5-mips64-u1-k1-k5:1.17 matt-nb5-mips64:1.17.0.44 netbsd-5-0-1-RELEASE:1.17 jym-xensuspend-nbase:1.17 netbsd-5-0:1.17.0.42 netbsd-5-0-RELEASE:1.17 netbsd-5-0-RC4:1.17 netbsd-5-0-RC3:1.17 netbsd-5-0-RC2:1.17 jym-xensuspend:1.17.0.40 jym-xensuspend-base:1.17 netbsd-5-0-RC1:1.17 netbsd-5:1.17.0.38 netbsd-5-base:1.17 matt-mips64-base2:1.17 matt-mips64:1.17.0.36 mjf-devfs2:1.17.0.34 mjf-devfs2-base:1.17 netbsd-4-0-1-RELEASE:1.17 wrstuden-revivesa-base-3:1.17 wrstuden-revivesa-base-2:1.17 wrstuden-fixsa-newbase:1.17 wrstuden-revivesa-base-1:1.17 yamt-pf42-base4:1.17 yamt-pf42-base3:1.17 hpcarm-cleanup-nbase:1.17 yamt-pf42-baseX:1.17 yamt-pf42-base2:1.17 wrstuden-revivesa:1.17.0.32 wrstuden-revivesa-base:1.17 yamt-pf42:1.17.0.30 yamt-pf42-base:1.17 keiichi-mipv6:1.17.0.28 keiichi-mipv6-base:1.17 matt-armv6-nbase:1.17 matt-armv6-prevmlocking:1.17 wrstuden-fixsa-base-1:1.17 netbsd-4-0:1.17.0.26 netbsd-4-0-RELEASE:1.17 cube-autoconf:1.17.0.24 cube-autoconf-base:1.17 netbsd-4-0-RC5:1.17 netbsd-4-0-RC4:1.17 netbsd-4-0-RC3:1.17 netbsd-4-0-RC2:1.17 netbsd-4-0-RC1:1.17 matt-armv6:1.17.0.22 matt-armv6-base:1.17 matt-mips64-base:1.17 hpcarm-cleanup:1.17.0.20 hpcarm-cleanup-base:1.17 netbsd-3-1-1-RELEASE:1.17 netbsd-3-0-3-RELEASE:1.17 wrstuden-fixsa:1.17.0.18 wrstuden-fixsa-base:1.17 abandoned-netbsd-4-base:1.17 abandoned-netbsd-4:1.17.0.12 netbsd-3-1:1.17.0.14 netbsd-3-1-RELEASE:1.17 netbsd-3-0-2-RELEASE:1.17 netbsd-3-1-RC4:1.17 netbsd-3-1-RC3:1.17 netbsd-3-1-RC2:1.17 netbsd-3-1-RC1:1.17 netbsd-4:1.17.0.16 netbsd-4-base:1.17 netbsd-3-0-1-RELEASE:1.17 netbsd-3-0:1.17.0.10 netbsd-3-0-RELEASE:1.17 netbsd-3-0-RC6:1.17 netbsd-3-0-RC5:1.17 netbsd-3-0-RC4:1.17 netbsd-3-0-RC3:1.17 netbsd-3-0-RC2:1.17 netbsd-3-0-RC1:1.17 netbsd-2-0-3-RELEASE:1.17 netbsd-2-1:1.17.0.8 netbsd-2-1-RELEASE:1.17 netbsd-2-1-RC6:1.17 netbsd-2-1-RC5:1.17 netbsd-2-1-RC4:1.17 netbsd-2-1-RC3:1.17 netbsd-2-1-RC2:1.17 netbsd-2-1-RC1:1.17 netbsd-2-0-2-RELEASE:1.17 netbsd-3:1.17.0.6 netbsd-3-base:1.17 netbsd-2-0-1-RELEASE:1.17 netbsd-2:1.17.0.4 netbsd-2-base:1.17 netbsd-2-0-RELEASE:1.17 netbsd-2-0-RC5:1.17 netbsd-2-0-RC4:1.17 netbsd-2-0-RC3:1.17 netbsd-2-0-RC2:1.17 netbsd-2-0-RC1:1.17 netbsd-2-0:1.17.0.2 netbsd-2-0-base:1.17 netbsd-1-6-PATCH002-RELEASE:1.14 netbsd-1-6-PATCH002:1.14 netbsd-1-6-PATCH002-RC4:1.14 netbsd-1-6-PATCH002-RC3:1.14 netbsd-1-6-PATCH002-RC2:1.14 netbsd-1-6-PATCH002-RC1:1.14 netbsd-1-6-PATCH001:1.14 netbsd-1-6-PATCH001-RELEASE:1.14 netbsd-1-6-PATCH001-RC3:1.14 netbsd-1-6-PATCH001-RC2:1.14 netbsd-1-6-PATCH001-RC1:1.14 fvdl_fs64_base:1.14 netbsd-1-6-RELEASE:1.14 netbsd-1-6-RC3:1.14 netbsd-1-6-RC2:1.14 netbsd-1-6-RC1:1.14 netbsd-1-6:1.14.0.2 netbsd-1-6-base:1.14 netbsd-1-5-PATCH003:1.8.10.1 netbsd-1-5-PATCH002:1.8.10.1 netbsd-1-5-PATCH001:1.8.10.1 netbsd-1-5-RELEASE:1.8.10.1 netbsd-1-5-BETA2:1.8.10.1 netbsd-1-5-BETA:1.8.10.1 netbsd-1-4-PATCH003:1.8 netbsd-1-5-ALPHA2:1.8.10.1 netbsd-1-5:1.8.0.10 netbsd-1-5-base:1.8 minoura-xpg4dl:1.8.0.8 minoura-xpg4dl-base:1.8 netbsd-1-4-PATCH002:1.8 wrstuden-devbsize-19991221:1.8 wrstuden-devbsize:1.8.0.6 wrstuden-devbsize-base:1.8 comdex-fall-1999:1.8.0.4 comdex-fall-1999-base:1.8 netbsd-1-4-PATCH001:1.8 netbsd-1-4-RELEASE:1.8 netbsd-1-4:1.8.0.2 netbsd-1-4-base:1.8 netbsd-1-3-PATCH003:1.7 netbsd-1-3-PATCH003-CANDIDATE2:1.7 netbsd-1-3-PATCH003-CANDIDATE1:1.7 netbsd-1-3-PATCH003-CANDIDATE0:1.7 netbsd-1-3-PATCH002:1.7 netbsd-1-3-PATCH001:1.7 netbsd-1-3-RELEASE:1.7 netbsd-1-3-BETA:1.7 netbsd-1-3:1.7.0.2 netbsd-1-3-base:1.7 netbsd-1-2-PATCH001:1.6 netbsd-1-2-RELEASE:1.6 netbsd-1-2-BETA:1.6 netbsd-1-2-base:1.6 netbsd-1-2:1.6.0.4 netbsd-1-1-PATCH001:1.5 netbsd-1-1-RELEASE:1.5 netbsd-1-1:1.5.0.2 netbsd-1-1-base:1.5 lite-2:1.1.1.1 netbsd-1-0-PATCH06:1.2 netbsd-1-0-PATCH05:1.2 netbsd-1-0-PATCH04:1.2 netbsd-1-0-PATCH03:1.2 netbsd-1-0-PATCH02:1.2 netbsd-1-0-PATCH1:1.2 netbsd-1-0-PATCH0:1.2 netbsd-1-0-RELEASE:1.2 lite-1:1.1.1.1 CSRG:1.1.1 netbsd-1-0:1.2.0.2 netbsd-1-0-base:1.2 netbsd-0-9-RELEASE:1.1 netbsd-0-9-BETA:1.1 netbsd-0-9-ALPHA2:1.1 netbsd-0-9-ALPHA:1.1 netbsd-0-9:1.1.0.2 netbsd-0-9-base:1.1; locks; strict; comment @ * @; 1.17 date 2003.08.07.09.05.10; author agc; state Exp; branches 1.17.98.1; next 1.16; 1.16 date 2003.08.05.14.55.03; author erh; state Exp; branches; next 1.15; 1.15 date 2003.08.04.22.31.23; author jschauma; state Exp; branches; next 1.14; 1.14 date 2001.11.26.00.13.23; author lukem; state Exp; branches; next 1.13; 1.13 date 2001.11.25.10.50.06; author lukem; state Exp; branches; next 1.12; 1.12 date 2001.11.25.06.53.48; author lukem; state Exp; branches; next 1.11; 1.11 date 2001.04.28.22.47.23; author ross; state Exp; branches; next 1.10; 1.10 date 2001.01.16.02.41.17; author cgd; state Exp; branches; next 1.9; 1.9 date 2000.07.07.15.10.32; author itojun; state Exp; branches; next 1.8; 1.8 date 98.07.28.05.15.46; author mycroft; state Exp; branches 1.8.10.1; next 1.7; 1.7 date 97.07.20.21.58.37; author christos; state Exp; branches; next 1.6; 1.6 date 96.02.20.19.29.02; author jtc; state Exp; branches; next 1.5; 1.5 date 95.10.08.23.01.23; author gwr; state Exp; branches; next 1.4; 1.4 date 95.03.21.09.04.01; author cgd; state Exp; branches; next 1.3; 1.3 date 94.09.22.09.24.58; author mycroft; state Exp; branches; next 1.2; 1.2 date 93.08.01.19.00.11; author mycroft; state Exp; branches; next 1.1; 1.1 date 93.05.04.07.08.47; author glass; state Exp; branches 1.1.1.1; next ; 1.17.98.1 date 2020.04.21.18.41.03; author martin; state dead; branches; next 1.17.98.2; commitid 86tA4aEmdr3VCh5C; 1.17.98.2 date 2020.04.21.19.37.31; author martin; state Exp; branches; next ; commitid x6IB64bYH9UmWh5C; 1.8.10.1 date 2000.07.27.16.15.28; author itojun; state Exp; branches; next ; 1.1.1.1 date 94.09.22.03.04.34; author mycroft; state Exp; branches; next ; desc @@ 1.17 log @Move UCB-licensed code from 4-clause to 3-clause licence. Patches provided by Joel Baker in PR 22249, verified by myself. @ text @/* $NetBSD: conv.c,v 1.16 2003/08/05 14:55:03 erh Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Keith Muller of the University of California, San Diego and Lance * Visser of Convex Computer Corporation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #ifndef lint #if 0 static char sccsid[] = "@@(#)conv.c 8.3 (Berkeley) 4/2/94"; #else __RCSID("$NetBSD: conv.c,v 1.16 2003/08/05 14:55:03 erh Exp $"); #endif #endif /* not lint */ #include #include #include #include #include #include "dd.h" #include "extern.h" /* * def -- * Copy input to output. Input is buffered until reaches obs, and then * output until less than obs remains. Only a single buffer is used. * Worst case buffer calculation is (ibs + obs - 1). */ void def(void) { uint64_t cnt; u_char *inp; const u_char *t; if ((t = ctab) != NULL) for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp) *inp = t[*inp]; /* Make the output buffer look right. */ out.dbp = in.dbp; out.dbcnt = in.dbcnt; if (in.dbcnt >= out.dbsz) { /* If the output buffer is full, write it. */ dd_out(0); /* * Ddout copies the leftover output to the beginning of * the buffer and resets the output buffer. Reset the * input buffer to match it. */ in.dbp = out.dbp; in.dbcnt = out.dbcnt; } } void def_close(void) { /* Just update the count, everything is already in the buffer. */ if (in.dbcnt) out.dbcnt = in.dbcnt; } #ifdef NO_CONV /* Build a smaller version (i.e. for a miniroot) */ /* These can not be called, but just in case... */ static const char no_block[] = "unblock and -DNO_CONV?"; void block(void) { errx(EXIT_FAILURE, "%s", no_block + 2); } void block_close(void) { errx(EXIT_FAILURE, "%s", no_block + 2); } void unblock(void) { errx(EXIT_FAILURE, "%s", no_block); } void unblock_close(void) { errx(EXIT_FAILURE, "%s", no_block); } #else /* NO_CONV */ /* * Copy variable length newline terminated records with a max size cbsz * bytes to output. Records less than cbs are padded with spaces. * * max in buffer: MAX(ibs, cbsz) * max out buffer: obs + cbsz */ void block(void) { static int intrunc; int ch = 0; /* pacify gcc */ uint64_t cnt, maxlen; u_char *inp, *outp; const u_char *t; /* * Record truncation can cross block boundaries. If currently in a * truncation state, keep tossing characters until reach a newline. * Start at the beginning of the buffer, as the input buffer is always * left empty. */ if (intrunc) { for (inp = in.db, cnt = in.dbrcnt; cnt && *inp++ != '\n'; --cnt); if (!cnt) { in.dbcnt = 0; in.dbp = in.db; return; } intrunc = 0; /* Adjust the input buffer numbers. */ in.dbcnt = cnt - 1; in.dbp = inp + cnt - 1; } /* * Copy records (max cbsz size chunks) into the output buffer. The * translation is done as we copy into the output buffer. */ for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) { maxlen = MIN(cbsz, in.dbcnt); if ((t = ctab) != NULL) for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n'; ++cnt) *outp++ = t[ch]; else for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n'; ++cnt) *outp++ = ch; /* * Check for short record without a newline. Reassemble the * input block. */ if (ch != '\n' && in.dbcnt < cbsz) { (void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt); break; } /* Adjust the input buffer numbers. */ in.dbcnt -= cnt; if (ch == '\n') --in.dbcnt; /* Pad short records with spaces. */ if (cnt < cbsz) (void)memset(outp, ctab ? ctab[' '] : ' ', cbsz - cnt); else { /* * If the next character wouldn't have ended the * block, it's a truncation. */ if (!in.dbcnt || *inp != '\n') ++st.trunc; /* Toss characters to a newline. */ for (; in.dbcnt && *inp++ != '\n'; --in.dbcnt); if (!in.dbcnt) intrunc = 1; else --in.dbcnt; } /* Adjust output buffer numbers. */ out.dbp += cbsz; if ((out.dbcnt += cbsz) >= out.dbsz) dd_out(0); outp = out.dbp; } in.dbp = in.db + in.dbcnt; } void block_close(void) { /* * Copy any remaining data into the output buffer and pad to a record. * Don't worry about truncation or translation, the input buffer is * always empty when truncating, and no characters have been added for * translation. The bottom line is that anything left in the input * buffer is a truncated record. Anything left in the output buffer * just wasn't big enough. */ if (in.dbcnt) { ++st.trunc; (void)memmove(out.dbp, in.dbp - in.dbcnt, in.dbcnt); (void)memset(out.dbp + in.dbcnt, ctab ? ctab[' '] : ' ', cbsz - in.dbcnt); out.dbcnt += cbsz; } } /* * Convert fixed length (cbsz) records to variable length. Deletes any * trailing blanks and appends a newline. * * max in buffer: MAX(ibs, cbsz) + cbsz * max out buffer: obs + cbsz */ void unblock(void) { uint64_t cnt; u_char *inp; const u_char *t; /* Translation and case conversion. */ if ((t = ctab) != NULL) for (cnt = in.dbrcnt, inp = in.dbp - 1; cnt--; inp--) *inp = t[*inp]; /* * Copy records (max cbsz size chunks) into the output buffer. The * translation has to already be done or we might not recognize the * spaces. */ for (inp = in.db; in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) { for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t); if (t >= inp) { cnt = t - inp + 1; (void)memmove(out.dbp, inp, cnt); out.dbp += cnt; out.dbcnt += cnt; } ++out.dbcnt; *out.dbp++ = '\n'; if (out.dbcnt >= out.dbsz) dd_out(0); } if (in.dbcnt) (void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt); in.dbp = in.db + in.dbcnt; } void unblock_close(void) { uint64_t cnt; u_char *t; if (in.dbcnt) { warnx("%s: short input record", in.name); for (t = in.db + in.dbcnt - 1; t >= in.db && *t == ' '; --t); if (t >= in.db) { cnt = t - in.db + 1; (void)memmove(out.dbp, in.db, cnt); out.dbp += cnt; out.dbcnt += cnt; } ++out.dbcnt; *out.dbp++ = '\n'; } } #endif /* NO_CONV */ @ 1.17.98.1 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.17 2003/08/07 09:05:10 agc Exp $ */ d41 1 a41 1 __RCSID("$NetBSD: conv.c,v 1.17 2003/08/07 09:05:10 agc Exp $"); @ 1.17.98.2 log @Ooops, restore accidently removed files from merge mishap @ text @@ 1.16 log @Include stdlib.h so EXIT_FAILURE is defined. @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.15 2003/08/04 22:31:23 jschauma Exp $ */ d19 1 a19 5 * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors d41 1 a41 1 __RCSID("$NetBSD: conv.c,v 1.15 2003/08/04 22:31:23 jschauma Exp $"); @ 1.15 log @As discusses a little while back on tech-userlevel: If stdout is a tty, use vis(3) to print any filenames to prevent garbage from being printed if the filename contains control- or other non-printable characters. While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate. @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.14 2001/11/26 00:13:23 lukem Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.14 2001/11/26 00:13:23 lukem Exp $"); d54 1 @ 1.14 log @Replace {u_,}longlong_t usage with {u,}int64_t, as the former has "issues" and really shouldn't be used outside of the Sun XDR stuff. Thanks again to Chuck Silvers for reminding me. @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.13 2001/11/25 10:50:06 lukem Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.13 2001/11/25 10:50:06 lukem Exp $"); d106 4 a109 4 void block(void) { errx(1, "%s", no_block + 2); } void block_close(void) { errx(1, "%s", no_block + 2); } void unblock(void) { errx(1, "%s", no_block); } void unblock_close(void) { errx(1, "%s", no_block); } @ 1.13 log @- Use u_longlong_t instead of u_quad_t, u_long, or int for various buffer sizes - Add strsuftoull(), which parses a number into a u_longlong_t, with multiplication support, and support for 'g' (GB) and 't' (TB) suffices. If an error occurs, print to stderr and exit. Based on get_blk() from args.c and strsufto*() (in other programs) - Add strsuftoullx(), which acts as per strsuftoull() but returns the error in the supplied buffer instead (if the returned buffer != "", an error occurred) - Replace get_bsz() use with strsuftoull() - Remove (now) unnecessary argument validation - Remove unused {f,p,s,t}_stats fields in struct IO @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.12 2001/11/25 06:53:48 lukem Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.12 2001/11/25 06:53:48 lukem Exp $"); d67 1 a67 1 u_longlong_t cnt; d124 1 a124 1 u_longlong_t cnt, maxlen; d235 1 a235 1 u_longlong_t cnt; d269 1 a269 1 u_longlong_t cnt; @ 1.12 log @- ANSI KNF - WARNS=2 (mainly converting some "char *" -> "const char *") @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.11 2001/04/28 22:47:23 ross Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.11 2001/04/28 22:47:23 ross Exp $"); d67 1 a67 1 int cnt; d124 1 a124 1 int cnt, maxlen; d235 1 a235 1 int cnt; d269 1 a269 1 int cnt; @ 1.11 log @In the words of Our Fearless Leader, I am "utterly sick" of dd(1) lying to me about transfer rates. Do some fixed point frobbing to get stuff like: 2486864 bytes transferred in 0.272 secs (9142882 bytes/sec) @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.10 2001/01/16 02:41:17 cgd Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.10 2001/01/16 02:41:17 cgd Exp $"); d65 1 a65 1 def() d94 1 a94 1 def_close() d96 1 d105 5 a109 5 static char no_block[] = "unblock and -DNO_CONV?"; void block() { errx(1, "%s", no_block + 2); } void block_close() { errx(1, "%s", no_block + 2); } void unblock() { errx(1, "%s", no_block); } void unblock_close() { errx(1, "%s", no_block); } d120 1 a120 1 block() d205 1 a205 1 block_close() d207 1 d233 1 a233 1 unblock() d267 1 a267 1 unblock_close() @ 1.10 log @avoid C sequence point issues warned about by development version of gcc. @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.9 2000/07/07 15:10:32 itojun Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.9 2000/07/07 15:10:32 itojun Exp $"); d50 1 @ 1.9 log @errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.8 1998/07/28 05:15:46 mycroft Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.8 1998/07/28 05:15:46 mycroft Exp $"); d238 2 a239 2 for (cnt = in.dbrcnt, inp = in.dbp; cnt--;) *--inp = t[*inp]; @ 1.8 log @Delint. @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.7 1997/07/20 21:58:37 christos Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.7 1997/07/20 21:58:37 christos Exp $"); d104 4 a107 4 void block() { errx(1, no_block + 2); } void block_close() { errx(1, no_block + 2); } void unblock() { errx(1, no_block); } void unblock_close() { errx(1, no_block); } @ 1.8.10.1 log @pullup (approved by releng-1-5) printf-like format pedant. do not pass string variable alone. use "%s". from openbsd. /cvsroot/basesrc/bin/dd/conv.c 1.8 -> 1.9 /cvsroot/basesrc/bin/cp/cp.c 1.29 -> 1.30 /cvsroot/basesrc/bin/chmod/chmod.c 1.22 -> 1.23 @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.8 1998/07/28 05:15:46 mycroft Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: conv.c,v 1.8 1998/07/28 05:15:46 mycroft Exp $"); d104 4 a107 4 void block() { errx(1, "%s", no_block + 2); } void block_close() { errx(1, "%s", no_block + 2); } void unblock() { errx(1, "%s", no_block); } void unblock_close() { errx(1, "%s", no_block); } @ 1.7 log @Fix compiler warnings. Add WARNS=1 @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.6 1996/02/20 19:29:02 jtc Exp $ */ d45 1 a45 1 __RCSID("$NetBSD$"); d165 1 a165 1 memmove(in.db, in.dbp - in.dbcnt, in.dbcnt); d215 1 a215 1 memmove(out.dbp, in.dbp - in.dbcnt, in.dbcnt); d249 1 a249 1 memmove(out.dbp, inp, cnt); d259 1 a259 1 memmove(in.db, in.dbp - in.dbcnt, in.dbcnt); d274 1 a274 1 memmove(out.dbp, in.db, cnt); @ 1.6 log @Re-do change to use const qualifer with conversion tables. Fixed bug where pre-computed upper/lower case conversion tables were used. This won't work if user selected a different locale. @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.5 1995/10/08 23:01:23 gwr Exp $ */ d40 1 d45 1 a45 1 static char rcsid[] = "$NetBSD: conv.c,v 1.5 1995/10/08 23:01:23 gwr Exp $"; d70 1 a70 1 if (t = ctab) d121 2 a122 1 int ch, cnt, maxlen; d152 1 a152 1 if (t = ctab) d237 1 a237 1 if (t = ctab) @ 1.5 log @Add -DNO_CONV to make this smaller in my ramdisk. @ text @d1 1 a1 1 /* $NetBSD: conv.c,v 1.4 1995/03/21 09:04:01 cgd Exp $ */ d44 1 a44 1 static char rcsid[] = "$NetBSD: conv.c,v 1.4 1995/03/21 09:04:01 cgd Exp $"; d66 2 a67 1 u_char *inp, *t; d121 2 a122 1 u_char *inp, *outp, *t; d231 2 a232 1 u_char *inp, *t; @ 1.4 log @convert to new RCS id conventions. @ text @d1 1 a1 1 /* $NetBSD$ */ d44 1 a44 1 static char rcsid[] = "$NetBSD$"; d98 10 d277 2 @ 1.3 log @Merge 4.4-Lite version. @ text @d1 2 d41 5 a45 2 /*static char sccsid[] = "from: @@(#)conv.c 8.3 (Berkeley) 4/2/94";*/ static char *rcsid = "$Id: $"; @ 1.2 log @Add RCS identifiers. @ text @d2 2 a3 2 * Copyright (c) 1991 The Regents of the University of California. * All rights reserved. d39 2 a40 2 /*static char sccsid[] = "from: @@(#)conv.c 5.6 (Berkeley) 4/28/93";*/ static char rcsid[] = "$Id: $"; d45 1 d60 2 a61 2 register int cnt; register u_char *inp, *t; d104 2 a105 3 register int ch, cnt; register u_char *inp, *outp, *t; int maxlen; d213 2 a214 2 register int cnt; register u_char *inp, *t; d246 2 a247 2 register int cnt; register u_char *t; d250 1 a250 1 warn("%s: short input record", in.name); @ 1.1 log @added dd(1) from ftp.uu.net:bsd-sources; torching GNU dd @ text @d39 2 a40 1 static char sccsid[] = "@@(#)conv.c 5.6 (Berkeley) 4/28/93"; @ 1.1.1.1 log @Import original 4.4-Lite version. @ text @d2 2 a3 2 * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. d39 1 a39 1 static char sccsid[] = "@@(#)conv.c 8.3 (Berkeley) 4/2/94"; a43 1 #include d58 2 a59 2 int cnt; u_char *inp, *t; d102 3 a104 2 int ch, cnt, maxlen; u_char *inp, *outp, *t; d212 2 a213 2 int cnt; u_char *inp, *t; d245 2 a246 2 int cnt; u_char *t; d249 1 a249 1 warnx("%s: short input record", in.name); @