Deleted Added
full compact
output.c (17987) output.c (18018)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id: output.c,v 1.2 1994/09/24 02:58:06 davidg Exp $
36 * $Id: output.c,v 1.3 1996/09/01 10:21:23 peter Exp $
37 */
38
39#ifndef lint
40static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95";
41#endif /* not lint */
42
43/*
44 * Shell output routines. We use our own output routines because:
45 * When a builtin command is interrupted we have to discard
46 * any pending output.
47 * When a builtin command appears in back quotes, we want to
48 * save the output of the command in a region obtained
49 * via malloc, rather than doing a fork and reading the
50 * output of the command via a pipe.
51 * Our output routines may be smaller than the stdio routines.
52 */
53
54#include <sys/ioctl.h>
37 */
38
39#ifndef lint
40static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95";
41#endif /* not lint */
42
43/*
44 * Shell output routines. We use our own output routines because:
45 * When a builtin command is interrupted we have to discard
46 * any pending output.
47 * When a builtin command appears in back quotes, we want to
48 * save the output of the command in a region obtained
49 * via malloc, rather than doing a fork and reading the
50 * output of the command via a pipe.
51 * Our output routines may be smaller than the stdio routines.
52 */
53
54#include <sys/ioctl.h>
55#include <sys/types.h> /* quad_t */
55
56#include <stdio.h> /* defines BUFSIZ */
57#include <string.h>
58#ifdef __STDC__
59#include <stdarg.h>
60#else
61#include <varargs.h>
62#endif

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

332}
333#endif /* __STDC__ */
334
335
336/*
337 * Formatted output. This routine handles a subset of the printf formats:
338 * - Formats supported: d, u, o, X, s, and c.
339 * - The x format is also accepted but is treated like X.
56
57#include <stdio.h> /* defines BUFSIZ */
58#include <string.h>
59#ifdef __STDC__
60#include <stdarg.h>
61#else
62#include <varargs.h>
63#endif

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

333}
334#endif /* __STDC__ */
335
336
337/*
338 * Formatted output. This routine handles a subset of the printf formats:
339 * - Formats supported: d, u, o, X, s, and c.
340 * - The x format is also accepted but is treated like X.
340 * - The l modifier is accepted.
341 * - The l and q modifiers is accepted.
341 * - The - and # flags are accepted; # only works with the o format.
342 * - Width and precision may be specified with any format except c.
343 * - An * may be given for the width or precision.
344 * - The obsolete practice of preceding the width with a zero to get
345 * zero padding is not supported; use the precision field.
346 * - A % may be printed by writing %% in the format string.
347 */
348
349#define TEMPSIZE 24
350
351#ifdef __STDC__
342 * - The - and # flags are accepted; # only works with the o format.
343 * - Width and precision may be specified with any format except c.
344 * - An * may be given for the width or precision.
345 * - The obsolete practice of preceding the width with a zero to get
346 * zero padding is not supported; use the precision field.
347 * - A % may be printed by writing %% in the format string.
348 */
349
350#define TEMPSIZE 24
351
352#ifdef __STDC__
352static const char digit[16] = "0123456789ABCDEF";
353static const char digit[] = "0123456789ABCDEF";
353#else
354static const char digit[17] = "0123456789ABCDEF";
355#endif
356
357
358void
359doformat(dest, f, ap)
360 register struct output *dest;
361 register char *f; /* format string */
362 va_list ap;
363 {
364 register char c;
365 char temp[TEMPSIZE];
366 int flushleft;
367 int sharp;
368 int width;
369 int prec;
370 int islong;
354#else
355static const char digit[17] = "0123456789ABCDEF";
356#endif
357
358
359void
360doformat(dest, f, ap)
361 register struct output *dest;
362 register char *f; /* format string */
363 va_list ap;
364 {
365 register char c;
366 char temp[TEMPSIZE];
367 int flushleft;
368 int sharp;
369 int width;
370 int prec;
371 int islong;
372 int isquad;
371 char *p;
372 int sign;
373 char *p;
374 int sign;
373 long l;
374 unsigned long num;
375 quad_t l;
376 u_quad_t num;
375 unsigned base;
376 int len;
377 int size;
378 int pad;
379
380 while ((c = *f++) != '\0') {
381 if (c != '%') {
382 outc(c, dest);
383 continue;
384 }
385 flushleft = 0;
386 sharp = 0;
387 width = 0;
388 prec = -1;
389 islong = 0;
377 unsigned base;
378 int len;
379 int size;
380 int pad;
381
382 while ((c = *f++) != '\0') {
383 if (c != '%') {
384 outc(c, dest);
385 continue;
386 }
387 flushleft = 0;
388 sharp = 0;
389 width = 0;
390 prec = -1;
391 islong = 0;
392 isquad = 0;
390 for (;;) {
391 if (*f == '-')
392 flushleft++;
393 else if (*f == '#')
394 sharp++;
395 else
396 break;
397 f++;

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

413 while (is_digit(*f)) {
414 prec = 10 * prec + digit_val(*f++);
415 }
416 }
417 }
418 if (*f == 'l') {
419 islong++;
420 f++;
393 for (;;) {
394 if (*f == '-')
395 flushleft++;
396 else if (*f == '#')
397 sharp++;
398 else
399 break;
400 f++;

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

416 while (is_digit(*f)) {
417 prec = 10 * prec + digit_val(*f++);
418 }
419 }
420 }
421 if (*f == 'l') {
422 islong++;
423 f++;
424 } else if (*f == 'q') {
425 isquad++;
426 f++;
421 }
422 switch (*f) {
423 case 'd':
424 if (islong)
425 l = va_arg(ap, long);
427 }
428 switch (*f) {
429 case 'd':
430 if (islong)
431 l = va_arg(ap, long);
432 else if (isquad)
433 l = va_arg(ap, quad_t);
426 else
427 l = va_arg(ap, int);
428 sign = 0;
429 num = l;
430 if (l < 0) {
431 num = -l;
432 sign = 1;
433 }

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

442 case 'x':
443 /* we don't implement 'x'; treat like 'X' */
444 case 'X':
445 base = 16;
446uns_number: /* an unsigned number */
447 sign = 0;
448 if (islong)
449 num = va_arg(ap, unsigned long);
434 else
435 l = va_arg(ap, int);
436 sign = 0;
437 num = l;
438 if (l < 0) {
439 num = -l;
440 sign = 1;
441 }

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

450 case 'x':
451 /* we don't implement 'x'; treat like 'X' */
452 case 'X':
453 base = 16;
454uns_number: /* an unsigned number */
455 sign = 0;
456 if (islong)
457 num = va_arg(ap, unsigned long);
458 else if (isquad)
459 num = va_arg(ap, u_quad_t);
450 else
451 num = va_arg(ap, unsigned int);
452number: /* process a number */
453 p = temp + TEMPSIZE - 1;
454 *p = '\0';
455 while (num) {
456 *--p = digit[num % base];
457 num /= base;

--- 110 unchanged lines hidden ---
460 else
461 num = va_arg(ap, unsigned int);
462number: /* process a number */
463 p = temp + TEMPSIZE - 1;
464 *p = '\0';
465 while (num) {
466 *--p = digit[num % base];
467 num /= base;

--- 110 unchanged lines hidden ---