output.c (18018) | output.c (20425) |
---|---|
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.3 1996/09/01 10:21:23 peter Exp $ | 36 * $Id: output.c,v 1.4 1996/09/03 14:15:56 peter Exp $ |
37 */ 38 39#ifndef lint | 37 */ 38 39#ifndef lint |
40static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95"; | 40static char const 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 | 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/types.h> /* quad_t */ |
|
54#include <sys/ioctl.h> | 55#include <sys/ioctl.h> |
55#include <sys/types.h> /* quad_t */ | |
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. | 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. |
341 * - The l and q modifiers is accepted. | 341 * - The l and q modifiers are accepted. |
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 | 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__ | |
353static const char digit[] = "0123456789ABCDEF"; | 352static const char digit[] = "0123456789ABCDEF"; |
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 { --- 57 unchanged lines hidden (view full) --- 422 islong++; 423 f++; 424 } else if (*f == 'q') { 425 isquad++; 426 f++; 427 } 428 switch (*f) { 429 case 'd': | 353 354 355void 356doformat(dest, f, ap) 357 register struct output *dest; 358 register char *f; /* format string */ 359 va_list ap; 360 { --- 57 unchanged lines hidden (view full) --- 418 islong++; 419 f++; 420 } else if (*f == 'q') { 421 isquad++; 422 f++; 423 } 424 switch (*f) { 425 case 'd': |
430 if (islong) 431 l = va_arg(ap, long); 432 else if (isquad) | 426 if (isquad) |
433 l = va_arg(ap, quad_t); | 427 l = va_arg(ap, quad_t); |
428 else if (islong) 429 l = va_arg(ap, 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 } --- 6 unchanged lines hidden (view full) --- 448 base = 8; 449 goto uns_number; 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; | 430 else 431 l = va_arg(ap, int); 432 sign = 0; 433 num = l; 434 if (l < 0) { 435 num = -l; 436 sign = 1; 437 } --- 6 unchanged lines hidden (view full) --- 444 base = 8; 445 goto uns_number; 446 case 'x': 447 /* we don't implement 'x'; treat like 'X' */ 448 case 'X': 449 base = 16; 450uns_number: /* an unsigned number */ 451 sign = 0; |
456 if (islong) 457 num = va_arg(ap, unsigned long); 458 else if (isquad) | 452 if (isquad) |
459 num = va_arg(ap, u_quad_t); | 453 num = va_arg(ap, u_quad_t); |
454 else if (islong) 455 num = va_arg(ap, unsigned long); |
|
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; --- 92 unchanged lines hidden (view full) --- 560 561 562/* 563 * Version of ioctl that retries after a signal is caught. 564 * XXX unused function 565 */ 566 567int | 456 else 457 num = va_arg(ap, unsigned int); 458number: /* process a number */ 459 p = temp + TEMPSIZE - 1; 460 *p = '\0'; 461 while (num) { 462 *--p = digit[num % base]; 463 num /= base; --- 92 unchanged lines hidden (view full) --- 556 557 558/* 559 * Version of ioctl that retries after a signal is caught. 560 * XXX unused function 561 */ 562 563int |
568xioctl(fd, request, arg) | 564xioctl(fd, request, arg) |
569 int fd; 570 unsigned long request; 571 char * arg; 572{ 573 int i; 574 575 while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR); 576 return i; 577} | 565 int fd; 566 unsigned long request; 567 char * arg; 568{ 569 int i; 570 571 while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR); 572 return i; 573} |