OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [sys/] [linux/] [argp/] [argp-fmtstream.c] - Diff between revs 207 and 520

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 520
/* Word-wrapping and line-truncating streams
/* Word-wrapping and line-truncating streams
   Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
   Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   This file is part of the GNU C Library.
   Written by Miles Bader <miles@gnu.ai.mit.edu>.
   Written by Miles Bader <miles@gnu.ai.mit.edu>.
 
 
   The GNU C Library is free software; you can redistribute it and/or
   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.
   version 2.1 of the License, or (at your option) any later version.
 
 
   The GNU C Library is distributed in the hope that it will be useful,
   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
   Lesser General Public License for more details.
 
 
   You should have received a copy of the GNU Lesser General Public
   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */
   02111-1307 USA.  */
 
 
/* This package emulates glibc `line_wrap_stream' semantics for systems that
/* This package emulates glibc `line_wrap_stream' semantics for systems that
   don't have that.  */
   don't have that.  */
 
 
#ifdef HAVE_CONFIG_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#include <config.h>
#endif
#endif
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <errno.h>
#include <stdarg.h>
#include <stdarg.h>
#include <ctype.h>
#include <ctype.h>
 
 
#include "argp-fmtstream.h"
#include "argp-fmtstream.h"
#include "argp-namefrob.h"
#include "argp-namefrob.h"
 
 
#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
 
 
#ifndef isblank
#ifndef isblank
#define isblank(ch) ((ch)==' ' || (ch)=='\t')
#define isblank(ch) ((ch)==' ' || (ch)=='\t')
#endif
#endif
 
 
#if defined _LIBC && defined USE_IN_LIBIO
#if defined _LIBC && defined USE_IN_LIBIO
# include <wchar.h>
# include <wchar.h>
# include <libio/libioP.h>
# include <libio/libioP.h>
# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
#endif
#endif
 
 
#define INIT_BUF_SIZE 200
#define INIT_BUF_SIZE 200
#define PRINTF_SIZE_GUESS 150
#define PRINTF_SIZE_GUESS 150


/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
   written on it with LMARGIN spaces and limits them to RMARGIN columns
   written on it with LMARGIN spaces and limits them to RMARGIN columns
   total.  If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
   total.  If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
   replacing the whitespace before them with a newline and WMARGIN spaces.
   replacing the whitespace before them with a newline and WMARGIN spaces.
   Otherwise, chars beyond RMARGIN are simply dropped until a newline.
   Otherwise, chars beyond RMARGIN are simply dropped until a newline.
   Returns NULL if there was an error.  */
   Returns NULL if there was an error.  */
argp_fmtstream_t
argp_fmtstream_t
__argp_make_fmtstream (FILE *stream,
__argp_make_fmtstream (FILE *stream,
                       size_t lmargin, size_t rmargin, ssize_t wmargin)
                       size_t lmargin, size_t rmargin, ssize_t wmargin)
{
{
  argp_fmtstream_t fs;
  argp_fmtstream_t fs;
 
 
  fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
  fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
  if (fs != NULL)
  if (fs != NULL)
    {
    {
      fs->stream = stream;
      fs->stream = stream;
 
 
      fs->lmargin = lmargin;
      fs->lmargin = lmargin;
      fs->rmargin = rmargin;
      fs->rmargin = rmargin;
      fs->wmargin = wmargin;
      fs->wmargin = wmargin;
      fs->point_col = 0;
      fs->point_col = 0;
      fs->point_offs = 0;
      fs->point_offs = 0;
 
 
      fs->buf = (char *) malloc (INIT_BUF_SIZE);
      fs->buf = (char *) malloc (INIT_BUF_SIZE);
      if (! fs->buf)
      if (! fs->buf)
        {
        {
          free (fs);
          free (fs);
          fs = 0;
          fs = 0;
        }
        }
      else
      else
        {
        {
          fs->p = fs->buf;
          fs->p = fs->buf;
          fs->end = fs->buf + INIT_BUF_SIZE;
          fs->end = fs->buf + INIT_BUF_SIZE;
        }
        }
    }
    }
 
 
  return fs;
  return fs;
}
}
#ifdef weak_alias
#ifdef weak_alias
weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
#endif
#endif
 
 
/* Flush FS to its stream, and free it (but don't close the stream).  */
/* Flush FS to its stream, and free it (but don't close the stream).  */
void
void
__argp_fmtstream_free (argp_fmtstream_t fs)
__argp_fmtstream_free (argp_fmtstream_t fs)
{
{
  __argp_fmtstream_update (fs);
  __argp_fmtstream_update (fs);
  if (fs->p > fs->buf)
  if (fs->p > fs->buf)
    {
    {
#ifdef USE_IN_LIBIO
#ifdef USE_IN_LIBIO
      if (_IO_fwide (fs->stream, 0) > 0)
      if (_IO_fwide (fs->stream, 0) > 0)
        __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf);
        __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf);
      else
      else
#endif
#endif
        fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream);
        fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream);
    }
    }
  free (fs->buf);
  free (fs->buf);
  free (fs);
  free (fs);
}
}
#ifdef weak_alias
#ifdef weak_alias
weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
#endif
#endif


