home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / backup / star-1.3.1.tar.gz / star-1.3.1.tar / star-1.3.1 / lib / printf.c < prev    next >
C/C++ Source or Header  |  2000-05-07  |  2KB  |  121 lines

  1. /* @(#)printf.c    1.12 00/05/07 Copyright 1985 J. Schilling */
  2. /*
  3.  *    Copyright (c) 1985 J. Schilling
  4.  */
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <mconfig.h>
  22. #include <stdio.h>
  23. #include <vadefs.h>
  24. #include <standard.h>
  25. #include <schily.h>
  26.  
  27. #define BFSIZ    256
  28.  
  29. typedef struct {
  30.     short    cnt;
  31.     char    *ptr;
  32.     char    buf[BFSIZ];
  33.     int    count;
  34.     FILE    *f;
  35. } *BUF, _BUF;
  36.  
  37. LOCAL void _bflush    __PR((BUF));
  38. LOCAL void _bput    __PR((char, long));
  39.  
  40. LOCAL void _bflush (bp)
  41.     register BUF    bp;
  42. {
  43.     bp->count += bp->ptr - bp->buf;
  44.     if (filewrite (bp->f, bp->buf, bp->ptr - bp->buf) < 0)
  45.         bp->count = EOF;
  46.     bp->ptr = bp->buf;
  47.     bp->cnt = BFSIZ;
  48. }
  49.  
  50. #ifdef    PROTOTYPES
  51. LOCAL void _bput (char c, long l)
  52. #else
  53. LOCAL void _bput (c, l)
  54.         char    c;
  55.         long    l;
  56. #endif
  57.     register BUF    bp = (BUF)l;
  58.  
  59.     *bp->ptr++ = c;
  60.     if (--bp->cnt <= 0)
  61.         _bflush (bp);
  62. }
  63.  
  64. /* VARARGS2 */
  65. #ifdef    PROTOTYPES
  66. EXPORT int printf(const char *form, ...)
  67. #else
  68. EXPORT int printf(form, va_alist)
  69.     char    *form;
  70.     va_dcl
  71. #endif
  72. {
  73.     va_list    args;
  74.     _BUF    bb;
  75.  
  76.     bb.ptr = bb.buf;
  77.     bb.cnt = BFSIZ;
  78.     bb.count = 0;
  79.     bb.f = stdout;
  80. #ifdef    PROTOTYPES
  81.     va_start(args, form);
  82. #else
  83.     va_start(args);
  84. #endif
  85.     format(_bput, (long)&bb, form, args);
  86.     va_end(args);
  87.     if (bb.cnt < BFSIZ)
  88.         _bflush (&bb);
  89.     return (bb.count);
  90. }
  91.  
  92. /* VARARGS3 */
  93. #ifdef    PROTOTYPES
  94. EXPORT int fprintf(FILE *file, const char *form, ...)
  95. #else
  96. EXPORT int fprintf(file, form, va_alist)
  97.     FILE    *file;
  98.     char    *form;
  99.     va_dcl
  100. #endif
  101. {
  102.     va_list    args;
  103.     _BUF    bb;
  104.  
  105.     bb.ptr = bb.buf;
  106.     bb.cnt = BFSIZ;
  107.     bb.count = 0;
  108.     bb.f = file;
  109. #ifdef    PROTOTYPES
  110.     va_start(args, form);
  111. #else
  112.     va_start(args);
  113. #endif
  114.     format(_bput, (long)&bb, form, args);
  115.     va_end(args);
  116.     if (bb.cnt < BFSIZ)
  117.         _bflush (&bb);
  118.     return (bb.count);
  119. }
  120.