head	1.2;
access;
symbols
	perseant-exfatfs-base-20250801:1.2
	perseant-exfatfs-base-20240630:1.2
	cjep_sun2x:1.2.0.44
	cjep_sun2x-base:1.2
	cjep_staticlib_x-base1:1.2
	cjep_staticlib_x:1.2.0.42
	cjep_staticlib_x-base:1.2
	phil-wifi-20200421:1.2
	phil-wifi-20200411:1.2
	phil-wifi-20200406:1.2
	pgoyette-compat-merge-20190127:1.2
	pgoyette-compat-20190127:1.2
	pgoyette-compat-20190118:1.2
	pgoyette-compat-1226:1.2
	pgoyette-compat-1126:1.2
	pgoyette-compat-1020:1.2
	pgoyette-compat-0930:1.2
	pgoyette-compat-0906:1.2
	pgoyette-compat-0728:1.2
	pgoyette-compat-0625:1.2
	pgoyette-compat-0521:1.2
	pgoyette-compat-0502:1.2
	pgoyette-compat-0422:1.2
	pgoyette-compat-0415:1.2
	pgoyette-compat-0407:1.2
	pgoyette-compat-0330:1.2
	pgoyette-compat-0322:1.2
	pgoyette-compat-0315:1.2
	pgoyette-compat:1.2.0.40
	pgoyette-compat-base:1.2
	perseant-stdc-iso10646:1.2.0.38
	perseant-stdc-iso10646-base:1.2
	prg-localcount2-base3:1.2
	prg-localcount2-base2:1.2
	prg-localcount2-base1:1.2
	prg-localcount2:1.2.0.36
	prg-localcount2-base:1.2
	pgoyette-localcount-20170426:1.2
	bouyer-socketcan-base1:1.2
	pgoyette-localcount-20170320:1.2
	bouyer-socketcan:1.2.0.34
	bouyer-socketcan-base:1.2
	pgoyette-localcount-20170107:1.2
	pgoyette-localcount-20161104:1.2
	localcount-20160914:1.2
	pgoyette-localcount-20160806:1.2
	pgoyette-localcount-20160726:1.2
	pgoyette-localcount:1.2.0.32
	pgoyette-localcount-base:1.2
	netbsd-5-2-3-RELEASE:1.2
	netbsd-5-1-5-RELEASE:1.2
	yamt-pagecache-base9:1.2
	yamt-pagecache-tag8:1.2
	tls-earlyentropy:1.2.0.28
	tls-earlyentropy-base:1.2
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.2
	riastradh-drm2-base3:1.2
	netbsd-5-2-2-RELEASE:1.2
	netbsd-5-1-4-RELEASE:1.2
	netbsd-5-2-1-RELEASE:1.2
	netbsd-5-1-3-RELEASE:1.2
	agc-symver:1.2.0.30
	agc-symver-base:1.2
	tls-maxphys-base:1.2
	yamt-pagecache-base8:1.2
	netbsd-5-2:1.2.0.26
	yamt-pagecache-base7:1.2
	netbsd-5-2-RELEASE:1.2
	netbsd-5-2-RC1:1.2
	yamt-pagecache-base6:1.2
	yamt-pagecache-base5:1.2
	yamt-pagecache-base4:1.2
	netbsd-5-1-2-RELEASE:1.2
	netbsd-5-1-1-RELEASE:1.2
	yamt-pagecache-base3:1.2
	yamt-pagecache-base2:1.2
	yamt-pagecache:1.2.0.24
	yamt-pagecache-base:1.2
	bouyer-quota2-nbase:1.2
	bouyer-quota2:1.2.0.22
	bouyer-quota2-base:1.2
	matt-nb5-pq3:1.2.0.20
	matt-nb5-pq3-base:1.2
	netbsd-5-1:1.2.0.18
	netbsd-5-1-RELEASE:1.2
	netbsd-5-1-RC4:1.2
	netbsd-5-1-RC3:1.2
	netbsd-5-1-RC2:1.2
	netbsd-5-1-RC1:1.2
	netbsd-5-0-2-RELEASE:1.2
	netbsd-5-0-1-RELEASE:1.2
	jym-xensuspend-nbase:1.2
	netbsd-5-0:1.2.0.16
	netbsd-5-0-RELEASE:1.2
	netbsd-5-0-RC4:1.2
	netbsd-5-0-RC3:1.2
	netbsd-5-0-RC2:1.2
	jym-xensuspend:1.2.0.14
	jym-xensuspend-base:1.2
	netbsd-5-0-RC1:1.2
	netbsd-5:1.2.0.12
	netbsd-5-base:1.2
	mjf-devfs2:1.2.0.10
	mjf-devfs2-base:1.2
	yamt-pf42-base4:1.2
	yamt-pf42-base3:1.2
	hpcarm-cleanup-nbase:1.2
	yamt-pf42-base2:1.2
	yamt-pf42:1.2.0.8
	yamt-pf42-base:1.2
	keiichi-mipv6:1.2.0.6
	keiichi-mipv6-base:1.2
	cube-autoconf:1.2.0.4
	cube-autoconf-base:1.2
	hpcarm-cleanup:1.2.0.2
	hpcarm-cleanup-base:1.2
	netbsd-1-1-PATCH001:1.1
	netbsd-1-1-RELEASE:1.1
	netbsd-1-1:1.1.0.6
	netbsd-1-1-base:1.1
	netbsd-1-0-PATCH06:1.1
	netbsd-1-0-PATCH05:1.1
	netbsd-1-0-PATCH04:1.1
	netbsd-1-0-PATCH03:1.1
	netbsd-1-0-PATCH02:1.1
	netbsd-1-0-PATCH1:1.1
	netbsd-1-0-PATCH0:1.1
	netbsd-1-0-RELEASE:1.1
	netbsd-1-0:1.1.0.4
	netbsd-1-0-base:1.1
	netbsd-0-9-RELEASE:1.1
	netbsd-0-9-BETA:1.1
	netbsd-0-9-ALPHA2:1.1
	netbsd-0-9-ALPHA:1.1
	netbsd-0-9:1.1.0.2
	netbsd-0-9-base:1.1;
