Deleted Added
full compact
conv.c (273734) conv.c (273743)
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Keith Muller of the University of California, San Diego and Lance
7 * Visser of Convex Computer Corporation.
8 *

--- 23 unchanged lines hidden (view full) ---

32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
37#endif
38#endif /* not lint */
39#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Keith Muller of the University of California, San Diego and Lance
7 * Visser of Convex Computer Corporation.
8 *

--- 23 unchanged lines hidden (view full) ---

32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
37#endif
38#endif /* not lint */
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD: head/bin/dd/conv.c 273734 2014-10-27 11:38:17Z pi $");
40__FBSDID("$FreeBSD: head/bin/dd/conv.c 273743 2014-10-27 17:39:37Z pi $");
41
42#include <sys/param.h>
43
44#include <err.h>
45#include <inttypes.h>
46#include <string.h>
47
48#include "dd.h"

--- 79 unchanged lines hidden (view full) ---

128 }
129
130 /*
131 * Copy records (max cbsz size chunks) into the output buffer. The
132 * translation is done as we copy into the output buffer.
133 */
134 ch = 0;
135 for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) {
41
42#include <sys/param.h>
43
44#include <err.h>
45#include <inttypes.h>
46#include <string.h>
47
48#include "dd.h"

--- 79 unchanged lines hidden (view full) ---

128 }
129
130 /*
131 * Copy records (max cbsz size chunks) into the output buffer. The
132 * translation is done as we copy into the output buffer.
133 */
134 ch = 0;
135 for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) {
136 maxlen = MIN(cbsz, (size_t)in.dbcnt);
136 maxlen = MIN(cbsz, in.dbcnt);
137 if ((t = ctab) != NULL)
138 for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
139 ++cnt)
140 *outp++ = t[ch];
141 else
142 for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
143 ++cnt)
144 *outp++ = ch;
145 /*
146 * Check for short record without a newline. Reassemble the
147 * input block.
148 */
137 if ((t = ctab) != NULL)
138 for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
139 ++cnt)
140 *outp++ = t[ch];
141 else
142 for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
143 ++cnt)
144 *outp++ = ch;
145 /*
146 * Check for short record without a newline. Reassemble the
147 * input block.
148 */
149 if (ch != '\n' && (size_t)in.dbcnt < cbsz) {
149 if (ch != '\n' && in.dbcnt < cbsz) {
150 (void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
151 break;
152 }
153
154 /* Adjust the input buffer numbers. */
155 in.dbcnt -= cnt;
156 if (ch == '\n')
157 --in.dbcnt;

--- 65 unchanged lines hidden (view full) ---

223 if ((t = ctab) != NULL)
224 for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
225 *inp = t[*inp];
226 /*
227 * Copy records (max cbsz size chunks) into the output buffer. The
228 * translation has to already be done or we might not recognize the
229 * spaces.
230 */
150 (void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
151 break;
152 }
153
154 /* Adjust the input buffer numbers. */
155 in.dbcnt -= cnt;
156 if (ch == '\n')
157 --in.dbcnt;

--- 65 unchanged lines hidden (view full) ---

223 if ((t = ctab) != NULL)
224 for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
225 *inp = t[*inp];
226 /*
227 * Copy records (max cbsz size chunks) into the output buffer. The
228 * translation has to already be done or we might not recognize the
229 * spaces.
230 */
231 for (inp = in.db; (size_t)in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) {
231 for (inp = in.db; in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) {
232 for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t)
233 ;
234 if (t >= inp) {
235 cnt = t - inp + 1;
236 (void)memmove(out.dbp, inp, cnt);
237 out.dbp += cnt;
238 out.dbcnt += cnt;
239 }

--- 29 unchanged lines hidden ---
232 for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t)
233 ;
234 if (t >= inp) {
235 cnt = t - inp + 1;
236 (void)memmove(out.dbp, inp, cnt);
237 out.dbp += cnt;
238 out.dbcnt += cnt;
239 }

--- 29 unchanged lines hidden ---