/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
   end of its buffer.  This code is mostly from glibc stdio/linewrap.c.  */
   end of its buffer.  This code is mostly from glibc stdio/linewrap.c.  */
void
void
__argp_fmtstream_update (argp_fmtstream_t fs)
__argp_fmtstream_update (argp_fmtstream_t fs)
{
{
  char *buf, *nl;
  char *buf, *nl;
  size_t len;
  size_t len;
 
 
  /* Scan the buffer for newlines.  */
  /* Scan the buffer for newlines.  */
  buf = fs->buf + fs->point_offs;
  buf = fs->buf + fs->point_offs;
  while (buf < fs->p)
  while (buf < fs->p)
    {
    {
      size_t r;
      size_t r;
 
 
      if (fs->point_col == 0 && fs->lmargin != 0)
      if (fs->point_col == 0 && fs->lmargin != 0)
        {
        {
          /* We are starting a new line.  Print spaces to the left margin.  */
          /* We are starting a new line.  Print spaces to the left margin.  */
          const size_t pad = fs->lmargin;
          const size_t pad = fs->lmargin;
          if (fs->p + pad < fs->end)
          if (fs->p + pad < fs->end)
            {
            {
              /* We can fit in them in the buffer by moving the
              /* We can fit in them in the buffer by moving the
                 buffer text up and filling in the beginning.  */
                 buffer text up and filling in the beginning.  */
              memmove (buf + pad, buf, fs->p - buf);
              memmove (buf + pad, buf, fs->p - buf);
              fs->p += pad; /* Compensate for bigger buffer. */
              fs->p += pad; /* Compensate for bigger buffer. */
              memset (buf, ' ', pad); /* Fill in the spaces.  */
              memset (buf, ' ', pad); /* Fill in the spaces.  */
              buf += pad; /* Don't bother searching them.  */
              buf += pad; /* Don't bother searching them.  */
            }
            }
          else
          else
            {
            {
              /* No buffer space for spaces.  Must flush.  */
              /* No buffer space for spaces.  Must flush.  */
              size_t i;
              size_t i;
              for (i = 0; i < pad; i++)
              for (i = 0; i < pad; i++)
                {
                {
#ifdef USE_IN_LIBIO
#ifdef USE_IN_LIBIO
                  if (_IO_fwide (fs->stream, 0) > 0)
                  if (_IO_fwide (fs->stream, 0) > 0)
                    putwc_unlocked (L' ', fs->stream);
                    putwc_unlocked (L' ', fs->stream);
                  else
                  else
#endif
#endif
                    putc_unlocked (' ', fs->stream);
                    putc_unlocked (' ', fs->stream);
                }
                }
            }
            }
          fs->point_col = pad;
          fs->point_col = pad;
        }
        }
 
 
      len = fs->p - buf;
      len = fs->p - buf;
      nl = memchr (buf, '\n', len);
      nl = memchr (buf, '\n', len);
 
 
      if (fs->point_col < 0)
      if (fs->point_col < 0)
        fs->point_col = 0;
        fs->point_col = 0;
 
 
      if (!nl)
      if (!nl)
        {
        {
          /* The buffer ends in a partial line.  */
          /* The buffer ends in a partial line.  */
 
 
          if (fs->point_col + len < fs->rmargin)
          if (fs->point_col + len < fs->rmargin)
            {
            {
              /* The remaining buffer text is a partial line and fits
              /* The remaining buffer text is a partial line and fits
                 within the maximum line width.  Advance point for the
                 within the maximum line width.  Advance point for the
                 characters to be written and stop scanning.  */
                 characters to be written and stop scanning.  */
              fs->point_col += len;
              fs->point_col += len;
              break;
              break;
            }
            }
          else
          else
            /* Set the end-of-line pointer for the code below to
            /* Set the end-of-line pointer for the code below to
               the end of the buffer.  */
               the end of the buffer.  */
            nl = fs->p;
            nl = fs->p;
        }
        }
      else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
      else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
        {
        {
          /* The buffer contains a full line that fits within the maximum
          /* The buffer contains a full line that fits within the maximum
             line width.  Reset point and scan the next line.  */
             line width.  Reset point and scan the next line.  */
          fs->point_col = 0;
          fs->point_col = 0;
          buf = nl + 1;
          buf = nl + 1;
          continue;
          continue;
        }
        }
 
 
      /* This line is too long.  */
      /* This line is too long.  */
      r = fs->rmargin - 1;
      r = fs->rmargin - 1;
 
 
      if (fs->wmargin < 0)
      if (fs->wmargin < 0)
        {
        {
          /* Truncate the line by overwriting the excess with the
          /* Truncate the line by overwriting the excess with the
             newline and anything after it in the buffer.  */
             newline and anything after it in the buffer.  */
          if (nl < fs->p)
          if (nl < fs->p)
            {
            {
              memmove (buf + (r - fs->point_col), nl, fs->p - nl);
              memmove (buf + (r - fs->point_col), nl, fs->p - nl);
              fs->p -= buf + (r - fs->point_col) - nl;
              fs->p -= buf + (r - fs->point_col) - nl;
              /* Reset point for the next line and start scanning it.  */
              /* Reset point for the next line and start scanning it.  */
              fs->point_col = 0;
              fs->point_col = 0;
              buf += r + 1; /* Skip full line plus \n. */
              buf += r + 1; /* Skip full line plus \n. */
            }
            }
          else
          else
            {
            {
              /* The buffer ends with a partial line that is beyond the
              /* The buffer ends with a partial line that is beyond the
                 maximum line width.  Advance point for the characters
                 maximum line width.  Advance point for the characters
                 written, and discard those past the max from the buffer.  */
                 written, and discard those past the max from the buffer.  */
              fs->point_col += len;
              fs->point_col += len;
              fs->p -= fs->point_col - r;
              fs->p -= fs->point_col - r;
              break;
              break;
            }
            }
        }
        }
      else
      else
        {
        {
          /* Do word wrap.  Go to the column just past the maximum line
          /* Do word wrap.  Go to the column just past the maximum line
             width and scan back for the beginning of the word there.
             width and scan back for the beginning of the word there.
             Then insert a line break.  */
             Then insert a line break.  */
 
 
          char *p, *nextline;
          char *p, *nextline;
          int i;
          int i;
 
 
          p = buf + (r + 1 - fs->point_col);
          p = buf + (r + 1 - fs->point_col);
          while (p >= buf && !isblank (*p))
          while (p >= buf && !isblank (*p))
            --p;
            --p;
          nextline = p + 1;     /* This will begin the next line.  */
          nextline = p + 1;     /* This will begin the next line.  */
 
 
          if (nextline > buf)
          if (nextline > buf)
            {
            {
              /* Swallow separating blanks.  */
              /* Swallow separating blanks.  */
              if (p >= buf)
              if (p >= buf)
                do
                do
                  --p;
                  --p;
                while (p >= buf && isblank (*p));
                while (p >= buf && isblank (*p));
              nl = p + 1;       /* The newline will replace the first blank. */
              nl = p + 1;       /* The newline will replace the first blank. */
            }
            }
          else
          else
            {
            {
              /* A single word that is greater than the maximum line width.
              /* A single word that is greater than the maximum line width.
                 Oh well.  Put it on an overlong line by itself.  */
                 Oh well.  Put it on an overlong line by itself.  */
              p = buf + (r + 1 - fs->point_col);
              p = buf + (r + 1 - fs->point_col);
              /* Find the end of the long word.  */
              /* Find the end of the long word.  */
              do
              do
                ++p;
                ++p;
              while (p < nl && !isblank (*p));
              while (p < nl && !isblank (*p));
              if (p == nl)
              if (p == nl)
                {
                {
                  /* It already ends a line.  No fussing required.  */
                  /* It already ends a line.  No fussing required.  */
                  fs->point_col = 0;
                  fs->point_col = 0;
                  buf = nl + 1;
                  buf = nl + 1;
                  continue;
                  continue;
                }
                }
              /* We will move the newline to replace the first blank.  */
              /* We will move the newline to replace the first blank.  */
              nl = p;
              nl = p;
              /* Swallow separating blanks.  */
              /* Swallow separating blanks.  */
              do
              do
                ++p;
                ++p;
              while (isblank (*p));
              while (isblank (*p));
              /* The next line will start here.  */
              /* The next line will start here.  */
              nextline = p;
              nextline = p;
            }
            }
 
 
          /* Note: There are a bunch of tests below for
          /* Note: There are a bunch of tests below for
             NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
             NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
             at the end of the buffer, and NEXTLINE is in fact empty (and so
             at the end of the buffer, and NEXTLINE is in fact empty (and so
             we need not be careful to maintain its contents).  */
             we need not be careful to maintain its contents).  */
 
 
          if (nextline == buf + len + 1
          if (nextline == buf + len + 1
              ? fs->end - nl < fs->wmargin + 1
              ? fs->end - nl < fs->wmargin + 1
              : nextline - (nl + 1) < fs->wmargin)
              : nextline - (nl + 1) < fs->wmargin)
            {
            {
              /* The margin needs more blanks than we removed.  */
              /* The margin needs more blanks than we removed.  */
              if (fs->end - fs->p > fs->wmargin + 1)
              if (fs->end - fs->p > fs->wmargin + 1)
                /* Make some space for them.  */
                /* Make some space for them.  */
                {
                {
                  size_t mv = fs->p - nextline;
                  size_t mv = fs->p - nextline;
                  memmove (nl + 1 + fs->wmargin, nextline, mv);
                  memmove (nl + 1 + fs->wmargin, nextline, mv);
                  nextline = nl + 1 + fs->wmargin;
                  nextline = nl + 1 + fs->wmargin;
                  len = nextline + mv - buf;
                  len = nextline + mv - buf;
                  *nl++ = '\n';
                  *nl++ = '\n';
                }
                }
              else
              else
                /* Output the first line so we can use the space.  */
                /* Output the first line so we can use the space.  */
                {
                {
#ifdef USE_IN_LIBIO
#ifdef USE_IN_LIBIO
                  if (_IO_fwide (fs->stream, 0) > 0)
                  if (_IO_fwide (fs->stream, 0) > 0)
                    __fwprintf (fs->stream, L"%.*s\n",
                    __fwprintf (fs->stream, L"%.*s\n",
                                (int) (nl - fs->buf), fs->buf);
                                (int) (nl - fs->buf), fs->buf);
                  else
                  else
#endif
#endif
                    {
                    {
                      if (nl > fs->buf)
                      if (nl > fs->buf)
                        fwrite (fs->buf, 1, nl - fs->buf, fs->stream);
                        fwrite (fs->buf, 1, nl - fs->buf, fs->stream);
                      putc_unlocked ('\n', fs->stream);
                      putc_unlocked ('\n', fs->stream);
                    }
                    }
                  len += buf - fs->buf;
                  len += buf - fs->buf;
                  nl = buf = fs->buf;
                  nl = buf = fs->buf;
                }
                }
            }
            }
          else
          else
            /* We can fit the newline and blanks in before
            /* We can fit the newline and blanks in before
               the next word.  */
               the next word.  */
            *nl++ = '\n';
            *nl++ = '\n';
 
 
          if (nextline - nl >= fs->wmargin
          if (nextline - nl >= fs->wmargin
              || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
              || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
            /* Add blanks up to the wrap margin column.  */
            /* Add blanks up to the wrap margin column.  */
            for (i = 0; i < fs->wmargin; ++i)
            for (i = 0; i < fs->wmargin; ++i)
              *nl++ = ' ';
              *nl++ = ' ';
          else
          else
            for (i = 0; i < fs->wmargin; ++i)
            for (i = 0; i < fs->wmargin; ++i)
#ifdef USE_IN_LIBIO
#ifdef USE_IN_LIBIO
              if (_IO_fwide (fs->stream, 0) > 0)
              if (_IO_fwide (fs->stream, 0) > 0)
                putwc_unlocked (L' ', fs->stream);
                putwc_unlocked (L' ', fs->stream);
              else
              else
#endif
#endif
                putc_unlocked (' ', fs->stream);
                putc_unlocked (' ', fs->stream);
 
 
          /* Copy the tail of the original buffer into the current buffer
          /* Copy the tail of the original buffer into the current buffer
             position.  */
             position.  */
          if (nl < nextline)
          if (nl < nextline)
            memmove (nl, nextline, buf + len - nextline);
            memmove (nl, nextline, buf + len - nextline);
          len -= nextline - buf;
          len -= nextline - buf;
 
 
          /* Continue the scan on the remaining lines in the buffer.  */
          /* Continue the scan on the remaining lines in the buffer.  */
          buf = nl;
          buf = nl;
 
 
          /* Restore bufp to include all the remaining text.  */
          /* Restore bufp to include all the remaining text.  */
          fs->p = nl + len;
          fs->p = nl + len;
 
 
          /* Reset the counter of what has been output this line.  If wmargin
          /* Reset the counter of what has been output this line.  If wmargin
             is 0, we want to avoid the lmargin getting added, so we set
             is 0, we want to avoid the lmargin getting added, so we set
             point_col to a magic value of -1 in that case.  */
             point_col to a magic value of -1 in that case.  */
          fs->point_col = fs->wmargin ? fs->wmargin : -1;
          fs->point_col = fs->wmargin ? fs->wmargin : -1;
        }
        }
    }
    }
 
 
  /* Remember that we've scanned as far as the end of the buffer.  */
  /* Remember that we've scanned as far as the end of the buffer.  */
  fs->point_offs = fs->p - fs->buf;
  fs->point_offs = fs->p - fs->buf;
}
}


/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
   growing the buffer, or by flushing it.  True is returned iff we succeed. */
   growing the buffer, or by flushing it.  True is returned iff we succeed. */
int
int
__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
{
{
  if ((size_t) (fs->end - fs->p) < amount)
  if ((size_t) (fs->end - fs->p) < amount)
    {
    {
      ssize_t wrote;
      ssize_t wrote;
 
 
      /* Flush FS's buffer.  */
      /* Flush FS's buffer.  */
      __argp_fmtstream_update (fs);
      __argp_fmtstream_update (fs);
 
 
#ifdef USE_IN_LIBIO
#ifdef USE_IN_LIBIO
      if (_IO_fwide (fs->stream, 0) > 0)
      if (_IO_fwide (fs->stream, 0) > 0)
        {
        {
          __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf);
          __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf);
          wrote = fs->p - fs->buf;
          wrote = fs->p - fs->buf;
        }
        }
      else
      else
#endif
#endif
        wrote = fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream);
        wrote = fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream);
      if (wrote == fs->p - fs->buf)
      if (wrote == fs->p - fs->buf)
        {
        {
          fs->p = fs->buf;
          fs->p = fs->buf;
          fs->point_offs = 0;
          fs->point_offs = 0;
        }
        }
      else
      else
        {
        {
          fs->p -= wrote;
          fs->p -= wrote;
          fs->point_offs -= wrote;
          fs->point_offs -= wrote;
          memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
          memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
          return 0;
          return 0;
        }
        }
 
 
      if ((size_t) (fs->end - fs->buf) < amount)
      if ((size_t) (fs->end - fs->buf) < amount)
        /* Gotta grow the buffer.  */
        /* Gotta grow the buffer.  */
        {
        {
          size_t new_size = fs->end - fs->buf + amount;
          size_t new_size = fs->end - fs->buf + amount;
          char *new_buf = realloc (fs->buf, new_size);
          char *new_buf = realloc (fs->buf, new_size);
 
 
          if (! new_buf)
          if (! new_buf)
            {
            {
              __set_errno (ENOMEM);
              __set_errno (ENOMEM);
              return 0;
              return 0;
            }
            }
 
 
          fs->buf = new_buf;
          fs->buf = new_buf;
          fs->end = new_buf + new_size;
          fs->end = new_buf + new_size;
          fs->p = fs->buf;
          fs->p = fs->buf;
        }
        }
    }
    }
 
 
  return 1;
  return 1;
}
}


ssize_t
ssize_t
__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
{
{
  int out;
  int out;
  size_t avail;
  size_t avail;
  size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
  size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
 
 
  do
  do
    {
    {
      va_list args;
      va_list args;
 
 
      if (! __argp_fmtstream_ensure (fs, size_guess))
      if (! __argp_fmtstream_ensure (fs, size_guess))
        return -1;
        return -1;
 
 
      va_start (args, fmt);
      va_start (args, fmt);
      avail = fs->end - fs->p;
      avail = fs->end - fs->p;
      out = __vsnprintf (fs->p, avail, fmt, args);
      out = __vsnprintf (fs->p, avail, fmt, args);
      va_end (args);
      va_end (args);
      if (out >= avail)
      if (out >= avail)
        size_guess = out + 1;
        size_guess = out + 1;
    }
    }
  while (out >= avail);
  while (out >= avail);
 
 
  fs->p += out;
  fs->p += out;
 
 
  return out;
  return out;
}
}
#ifdef weak_alias
#ifdef weak_alias
weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
#endif
#endif
 
 
#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.