locks; strict;
comment	@ * @;


1.2
date	96.03.09.00.32.49;	author phil;	state dead;
branches;
next	1.1;

1.1
date	93.07.14.09.13.42;	author cgd;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Removal of old libg++.
@
text
@//    This is part of the iostream library, providing input/output for C++.
//    Copyright (C) 1991 Per Bothner.
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Library General Public
//    License as published by the Free Software Foundation; either
//    version 2 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Library General Public License for more details.
//
//    You should have received a copy of the GNU Library General Public
//    License along with this library; if not, write to the Free
//    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#ifdef __GNUG__
#pragma implementation
#endif
#include "ioprivate.h"
#include "parsestream.h"

streambuf* parsebuf::setbuf(char*, int)
{
    return NULL;
}

int parsebuf::tell_in_line()
{
    return 0;
}

int parsebuf::pbackfail(int c)
{
    if (c == EOF)
	return 0;
    if (seekoff(-1, ios::cur) == EOF)
	return EOF;
    return (unsigned char)c;
}

char* parsebuf::current_line() { return NULL; }

streampos parsebuf::seekoff(streamoff offset, _seek_dir dir, int)
{
    // Make offset relative to line start.
    switch (dir) {
      case ios::beg:
	offset -= pos_at_line_start;
	break;
      case ios::cur:
	offset += tell_in_line();
	break;
      default:
	return EOF;
    }
    if (offset < -1)
	return EOF;
    if (offset > _line_length + 1)
	return EOF;
    return seek_in_line(offset) + pos_at_line_start;
}

// string_parsebuf invariants:
// The reserve ares (base() .. ebuf()) is always the entire string.
// The get area (eback() .. egptr()) is the extended current line
// (i.e. with the '\n' at either end, if these exist).

string_parsebuf::string_parsebuf(char *buf, int len,
				 int delete_at_close /* = 0*/)
: parsebuf()
{
    setb(buf, buf+len, delete_at_close);
    register char *ptr = buf;
    while (ptr < ebuf() && *ptr != '\n') ptr++;
    _line_length = ptr - buf;
    setg(buf, buf, ptr);
}

int string_parsebuf::underflow()
{
    register char* ptr = egptr(); // Point to end of current_line
    do {
	int i = right() - ptr;
	if (i <= 0)
	    return EOF;
	ptr++; i--; // Skip '\n'.
	char *line_start = ptr;
	while (ptr < right() && *ptr == '\n') ptr++;
	setg(line_start-1, line_start, ptr + (ptr < right()));
	pos_at_line_start = line_start - left();
	_line_length = ptr - line_start;
	__line_number++;
    } while (gptr() == ptr);
    return *gptr();
}

char* string_parsebuf::current_line()
{
    char *ptr = eback();
    if (__line_number > 0)
	ptr++; // Skip '\n' at end of previous line.
    return ptr;
}

int string_parsebuf::tell_in_line()
{
    int offset = gptr() - eback();
    if (__line_number > 0)
	offset--;
    return offset;
}

int string_parsebuf::seek_in_line(int i)
{
    int delta = i - tell_in_line();
    gbump(delta); // FIXME: Needs error (bounds) checking!
    return i;
}

static const char NewLine[1] = { '\n' };

general_parsebuf::general_parsebuf(streambuf *buf, int delete_arg_buf)
 : parsebuf()
{
    delete_buf = delete_arg_buf;
    sbuf = buf;
    int buf_size = 128;
    char* buffer = ALLOC_BUF(buf_size);
    setb(buffer, buffer+buf_size, 1);
//    setg(buffer, buffer, buffer);
}

general_parsebuf::~general_parsebuf()
{
    if (delete_buf)
	delete sbuf;
}

