コード例 #1
0
ファイル: s_textbuffer.c プロジェクト: jaredcasper/geda-gaf
/*! \brief Fetch the next line from a text buffer
 *
 *  \par Function description
 *  Get the next line of characters from a TextBuffer, starting from
 *  the current position.  If the end of the buffer has been reached
 *  (and thus no more characters remain) returns null.
 *
 *  The returned character array should be considered highly volatile,
 *  and is only valid until the next call to s_textbuffer_next() or
 *  s_textbuffer_next_line().
 *
 *  \param tb    TextBuffer to read from.
 *  \retval      Character array, or NULL if no characters left.
 */
gchar *s_textbuffer_next_line (TextBuffer *tb)
{
  int len = 0;
  gchar *line;

  if (tb == NULL) return NULL;

  if (tb->offset >= tb->size) 
    return NULL;

  /* skip leading CR characters */
  while (tb->buffer[tb->offset] == '\r'
	 && tb->offset < tb->size - 1) {
    tb->offset += 1;
  }

  while ((tb->buffer[tb->offset + len] != '\n')
	 && (len < tb->size - tb->offset - 1)) {
    len++;
  }

  len++;

  line = s_textbuffer_next (tb, len);

  /* wipe out all trailing CR characters */
  while (len > 1 && line[len-2] == '\r') {
    line[len-1] = 0;
    len--;
  }

  return line;
}
コード例 #2
0
ファイル: s_textbuffer.c プロジェクト: peter-b/geda-gaf
/*! \brief Fetch the next line from a text buffer
 *
 *  \par Function description
 *  Get the next line of characters from a TextBuffer, starting from
 *  the current position.  If the end of the buffer has been reached
 *  (and thus no more characters remain) returns null.
 *
 *  The returned character array should be considered highly volatile,
 *  and is only valid until the next call to s_textbuffer_next() or
 *  s_textbuffer_next_line().
 *
 *  \param tb    TextBuffer to read from.
 *  \retval      Character array, or NULL if no characters left.
 */
const gchar *
s_textbuffer_next_line (TextBuffer *tb)
{
  g_return_val_if_fail (tb != NULL, 0);

  const gchar* line = s_textbuffer_next (tb, -1);

  if (line != NULL)
  {
    ++tb->linenum;

    if (verbose_loading)
    {
      fprintf (stderr, "%-4lu: %s", (unsigned long) tb->linenum, line);
    }
  }

  return line;
}
コード例 #3
0
ファイル: s_textbuffer.c プロジェクト: fvila/geda-gaf
/*! \brief Fetch the next line from a text buffer
 *
 *  \par Function description
 *  Get the next line of characters from a TextBuffer, starting from
 *  the current position.  If the end of the buffer has been reached
 *  (and thus no more characters remain) returns null.
 *
 *  The returned character array should be considered highly volatile,
 *  and is only valid until the next call to s_textbuffer_next() or
 *  s_textbuffer_next_line().
 *
 *  \param tb    TextBuffer to read from.
 *  \retval      Character array, or NULL if no characters left.
 */
const gchar *
s_textbuffer_next_line (TextBuffer *tb)
{
  return s_textbuffer_next (tb, -1);
}