int general_parsebuf::underflow()
{
    register char *ptr = base();
    int has_newline = eback() < gptr() && gptr()[-1] == '\n';
    if (has_newline)
	*ptr++ = '\n';
    register streambuf *sb = sbuf;
    register int ch;
    for (;;) {
	ch = sb->sbumpc();
	if (ch == EOF)
	    break;
	if (ptr == ebuf()) {
	    int old_size = ebuf() - base();
	    char *new_buffer = new char[old_size * 2];
	    memcpy(new_buffer, base(), old_size);
	    setb(new_buffer, new_buffer + 2 * old_size, 1);
	    ptr = new_buffer + old_size;
	}
	*ptr++ = ch;
	if (ch == '\n')
	    break;
    }
    char *cur_pos = base() + has_newline;
    pos_at_line_start += _line_length + 1;
    _line_length = ptr - cur_pos;
    if (ch != EOF || _line_length > 0)
	__line_number++;
    setg(base(), cur_pos, ptr);
    return ptr == cur_pos ? EOF : cur_pos[0];
}

char* general_parsebuf::current_line()
{
    char* ret = base();
    if (__line_number > 1)
	ret++; // Move past '\n' from end of previous line.
    return ret;
}

int general_parsebuf::tell_in_line()
{
    int off = gptr() - base();
    if (__line_number > 1)
	off--; // Subtract 1 for '\n' from end of previous line.
    return off;
}

int general_parsebuf::seek_in_line(int i)
{
    if (__line_number == 0)
	(void)general_parsebuf::underflow();
    if (__line_number > 1)
	i++; // Add 1 for '\n' from end of previous line.
    if (i < 0) i = 0;
    int len = egptr() - eback();
    if (i > len) i = len;
    setg(base(), base() + i, egptr());
    return i;
}

func_parsebuf::func_parsebuf(CharReader func, void *argm) : parsebuf()
{
    read_func = func;
    arg = argm;
    buf_start = NULL;
    buf_end = NULL;
    setb((char*)NewLine, (char*)NewLine+1, 0);
    setg((char*)NewLine, (char*)NewLine+1, (char*)NewLine+1);
    backed_up_to_newline = 0;
}

int func_parsebuf::tell_in_line()
{
    if (buf_start == NULL)
	return 0;
    if (egptr() != (char*)NewLine+1)
	// Get buffer was line buffer.
	return gptr() - buf_start;
    if (backed_up_to_newline)
	return -1;  // Get buffer is '\n' preceding current line.
    // Get buffer is '\n' following current line.
    return (buf_end - buf_start) + (gptr() - (char*)NewLine);
}

char* func_parsebuf::current_line()
{
    return buf_start;
}

int func_parsebuf::seek_in_line(int i)
{
    if (i < 0) {
	// Back up to preceding '\n'.
	if (i < -1) i = -1;
	backed_up_to_newline = 1;
	setg((char*)NewLine, (char*)NewLine+(i+1), (char*)NewLine+1);
	return i;
    }
    backed_up_to_newline = 0;
    int line_length = buf_end-buf_start;
    if (i <= line_length) {
	setg(buf_start, buf_start+i, buf_end);
	return i;
    }
    i -= line_length;
    if (i > 0) i = 1;
    setg((char*)NewLine, (char*)NewLine+i, (char*)NewLine+1);
    return line_length + i;
}

int func_parsebuf::underflow()
{
  retry:
    if (gptr() < egptr())
	return *gptr();
    if (gptr() != (char*)NewLine+1) {
	// Get buffer was line buffer.  Move to following '\n'.
	setg((char*)NewLine, (char*)NewLine, (char*)NewLine+1);
	return *gptr();
    }
    if (backed_up_to_newline)
	// Get buffer was '\n' preceding current line. Move to current line.
	backed_up_to_newline = 0;
    else {
	// Get buffer was '\n' following current line. Read new line.
	if (buf_start) free(buf_start);
	char *str = (*read_func)(arg);
	buf_start = str;
	if (str == NULL)
	    return EOF;
	// Initially, _line_length == -1, so pos_at_line_start becomes 0.
	pos_at_line_start += _line_length + 1;
	_line_length = strlen(str);
	buf_end = str + _line_length;
	__line_number++;
    }
    setg(buf_start, buf_start, buf_end);
    goto retry;
}

#if 0
size_t parsebuf::line_length()
{
    if (current_line_length == (size_t)(-1)) // Initial value;
	(void)sgetc();
    return current_line_length;
}
#endif

int parsebuf::seek_in_line(int i)
{
#if 1
    abort();
    return 0; // Suppress warning.
#else
    if (i > 0) {
	size_t len = line_length();
	if ((unsigned)i > len) i = len;
    }
    else if (i < -1) i = -1;
    int new_pos = seekoff(pos_at_line_start + i, ios::beg);
    if (new_pos == EOF)
	return tell_in_line();
    else return new_pos - pos_at_line_start;
#endif
}
@


1.1
log
@upgrade to libg++ 2.3.90.  g++ includes don't install right yet, but will fix
@
text
@@
