1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-26 07:55:01 +00:00

Michael Reifenberger's libg++ port

Submitted by:	mr
This commit is contained in:
Jordan K. Hubbard 1994-11-13 05:57:35 +00:00
parent b3f6f5fbb3
commit be25b01844
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/misc-GNU/dist/; revision=4422
48 changed files with 3937 additions and 436 deletions

View File

@ -42,26 +42,26 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
class ACG : public RNG {
unsigned long initialSeed; // used to reset generator
_G_uint32_t initialSeed; // used to reset generator
int initialTableEntry;
unsigned long *state;
unsigned long *auxState;
_G_uint32_t *state;
_G_uint32_t *auxState;
short stateSize;
short auxSize;
unsigned long lcgRecurr;
_G_uint32_t lcgRecurr;
short j;
short k;
protected:
public:
ACG(unsigned long seed = 0, int size = 55);
ACG(_G_uint32_t seed = 0, int size = 55);
virtual ~ACG();
//
// Return a long-words word of random bits
//
virtual unsigned long asLong();
virtual _G_uint32_t asLong();
virtual void reset();
};

View File

@ -87,33 +87,6 @@ Complex sqrt(const Complex& x);
istream& operator >> (istream& s, Complex& x);
ostream& operator << (ostream& s, const Complex& x);
// other functions defined as inlines
int operator == (const Complex& x, const Complex& y);
int operator == (const Complex& x, double y);
int operator != (const Complex& x, const Complex& y);
int operator != (const Complex& x, double y);
Complex operator - (const Complex& x);
Complex conj(const Complex& x);
Complex operator + (const Complex& x, const Complex& y);
Complex operator + (const Complex& x, double y);
Complex operator + (double x, const Complex& y);
Complex operator - (const Complex& x, const Complex& y);
Complex operator - (const Complex& x, double y);
Complex operator - (double x, const Complex& y);
Complex operator * (const Complex& x, const Complex& y);
Complex operator * (const Complex& x, double y);
Complex operator * (double x, const Complex& y);
double real(const Complex& x);
double imag(const Complex& x);
double abs(const Complex& x);
double norm(const Complex& x);
double arg(const Complex& x);
Complex polar(double r, double t = 0.0);
// inline members

View File

@ -25,7 +25,11 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#include <_G_config.h>
#if _G_HAVE_CURSES
// Even many system which mostly have C++-ready header files,
// do not have C++-ready curses.h.
extern "C" {
#include <curses.h>
}
/* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
Undefine it here, because CursesWindow uses lines as a method. */
@ -148,8 +152,9 @@ inline int (winch)(WINDOW* win) { return winch(win); }
/* deal with conflicting macros in ncurses.h which is SYSV based*/
#ifdef box
inline (box)(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
inline _G_box(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
#undef box
inline box(WINDOW* win, chtype v, chtype h) {return _G_box(win, v, h); }
#endif
#ifdef scroll
inline (scroll)(WINDOW* win) { return scroll(win); }

View File

@ -66,9 +66,9 @@ class BaseDLList {
int empty() const { return h == 0; }
int length() const;
void clear();
void error(const char* msg);
int owns(Pix p);
int OK();
void error(const char* msg) const;
int owns(Pix p) const;
int OK() const;
void del(Pix& p, int dir = 1);
void del_after(Pix& p);
void del_front();
@ -104,6 +104,13 @@ class DLList : public BaseDLList {
if (h == 0) error("rear: empty list");
return ((DLNode<T>*)h->bk)->hd;
}
const T& front() const {
if (h == 0) error("front: empty list");
return ((DLNode<T>*)h)->hd; }
const T& rear() const {
if (h == 0) error("rear: empty list");
return ((DLNode<T>*)h->bk)->hd;
}
T remove_front() { T dst; BaseDLList::remove_front(&dst); return dst; }
T remove_rear() { T dst; BaseDLList::remove_rear(&dst); return dst; }
@ -111,11 +118,15 @@ class DLList : public BaseDLList {
if (p == 0) error("null Pix");
return ((DLNode<T>*)p)->hd;
}
Pix first() { return Pix(h); }
Pix last() { return (h == 0)? 0 : Pix(h->bk); }
void next(Pix& p)
const T& operator () (Pix p) const {
if (p == 0) error("null Pix");
return ((DLNode<T>*)p)->hd;
}
Pix first() const { return Pix(h); }
Pix last() const { return (h == 0) ? 0 : Pix(h->bk); }
void next(Pix& p) const
{ p = (p == 0 || p == h->bk)? 0 : Pix(((DLNode<T>*)p)->fd); }
void prev(Pix& p)
void prev(Pix& p) const
{ p = (p == 0 || p == h)? 0 : Pix(((DLNode<T>*)p)->bk); }
Pix ins_after(Pix p, const T& item)
{return BaseDLList::ins_after(p, &item); }

View File

@ -40,11 +40,11 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#define Fix16_min (-1.)
#define Fix32_fs ((double)((unsigned long)(1 << 31)))
#define Fix32_fs ((double)((_G_uint32_t)(1 << 31)))
#define Fix32_msb ((unsigned long)(1 << 31))
#define Fix32_m_max ((long)((1 << 31) - 1))
#define Fix32_m_min ((long)(1 << 31))
#define Fix32_msb ((_G_uint32_t)(1 << 31))
#define Fix32_m_max ((_G_int32_t)((1 << 31) - 1))
#define Fix32_m_min ((_G_int32_t)(1 << 31))
#define Fix32_mult Fix32_fs
#define Fix32_div (1./Fix32_fs)
@ -135,12 +135,12 @@ class Fix32
{
friend class Fix16;
long m;
_G_int32_t m;
long round(double d);
long assign(double d);
_G_int32_t round(double d);
_G_int32_t assign(double d);
Fix32(long i);
Fix32(_G_int32_t i);
operator double() const;
@ -155,8 +155,8 @@ class Fix32
Fix32& operator = (const Fix16& f);
Fix32& operator = (double d);
friend long& mantissa(Fix32& f);
friend const long& mantissa(const Fix32& f);
friend _G_int32_t& mantissa(Fix32& f);
friend const _G_int32_t& mantissa(const Fix32& f);
friend double value(const Fix32& f);
Fix32 operator + () const;
@ -188,8 +188,8 @@ class Fix32
friend istream& operator >> (istream& s, Fix32& f);
friend ostream& operator << (ostream& s, const Fix32& f);
void overflow(long& i) const;
void range_error(long& i) const;
void overflow(_G_int32_t& i) const;
void range_error(_G_int32_t& i) const;
friend Fix32 operator * (const Fix32& f, int g);
friend Fix32 operator * (int g, const Fix32& f);
@ -199,7 +199,7 @@ class Fix32
// active error handler declarations
typedef void (*Fix16_peh)(short&);
typedef void (*Fix32_peh)(long&);
typedef void (*Fix32_peh)(_G_int32_t&);
extern Fix16_peh Fix16_overflow_handler;
extern Fix32_peh Fix32_overflow_handler;
@ -231,11 +231,11 @@ extern void
Fix16_abort(short&);
extern void
Fix32_ignore(long&),
Fix32_overflow_saturate(long&),
Fix32_overflow_warning_saturate(long&),
Fix32_warning(long&),
Fix32_abort(long&);
Fix32_ignore(_G_int32_t&),
Fix32_overflow_saturate(_G_int32_t&),
Fix32_overflow_warning_saturate(_G_int32_t&),
Fix32_warning(_G_int32_t&),
Fix32_abort(_G_int32_t&);
inline Fix16::~Fix16() {}
@ -294,7 +294,7 @@ inline Fix32::Fix32()
m = 0;
}
inline Fix32::Fix32(long i)
inline Fix32::Fix32(_G_int32_t i)
{
m = i;
}
@ -312,7 +312,7 @@ inline Fix32::Fix32(const Fix32& f)
inline Fix32::Fix32(const Fix16& f)
{
m = long(f.m) << 16;
m = _G_int32_t(f.m) << 16;
}
inline Fix32::Fix32(double d)
@ -340,7 +340,7 @@ inline Fix32& Fix32::operator=(const Fix32& f)
inline Fix32& Fix32::operator=(const Fix16& f)
{
m = long(f.m) << 16;
m = _G_int32_t(f.m) << 16;
return *this;
}
@ -393,7 +393,7 @@ inline Fix16 operator-(const Fix16& f, const Fix16& g)
inline Fix32 operator*(const Fix16& f, const Fix16& g)
{
return Fix32( long( long(f.m) * long(g.m) << 1));
return Fix32( _G_int32_t( _G_int32_t(f.m) * _G_int32_t(g.m) << 1));
}
inline Fix16 operator<<(const Fix16& a, int b)
@ -498,17 +498,17 @@ inline Fix16& Fix16::operator*=(int g)
inline Fix32::~Fix32() {}
inline long Fix32::round(double d)
inline _G_int32_t Fix32::round(double d)
{
return long( (d >= 0)? d + 0.5 : d - 0.5);
return _G_int32_t( (d >= 0)? d + 0.5 : d - 0.5);
}
inline long& mantissa(Fix32& f)
inline _G_int32_t& mantissa(Fix32& f)
{
return f.m;
}
inline const long& mantissa(const Fix32& f)
inline const _G_int32_t& mantissa(const Fix32& f)
{
return f.m;
}
@ -530,7 +530,7 @@ inline Fix32 Fix32::operator-() const
inline Fix32 operator+(const Fix32& f, const Fix32& g)
{
long sum = f.m + g.m;
_G_int32_t sum = f.m + g.m;
if ( (f.m ^ sum) & (g.m ^ sum) & Fix32_msb )
f.overflow(sum);
return sum;
@ -538,7 +538,7 @@ inline Fix32 operator+(const Fix32& f, const Fix32& g)
inline Fix32 operator-(const Fix32& f, const Fix32& g)
{
long sum = f.m - g.m;
_G_int32_t sum = f.m - g.m;
if ( (f.m ^ sum) & (-g.m ^ sum) & Fix32_msb )
f.overflow(sum);
return sum;
@ -630,7 +630,7 @@ inline ostream& operator<<(ostream& s, const Fix32& f)
inline Fix32 operator*(const Fix32& f, int g)
{
return Fix32(long(f.m * g));
return Fix32(_G_int32_t(f.m * g));
}
inline Fix32 operator*(int g, const Fix32& f)

View File

@ -29,8 +29,8 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
// extra type definitions
typedef struct {
long u;
unsigned long l;
_G_int32_t u;
_G_uint32_t l;
} twolongs;
// constant definitions
@ -45,7 +45,7 @@ static const double
Fix24_max = 1. - .5/Fix24_fs,
Fix24_min = -1.;
static const unsigned long
static const _G_uint32_t
Fix24_msb = 0x80000000L,
Fix24_lsb = 0x00000100L,
Fix24_m_max = 0x7fffff00L,
@ -74,9 +74,9 @@ class Fix24
{
friend class Fix48;
long m;
_G_int32_t m;
long assign(double d);
_G_int32_t assign(double d);
operator double() const;
Fix24(long i);
Fix24(int i);
@ -94,8 +94,8 @@ class Fix24
Fix24& operator=(double d);
Fix24& operator=(const Fix48& f);
friend long& mantissa(Fix24& f);
friend const long& mantissa(const Fix24& f);
friend _G_int32_t& mantissa(Fix24& f);
friend const _G_int32_t& mantissa(const Fix24& f);
friend double value(const Fix24& f);
Fix24 operator + () const;
@ -129,8 +129,8 @@ class Fix24
friend istream& operator >> (istream& s, Fix24& f);
friend ostream& operator << (ostream& s, const Fix24& f);
void overflow(long&) const;
void range_error(long&) const;
void overflow(_G_int32_t&) const;
void range_error(_G_int32_t&) const;
};
@ -200,7 +200,7 @@ class Fix48
// active error handler declarations
typedef void (*Fix24_peh)(long&);
typedef void (*Fix24_peh)(_G_int32_t&);
typedef void (*Fix48_peh)(twolongs&);
extern Fix24_peh Fix24_overflow_handler;
@ -226,11 +226,11 @@ extern Fix48_peh set_Fix48_range_error_handler(Fix48_peh);
extern void set_range_error_handler(Fix24_peh, Fix48_peh);
extern void
Fix24_ignore(long&),
Fix24_overflow_saturate(long&),
Fix24_overflow_warning_saturate(long&),
Fix24_warning(long&),
Fix24_abort(long&);
Fix24_ignore(_G_int32_t&),
Fix24_overflow_saturate(_G_int32_t&),
Fix24_overflow_warning_saturate(_G_int32_t&),
Fix24_warning(_G_int32_t&),
Fix24_abort(_G_int32_t&);
extern void
Fix48_ignore(twolongs&),
@ -295,12 +295,12 @@ inline Fix24& Fix24::operator=(const Fix48& f)
return *this;
}
inline long& mantissa(Fix24& f)
inline _G_int32_t& mantissa(Fix24& f)
{
return f.m;
}
inline const long& mantissa(const Fix24& f)
inline const _G_int32_t& mantissa(const Fix24& f)
{
return f.m;
}
@ -322,7 +322,7 @@ inline Fix24 Fix24::operator-() const
inline Fix24 operator+(const Fix24& f, const Fix24& g)
{
long sum = f.m + g.m;
_G_int32_t sum = f.m + g.m;
if ( (f.m ^ sum) & (g.m ^ sum) & Fix24_msb )
f.overflow(sum);
return sum;
@ -330,7 +330,7 @@ inline Fix24 operator+(const Fix24& f, const Fix24& g)
inline Fix24 operator-(const Fix24& f, const Fix24& g)
{
long sum = f.m - g.m;
_G_int32_t sum = f.m - g.m;
if ( (f.m ^ sum) & (-g.m ^ sum) & Fix24_msb )
f.overflow(sum);
return sum;
@ -353,7 +353,7 @@ inline Fix24 operator<<(const Fix24& a, int b)
inline Fix24 operator>>(const Fix24& a, int b)
{
return (a.m >> b) & (long)0xffffff00;
return (a.m >> b) & ~0xff;
}
inline Fix24& Fix24:: operator+=(const Fix24& f)
@ -448,7 +448,7 @@ inline Fix48:: operator double() const
* m.u is signed and m.l is unsigned.
*/
return (m.u >= 0)? Fix48_div_u * m.u + Fix48_div_l * m.l :
(Fix48_div_u * ((unsigned long)(m.u & 0xffffff00))
(Fix48_div_u * ((_G_uint32_t)(m.u & 0xffffff00))
+ Fix48_div_l * m.l) - 2;
}

View File

@ -41,7 +41,7 @@ class MLCG : public RNG {
//
// Return a long-words word of random bits
//
virtual unsigned long asLong();
virtual _G_uint32_t asLong();
virtual void reset();
_G_int32_t seed1();
void seed1(_G_int32_t);

View File

@ -46,7 +46,7 @@ class RNG {
//
// Return a long-words word of random bits
//
virtual unsigned long asLong() = 0;
virtual _G_uint32_t asLong() = 0;
virtual void reset() = 0;
//
// Return random bits converted to either a float or a double

View File

@ -64,10 +64,10 @@ class BaseSLList {
void clear();
Pix prepend(BaseSLNode*);
Pix append(BaseSLNode*);
int OK();
void error(const char* msg);
int OK() const;
void error(const char* msg) const;
void del_after(Pix p);
int owns(Pix p);
int owns(Pix p) const;
void del_front();
};
@ -95,9 +95,12 @@ class SLList : public BaseSLList
T& operator () (Pix p) {
if (p == 0) error("null Pix");
return ((SLNode<T>*)(p))->hd; }
inline Pix first() { return (last == 0)? 0 : Pix(last->tl); }
void next(Pix& p)
{ p = (p == 0 || p == last)? 0 : Pix(((SLNode<T>*)(p))->tl); }
const T& operator () (Pix p) const {
if (p == 0) error("null Pix");
return ((SLNode<T>*)(p))->hd; }
inline Pix first() const { return (last == 0) ? 0 : Pix(last->tl); }
void next(Pix& p) const
{ p = (p == 0 || p == last) ? 0 : Pix(((SLNode<T>*)(p))->tl); }
Pix ins_after(Pix p, const T& item)
{ return BaseSLList::ins_after(p, &item); }
void join(SLList<T>& a) { BaseSLList::join(a); }
@ -108,6 +111,12 @@ class SLList : public BaseSLList
T& rear() {
if (last == 0) error("rear: empty list");
return ((SLNode<T>*)last)->hd; }
const T& front() const {
if (last == 0) error("front: empty list");
return ((SLNode<T>*)last->tl)->hd; }
const T& rear() const {
if (last == 0) error("rear: empty list");
return ((SLNode<T>*)last)->hd; }
int remove_front(T& x) { return BaseSLList::remove_front(&x); }
T remove_front() { T dst; BaseSLList::remove_front(&dst, 1); return dst; }
};

View File

@ -39,7 +39,6 @@ struct StrRep // internal String representations
StrRep* Salloc(StrRep*, const char*, int, int);
StrRep* Scopy(StrRep*, const StrRep*);
StrRep* Sresize(StrRep*, int);
StrRep* Scat(StrRep*, const char*, int, const char*, int);
StrRep* Scat(StrRep*, const char*, int,const char*,int, const char*,int);
StrRep* Sprepend(StrRep*, const char*, int);
@ -155,50 +154,50 @@ class String
// procedural versions:
// concatenate first 2 args, store result in last arg
friend void cat(const String&, const String&, String&);
friend void cat(const String&, const SubString&, String&);
friend void cat(const String&, const char*, String&);
friend void cat(const String&, char, String&);
friend inline void cat(const String&, const String&, String&);
friend inline void cat(const String&, const SubString&, String&);
friend inline void cat(const String&, const char*, String&);
friend inline void cat(const String&, char, String&);
friend void cat(const SubString&, const String&, String&);
friend void cat(const SubString&, const SubString&, String&);
friend void cat(const SubString&, const char*, String&);
friend void cat(const SubString&, char, String&);
friend inline void cat(const SubString&, const String&, String&);
friend inline void cat(const SubString&, const SubString&, String&);
friend inline void cat(const SubString&, const char*, String&);
friend inline void cat(const SubString&, char, String&);
friend void cat(const char*, const String&, String&);
friend void cat(const char*, const SubString&, String&);
friend void cat(const char*, const char*, String&);
friend void cat(const char*, char, String&);
friend inline void cat(const char*, const String&, String&);
friend inline void cat(const char*, const SubString&, String&);
friend inline void cat(const char*, const char*, String&);
friend inline void cat(const char*, char, String&);
// double concatenation, by request. (yes, there are too many versions,
// but if one is supported, then the others should be too...)
// Concatenate first 3 args, store in last arg
friend void cat(const String&,const String&, const String&,String&);
friend void cat(const String&,const String&,const SubString&,String&);
friend void cat(const String&,const String&, const char*, String&);
friend void cat(const String&,const String&, char, String&);
friend void cat(const String&,const SubString&,const String&,String&);
friend void cat(const String&,const SubString&,const SubString&,String&);
friend void cat(const String&,const SubString&, const char*, String&);
friend void cat(const String&,const SubString&, char, String&);
friend void cat(const String&,const char*, const String&, String&);
friend void cat(const String&,const char*, const SubString&, String&);
friend void cat(const String&,const char*, const char*, String&);
friend void cat(const String&,const char*, char, String&);
friend inline void cat(const String&,const String&, const String&,String&);
friend inline void cat(const String&,const String&,const SubString&,String&);
friend inline void cat(const String&,const String&, const char*, String&);
friend inline void cat(const String&,const String&, char, String&);
friend inline void cat(const String&,const SubString&,const String&,String&);
inline friend void cat(const String&,const SubString&,const SubString&,String&);
friend inline void cat(const String&,const SubString&, const char*, String&);
friend inline void cat(const String&,const SubString&, char, String&);
friend inline void cat(const String&,const char*, const String&, String&);
friend inline void cat(const String&,const char*, const SubString&, String&);
friend inline void cat(const String&,const char*, const char*, String&);
friend inline void cat(const String&,const char*, char, String&);
friend void cat(const char*, const String&, const String&,String&);
friend void cat(const char*,const String&,const SubString&,String&);
friend void cat(const char*,const String&, const char*, String&);
friend void cat(const char*,const String&, char, String&);
friend void cat(const char*,const SubString&,const String&,String&);
friend void cat(const char*,const SubString&,const SubString&,String&);
friend void cat(const char*,const SubString&, const char*, String&);
friend void cat(const char*,const SubString&, char, String&);
friend void cat(const char*,const char*, const String&, String&);
friend void cat(const char*,const char*, const SubString&, String&);
friend void cat(const char*,const char*, const char*, String&);
friend void cat(const char*,const char*, char, String&);
friend inline void cat(const char*, const String&, const String&,String&);
friend inline void cat(const char*,const String&,const SubString&,String&);
friend inline void cat(const char*,const String&, const char*, String&);
friend inline void cat(const char*,const String&, char, String&);
friend inline void cat(const char*,const SubString&,const String&,String&);
friend inline void cat(const char*,const SubString&,const SubString&,String&);
friend inline void cat(const char*,const SubString&, const char*, String&);
friend inline void cat(const char*,const SubString&, char, String&);
friend inline void cat(const char*,const char*, const String&, String&);
friend inline void cat(const char*,const char*, const SubString&, String&);
friend inline void cat(const char*,const char*, const char*, String&);
friend inline void cat(const char*,const char*, char, String&);
// searching & matching
@ -327,10 +326,10 @@ class String
// simple builtin transformations
friend String reverse(const String& x);
friend String upcase(const String& x);
friend String downcase(const String& x);
friend String capitalize(const String& x);
friend inline String reverse(const String& x);
friend inline String upcase(const String& x);
friend inline String downcase(const String& x);
friend inline String capitalize(const String& x);
// in-place versions of above
@ -342,6 +341,7 @@ class String
// element extraction
char& operator [] (int i);
const char& operator [] (int i) const;
char elem(int i) const;
char firstchar() const;
char lastchar() const;
@ -354,7 +354,7 @@ class String
// IO
friend ostream& operator<<(ostream& s, const String& x);
friend inline ostream& operator<<(ostream& s, const String& x);
friend ostream& operator<<(ostream& s, const SubString& x);
friend istream& operator>>(istream& s, String& x);
@ -395,64 +395,12 @@ int fcompare(const String& x, const String& y); // ignore case
extern StrRep _nilStrRep;
extern String _nilString;
// other inlines
String operator + (const String& x, const String& y);
String operator + (const String& x, const SubString& y);
String operator + (const String& x, const char* y);
String operator + (const String& x, char y);
String operator + (const SubString& x, const String& y);
String operator + (const SubString& x, const SubString& y);
String operator + (const SubString& x, const char* y);
String operator + (const SubString& x, char y);
String operator + (const char* x, const String& y);
String operator + (const char* x, const SubString& y);
int operator==(const String& x, const String& y);
int operator!=(const String& x, const String& y);
int operator> (const String& x, const String& y);
int operator>=(const String& x, const String& y);
int operator< (const String& x, const String& y);
int operator<=(const String& x, const String& y);
int operator==(const String& x, const SubString& y);
int operator!=(const String& x, const SubString& y);
int operator> (const String& x, const SubString& y);
int operator>=(const String& x, const SubString& y);
int operator< (const String& x, const SubString& y);
int operator<=(const String& x, const SubString& y);
int operator==(const String& x, const char* t);
int operator!=(const String& x, const char* t);
int operator> (const String& x, const char* t);
int operator>=(const String& x, const char* t);
int operator< (const String& x, const char* t);
int operator<=(const String& x, const char* t);
int operator==(const SubString& x, const String& y);
int operator!=(const SubString& x, const String& y);
int operator> (const SubString& x, const String& y);
int operator>=(const SubString& x, const String& y);
int operator< (const SubString& x, const String& y);
int operator<=(const SubString& x, const String& y);
int operator==(const SubString& x, const SubString& y);
int operator!=(const SubString& x, const SubString& y);
int operator> (const SubString& x, const SubString& y);
int operator>=(const SubString& x, const SubString& y);
int operator< (const SubString& x, const SubString& y);
int operator<=(const SubString& x, const SubString& y);
int operator==(const SubString& x, const char* t);
int operator!=(const SubString& x, const char* t);
int operator> (const SubString& x, const char* t);
int operator>=(const SubString& x, const char* t);
int operator< (const SubString& x, const char* t);
int operator<=(const SubString& x, const char* t);
// status reports, needed before defining other things
inline unsigned int String::length() const { return rep->len; }
inline int String::empty() const { return rep->len == 0; }
inline const char* String::chars() const { return &(rep->s[0]); }
inline int String::allocation() const { return rep->sz; }
inline void String::alloc(int newsize) { rep = Sresize(rep, newsize); }
inline unsigned int SubString::length() const { return len; }
inline int SubString::empty() const { return len == 0; }
@ -948,6 +896,12 @@ inline char& String::operator [] (int i)
return rep->s[i];
}
inline const char& String::operator [] (int i) const
{
if (((unsigned)i) >= length()) error("invalid index");
return rep->s[i];
}
inline char String::elem (int i) const
{
if (((unsigned)i) >= length()) error("invalid index");

View File

@ -122,4 +122,4 @@ extern void _BS_xor __P((_BS_word*,int, const _BS_word*,int, _BS_size_t));
}
#endif
#endif _BS_PRIMS
#endif /* !_BS_PRIMS */

View File

@ -64,21 +64,6 @@ extern two_arg_error_handler_t
set_lib_error_handler(two_arg_error_handler_t f);
double abs(double arg);
float abs(float arg);
short abs(short arg);
long abs(long arg);
int sign(long arg);
int sign(double arg);
long sqr(long arg);
double sqr(double arg);
int even(long arg);
int odd(long arg);
long lcm(long x, long y);
void (setbit)(long& x, long b);
void clearbit(long& x, long b);
int testbit(long x, long b);
#if !defined(IV)
#if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */

View File

@ -30,4 +30,6 @@ typedef void fvoid_t();
typedef _G_wint_t wint_t;
#endif
enum capacity { default_size, reserve };
#endif

View File

@ -3,6 +3,10 @@
/* These emulate stdio functionality, but with a different name
(_IO_ungetc instead of ungetc), and using _IO_FILE instead of FILE. */
#ifdef __cplusplus
extern "C" {
#endif
extern int _IO_fclose __P((_IO_FILE*));
extern _IO_FILE *_IO_fdopen __P((int, const char*));
extern int _IO_fflush __P((_IO_FILE*));
@ -17,6 +21,7 @@ extern _IO_size_t _IO_fwrite __P((const void*,
_IO_size_t, _IO_size_t, _IO_FILE*));
extern char* _IO_gets __P((char*));
extern void _IO_perror __P((const char*));
extern int _IO_printf __P((const char*, ...));
extern int _IO_puts __P((const char*));
extern int _IO_scanf __P((const char*, ...));
extern void _IO_setbuffer __P((_IO_FILE *, char*, _IO_size_t));
@ -30,8 +35,6 @@ extern int _IO_vsprintf __P((char*, const char*, _IO_va_list));
#define _IO_pos_BAD ((_IO_fpos_t)(-1))
#endif
#define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
#define _IO_feof(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define _IO_ferror(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
#define _IO_fseek(__fp, __offset, __whence) \
(_IO_seekoff(__fp, __offset, (_IO_off_t)(__whence)) == _IO_pos_BAD ? EOF : 0)
#define _IO_rewind(FILE) (void)_IO_seekoff(FILE, 0, 0)
@ -44,3 +47,6 @@ extern _IO_FILE* _IO_popen __P((const char*, const char*));
#define _IO_setbuf(_FP, _BUF) _IO_setbuffer(_FP, _BUF, _IO_BUFSIZ)
#define _IO_setlinebuf(_FP) _IO_setvbuf(_FP, NULL, 1, 0)
#ifdef __cplusplus
}
#endif

View File

@ -130,7 +130,7 @@ template <class TP> class omanip {
omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
//
friend
ostream& operator<<(ostream& o, omanip<TP>& m)
ostream& operator<<(ostream& o, const omanip<TP>& m)
{ return (*m._f)(o, m._a); }
};

View File

@ -92,6 +92,7 @@ class ostream : virtual public ios
#endif
ostream& operator<<(double n);
ostream& operator<<(float n) { return operator<<((double)n); }
ostream& operator<<(long double n) { return operator<<((double)n); }
ostream& operator<<(__omanip func) { return (*func)(*this); }
ostream& operator<<(__manip func) {(*func)(*this); return *this;}
ostream& operator<<(streambuf*);
@ -103,6 +104,7 @@ class ostream : virtual public ios
class istream : virtual public ios
{
// NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
protected:
_IO_size_t _gcount;
int _skip_ws();
@ -198,22 +200,32 @@ class istream : virtual public ios
#endif
istream& operator>>(float&);
istream& operator>>(double&);
istream& operator>>(long double&);
istream& operator>>( __manip func) {(*func)(*this); return *this;}
istream& operator>>(__imanip func) { return (*func)(*this); }
istream& operator>>(streambuf*);
};
class iostream : public istream, public ostream
{
_IO_size_t _gcount;
public:
iostream() { _gcount = 0; }
iostream() { }
iostream(streambuf* sb, ostream*tied=NULL);
};
extern istream cin;
extern ostream cout, cerr, clog; // clog->rdbuf() == cerr->rdbuf()
class _IO_istream_withassign : public istream {
public:
_IO_istream_withassign& operator=(istream&);
};
class _IO_ostream_withassign : public ostream {
public:
_IO_ostream_withassign& operator=(ostream&);
};
extern _IO_istream_withassign cin;
// clog->rdbuf() == cerr->rdbuf()
extern _IO_ostream_withassign cout, cerr, clog;
struct Iostream_init { } ; // Compatibility hack for AT&T library.

View File

@ -61,6 +61,13 @@ extern int strtoerrno PARAMS ((const char *));
extern int signo_max PARAMS ((void));
/* Return a signal message string for a signal number
(e.g., strsignal (SIGHUP) returns something like "Hangup"). */
/* This is commented out as it can conflict with one in system headers.
We still document its existence though. */
/*extern const char *strsignal PARAMS ((int));*/
/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
"SIGHUP"). */

View File

@ -73,7 +73,7 @@ typedef _IO_fpos_t _IO_pos_t;
#ifndef __STDC__
#define const
#endif
#define USE_DTOA
#define _IO_USE_DTOA
#if 0
#ifdef _IO_NEED_STDARG_H
@ -236,6 +236,9 @@ extern unsigned __adjust_column __P((unsigned start, const char *line, int count
? __overflow(_fp, (unsigned char)(_ch)) \
: (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch)))
#define _IO_feof(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define _IO_ferror(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
/* This one is for Emacs. */
#define _IO_PENDING_OUTPUT_COUNT(_fp) \
((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)

View File

@ -146,9 +146,9 @@ extern struct _IO_jump_t _IO_streambuf_jumps;
extern struct _IO_jump_t _IO_proc_jumps;
extern struct _IO_jump_t _IO_str_jumps;
extern int _IO_do_write __P((_IO_FILE*, const char*, _IO_size_t));
extern int _IO_flush_all __P(());
extern void _IO_cleanup __P(());
extern void _IO_flush_all_linebuffered __P(());
extern int _IO_flush_all __P((void));
extern void _IO_cleanup __P((void));
extern void _IO_flush_all_linebuffered __P((void));
#define _IO_do_flush(_f) \
_IO_do_write(_f, (_f)->_IO_write_base, \
@ -205,6 +205,7 @@ extern void _IO_str_init_readonly __P((_IO_FILE *, const char*, int));
extern _IO_ssize_t _IO_str_count __P ((_IO_FILE*));
extern _IO_size_t _IO_getline __P((_IO_FILE*,char*,_IO_size_t,int,int));
extern _IO_ssize_t _IO_getdelim __P((char**, _IO_size_t*, int, _IO_FILE*));
extern double _IO_strtod __P((const char *, char **));
extern char * _IO_dtoa __P((double __d, int __mode, int __ndigits,
int *__decpt, int *__sign, char **__rve));
@ -213,7 +214,7 @@ extern int _IO_outfloat __P((double __value, _IO_FILE *__sb, int __type,
int __sign_mode, int __fill));
extern _IO_FILE *_IO_list_all;
extern void (*_IO_cleanup_registration_needed)();
extern void (*_IO_cleanup_registration_needed) __P ((void));
#ifndef EOF
#define EOF (-1)
@ -306,3 +307,20 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
(((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
&& (FILE) = *(FILE**)&((int*)fp)[1])
#endif
#ifdef EINVAL
#define MAYBE_SET_EINVAL errno = EINVAL
#else
#define MAYBE_SET_EINVAL /* nothing */
#endif
#ifdef DEBUG
#define CHECK_FILE(FILE,RET) \
if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
else { COERCE_FILE(FILE); \
if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
{ errno = EINVAL; return RET; }}
#else
#define CHECK_FILE(FILE,RET) \
COERCE_FILE(FILE)
#endif

3255
gnu/lib/libg++/include/rx.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -117,6 +117,7 @@ enum open_mode {
#endif
class ios : public _ios_fields {
ios& operator=(ios&); /* Not allowed! */
public:
typedef __fmtflags fmtflags;
typedef int iostate;
@ -200,10 +201,8 @@ class ios : public _ios_fields {
void _IO_fix_vtable(); /* TEMPORARY - for binary compatibility */
void _IO_fix_vtable() const; /* TEMPORARY - for binary compatibility */
#endif
#if 0
streambuf* rdbuf(streambuf *_s) {
streambuf *_old = _strbuf; _strbuf = _s; return _old; }
#endif
streambuf *_old = _strbuf; _strbuf = _s; clear (); return _old; }
void clear(iostate state = 0) {
_state = _strbuf ? state : state|badbit;
if (_state & _exceptions) _throw_failure(); }

View File

@ -123,7 +123,7 @@ static randomStateTable[][3] = {
//
#define RANDOM_PERM_SIZE 64
unsigned long randomPermutations[RANDOM_PERM_SIZE] = {
_G_uint32_t randomPermutations[RANDOM_PERM_SIZE] = {
0xffffffff, 0x00000000, 0x00000000, 0x00000000, // 3210
0x0000ffff, 0x00ff0000, 0x00000000, 0xff000000, // 2310
0xff0000ff, 0x0000ff00, 0x00000000, 0x00ff0000, // 3120
@ -149,7 +149,7 @@ unsigned long randomPermutations[RANDOM_PERM_SIZE] = {
// SEED_TABLE_SIZE must be a power of 2
//
#define SEED_TABLE_SIZE 32
static unsigned long seedTable[SEED_TABLE_SIZE] = {
static _G_uint32_t seedTable[SEED_TABLE_SIZE] = {
0xbdcc47e5, 0x54aea45d, 0xec0df859, 0xda84637b,
0xc8c6cb4f, 0x35574b01, 0x28260b7d, 0x0d07fdbf,
0x9faaeeb0, 0x613dd169, 0x5ce2d818, 0x85b9e706,
@ -171,15 +171,15 @@ static unsigned long seedTable[SEED_TABLE_SIZE] = {
// LC_C = result of a long trial & error series = 3907864577
//
static const unsigned long LC_A = 66049;
static const unsigned long LC_C = 3907864577;
static inline unsigned long LCG(unsigned long x)
static const _G_uint32_t LC_A = 66049;
static const _G_uint32_t LC_C = 3907864577;
static inline _G_uint32_t LCG(_G_uint32_t x)
{
return( x * LC_A + LC_C );
}
ACG::ACG(unsigned long seed, int size)
ACG::ACG(_G_uint32_t seed, int size)
{
initialSeed = seed;
@ -205,7 +205,7 @@ ACG::ACG(unsigned long seed, int size)
// Allocate the state table & the auxillary table in a single malloc
//
state = new unsigned long[stateSize + auxSize];
state = new _G_uint32_t[stateSize + auxSize];
auxState = &state[stateSize];
reset();
@ -217,7 +217,7 @@ ACG::ACG(unsigned long seed, int size)
void
ACG::reset()
{
register unsigned long u;
register _G_uint32_t u;
if (initialSeed < SEED_TABLE_SIZE) {
u = seedTable[ initialSeed ];
@ -247,7 +247,7 @@ ACG::reset()
lcgRecurr = u;
assert(sizeof(double) == 2 * sizeof(long));
assert(sizeof(double) == 2 * sizeof(_G_int32_t));
}
ACG::~ACG()
@ -261,15 +261,16 @@ ACG::~ACG()
// Returns 32 bits of random information.
//
unsigned long ACG::asLong()
_G_uint32_t
ACG::asLong()
{
unsigned long result = state[k] + state[j];
_G_uint32_t result = state[k] + state[j];
state[k] = result;
j = (j <= 0) ? (stateSize-1) : (j-1);
k = (k <= 0) ? (stateSize-1) : (k-1);
short int auxIndex = (result >> 24) & (auxSize - 1);
register unsigned long auxACG = auxState[auxIndex];
register _G_uint32_t auxACG = auxState[auxIndex];
auxState[auxIndex] = lcgRecurr = LCG(lcgRecurr);
//
@ -277,7 +278,7 @@ unsigned long ACG::asLong()
// do not want to run off the end of the permutation table.
// This insures that we have always got four entries left.
//
register unsigned long *perm = & randomPermutations[result & 0x3c];
register _G_uint32_t *perm = & randomPermutations[result & 0x3c];
result = *(perm++) & auxACG;
result |= *(perm++) & ((auxACG << 24)

View File

@ -25,7 +25,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#include <builtin.h>
#include "DLList.h"
void BaseDLList::error(const char* msg)
void BaseDLList::error(const char* msg) const
{
(*lib_error_handler)("DLList", msg);
}
@ -164,7 +164,7 @@ void BaseDLList::join(BaseDLList& b)
}
}
int BaseDLList::owns(Pix p)
int BaseDLList::owns(Pix p) const
{
BaseDLNode* t = h;
if (t != 0 && p != 0)
@ -207,7 +207,7 @@ void BaseDLList::del(Pix& p, int dir)
t->fd->bk = t->bk;
if (t == h) h = t->fd;
}
delete t;
delete_node(t);
}
void BaseDLList::del_after(Pix& p)
@ -305,7 +305,7 @@ void BaseDLList::del_rear()
}
int BaseDLList::OK()
int BaseDLList::OK() const
{
int v = 1;
if (h != 0)

View File

@ -347,7 +347,7 @@ Fix::multiply(const Rep* x, int y, Rep* r)
a = (_G_int32_t) (_G_int16_t )x->s[0] * y + carry;
r->s[0] = a;
a &= 0xffff8000L;
if ( a != 0xffff8000L && a != 0L ) {
if ( a != (_G_int32_t)0xffff8000L && a != (_G_int32_t)0L ) {
r->s[0] = 0x8000 ^ x->s[0] ^ y;
overflow_handler(r);
}
@ -419,7 +419,7 @@ Fix::shift(const Rep* x, int y, Rep* r)
return r;
}
int ay = abs((long) y),
int ay = abs((_G_int32_t) y),
ayh = ay >> 4,
ayl = ay & 0x0f;
int xl, u, ilow, ihigh;
@ -492,7 +492,7 @@ Fix::printon(ostream& s, int width) const
{
double val = value(*this);
int old_precision = s.precision(width-3);
long old_flags = s.setf(ios::fixed, ios::fixed|ios::scientific);
_G_int32_t old_flags = s.setf(ios::fixed, ios::fixed|ios::scientific);
if (val >= 0)
s << ' ';
s.width(width-2);

View File

@ -48,19 +48,19 @@ short Fix16::assign(double d)
return round(Fix16_mult * d);
}
long Fix32::assign(double d)
_G_int32_t Fix32::assign(double d)
{
if (d == 1.0)
return Fix32_m_max;
else if (d > Fix32_max)
{
long i = Fix32_m_max;
_G_int32_t i = Fix32_m_max;
range_error(i);
return i;
}
else if (d < Fix32_min)
{
long i = Fix32_m_min;
_G_int32_t i = Fix32_m_min;
range_error(i);
return i;
}
@ -75,20 +75,20 @@ Fix32 operator * (const Fix32& a, const Fix32& b)
// multiply, with rounding
int apos = (a.m >= 0);
unsigned long ua = (apos)? a.m : - a.m;
_G_uint32_t ua = (apos)? a.m : - a.m;
ua <<= 1; // ua is biased so result will be 31 bit mantissa, not 30:
unsigned long hi_a = (ua >> 16) & ((1 << 16) - 1);
unsigned long lo_a = ua & ((1 << 16) - 1);
_G_uint32_t hi_a = (ua >> 16) & ((1 << 16) - 1);
_G_uint32_t lo_a = ua & ((1 << 16) - 1);
int bpos = (b.m >= 0);
unsigned long ub = (bpos)? b.m : -b.m;
unsigned long hi_b = (ub >> 16) & ((1 << 16) - 1);
unsigned long lo_b = ub & ((1 << 16) - 1);
_G_uint32_t ub = (bpos)? b.m : -b.m;
_G_uint32_t hi_b = (ub >> 16) & ((1 << 16) - 1);
_G_uint32_t lo_b = ub & ((1 << 16) - 1);
unsigned long r = lo_a * lo_b + (1 << 15);
_G_uint32_t r = lo_a * lo_b + (1 << 15);
r = (r >> 16) + hi_a * lo_b + lo_a * hi_b + (1 << 15);
r = (r >> 16) + hi_a * hi_b;
long p = (apos != bpos)? -r : r;
_G_int32_t p = (apos != bpos)? -r : r;
return Fix32(p);
}
@ -96,8 +96,8 @@ Fix16 operator / (const Fix16& a, const Fix16& b)
{
short q;
int apos = (a.m >= 0);
long la = (apos)? a.m : -a.m;
long scaled_a = la << 15;
_G_int32_t la = (apos)? a.m : -a.m;
_G_int32_t scaled_a = la << 15;
int bpos = (b.m >= 0);
short sb = (bpos)? b.m: -b.m;
if (la >= sb)
@ -116,11 +116,11 @@ Fix16 operator / (const Fix16& a, const Fix16& b)
Fix32 operator / (const Fix32& a, const Fix32& b)
{
long q;
_G_int32_t q;
int apos = (a.m >= 0);
unsigned long la = (apos)? a.m : -a.m;
_G_uint32_t la = (apos)? a.m : -a.m;
int bpos = (b.m >= 0);
unsigned long lb = (bpos)? b.m: -b.m;
_G_uint32_t lb = (bpos)? b.m: -b.m;
if (la >= lb)
{
q = (apos == bpos)? Fix32_m_max: Fix32_m_min;
@ -129,7 +129,7 @@ Fix32 operator / (const Fix32& a, const Fix32& b)
else // standard shift-based division alg
{
q = 0;
long r = la;
_G_int32_t r = la;
for (int i = 32; i > 0; i--)
{
@ -155,7 +155,7 @@ void Fix16::overflow(short& i) const
(*Fix16_overflow_handler)(i);
}
void Fix32::overflow(long& i) const
void Fix32::overflow(_G_int32_t& i) const
{
(*Fix32_overflow_handler)(i);
}
@ -165,7 +165,7 @@ void Fix16::range_error(short& i) const
(*Fix16_range_error_handler)(i);
}
void Fix32::range_error(long& i) const
void Fix32::range_error(_G_int32_t& i) const
{
(*Fix32_range_error_handler)(i);
}
@ -225,14 +225,14 @@ void Fix16_overflow_warning_saturate(short& i)
void Fix16_abort(short&)
{ cerr << "error: Fix16 result out of range\n"; abort(); }
void Fix32_ignore(long&) {}
void Fix32_overflow_saturate(long& i)
void Fix32_ignore(_G_int32_t&) {}
void Fix32_overflow_saturate(_G_int32_t& i)
{ i = (i > 0 ? Fix32_m_min : Fix32_m_max); }
void Fix32_warning(long&)
void Fix32_warning(_G_int32_t&)
{ cerr << "warning: Fix32 result out of range\n"; }
void Fix32_overflow_warning_saturate(long& i)
void Fix32_overflow_warning_saturate(_G_int32_t& i)
{ cerr << "warning: Fix32 result out of range\n";
Fix32_overflow_saturate(i); }
void Fix32_abort(long&)
void Fix32_abort(_G_int32_t&)
{ cerr << "error: Fix32 result out of range\n"; abort(); }

View File

@ -28,25 +28,27 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
// basic operators too large to be inline
long Fix24::assign(double d)
_G_int32_t Fix24::assign(double d)
{
if (d == 1.0)
return Fix24_m_max;
else if (d > Fix24_max)
{
long i = Fix24_m_max;
_G_int32_t i = Fix24_m_max;
range_error(i);
return i;
}
else if (d < Fix24_min)
{
long i = Fix24_m_min;
_G_int32_t i = Fix24_m_min;
range_error(i);
return i;
}
else {
d = (long) (d * (1 << 24) + ((d >= 0)? 0.5 : -0.5)); // Round to 24 bits
return ((long) d) << (Fix24_shift - 24); /* Convert to integer format */
// Round to 24 bits
d = (_G_int32_t) (d * (1 << 24) + ((d >= 0)? 0.5 : -0.5));
/* Convert to integer format */
return ((_G_int32_t) d) << (Fix24_shift - 24);
}
}
@ -72,14 +74,14 @@ twolongs Fix48::assign(double d)
/* First, convert the absolute value of d to a 48-bit integer format */
if (d < 0) d = -d;
i.u = ((long)(d *= Fix24_mult)) & 0xffffff00;
i.l = ((unsigned long)((d - i.u)* (Fix24_mult / (1 << 7)))) & 0xffffff00;
i.u = ((_G_int32_t)(d *= Fix24_mult)) & 0xffffff00;
i.l = ((_G_uint32_t)((d - i.u)* (Fix24_mult / (1 << 7)))) & 0xffffff00;
/* Calculate the two's complement if d was negative */
if (sign) {
unsigned long oldlower = i.l;
_G_uint32_t oldlower = i.l;
i.l = (~i.l + 1) & 0xffffff00;
i.u = (~i.u + (((oldlower ^ i.l) & Fix24_msb)? 0 : 1)) & 0xffffff00;
i.u = (~i.u + (((oldlower ^ i.l) & Fix24_msb)? 0 : 1)) & ~0xffL;
}
return i;
}
@ -92,17 +94,17 @@ Fix48 operator * (const Fix24& a, const Fix24& b)
// multiply, with rounding
int apos = (a.m >= 0);
unsigned long ua = (apos)? a.m : - a.m;
_G_uint32_t ua = (apos)? a.m : - a.m;
ua <<= 1; // ua is biased so result will be 47 bit mantissa, not 46:
unsigned long hi_a = (ua >> 16) & ((1 << 16) - 1);
unsigned long lo_a = ua & ((1 << 16) - 1);
_G_uint32_t hi_a = (ua >> 16) & ((1 << 16) - 1);
_G_uint32_t lo_a = ua & ((1 << 16) - 1);
int bpos = (b.m >= 0);
unsigned long ub = (bpos)? b.m : -b.m;
unsigned long hi_b = (ub >> 16) & ((1 << 16) - 1);
unsigned long lo_b = ub & ((1 << 16) - 1);
_G_uint32_t ub = (bpos)? b.m : -b.m;
_G_uint32_t hi_b = (ub >> 16) & ((1 << 16) - 1);
_G_uint32_t lo_b = ub & ((1 << 16) - 1);
unsigned long
_G_uint32_t
hi_r = hi_a * hi_b,
mi_r = hi_a * lo_b + lo_a * hi_b,
lo_r = lo_a * lo_b,
@ -113,7 +115,7 @@ Fix48 operator * (const Fix24& a, const Fix24& b)
r.l = rl << 8;
if ( apos != bpos ) {
unsigned long l = r.l;
_G_uint32_t l = r.l;
r.l = -r.l;
r.u = (~r.u + ((l ^ r.l) & Fix24_msb ? 0 : Fix24_lsb)) & 0xffffff00;
}
@ -122,11 +124,11 @@ Fix48 operator * (const Fix24& a, const Fix24& b)
Fix24 operator / (const Fix24& a, const Fix24& b)
{
long q;
_G_int32_t q;
int apos = (a.m >= 0);
unsigned long la = (apos)? a.m : -a.m;
_G_uint32_t la = (apos)? a.m : -a.m;
int bpos = (b.m >= 0);
unsigned long lb = (bpos)? b.m: -b.m;
_G_uint32_t lb = (bpos)? b.m: -b.m;
if (la >= lb)
{
q = (apos == bpos)? Fix24_m_max: Fix24_m_min;
@ -135,7 +137,7 @@ Fix24 operator / (const Fix24& a, const Fix24& b)
else // standard shift-based division alg
{
q = 0;
long r = la;
_G_int32_t r = la;
for (int i = 32; i > 0; i--)
{
@ -151,13 +153,13 @@ Fix24 operator / (const Fix24& a, const Fix24& b)
q += 0x80; // Round result to 24 bits
if (apos != bpos) q = -q; // Fix sign
}
return (q & ~0xFF);
return (q & ~0xff);
}
Fix48 operator + (const Fix48& f, const Fix48& g)
{
long lo_r = (f.m.l >> 8) + (g.m.l >> 8);
_G_int32_t lo_r = (f.m.l >> 8) + (g.m.l >> 8);
twolongs r;
r.u = f.m.u + g.m.u + (lo_r & 0x01000000L ? 0x00000100L : 0);
r.l = lo_r << 8;
@ -189,15 +191,15 @@ Fix48 operator * (const Fix48& a, int b)
a.range_error(r);
}
else {
unsigned long
_G_uint32_t
lo_r = (a.m.l & 0xffff) * ub,
mi_r = ((a.m.l >> 16) & 0xffff) * ub,
hi_r = a.m.u * ub;
r.l = lo_r + (mi_r << 16);
r.u = hi_r + ((mi_r >> 8) & 0x00ffff00L);
if ( !bpos ) {
unsigned long l = r.l;
r.l = -r.l;
_G_uint32_t l = r.l;
r.l = -r.l & 0xffffffff;
r.u = ~r.u + ((l ^ r.l) & Fix24_msb ? 0 : Fix24_lsb);
}
}
@ -223,15 +225,15 @@ Fix48 operator >> (const Fix48& a, int b)
twolongs r; r.u = 0; r.l = 0;
if ( b >= 0 )
if ( b < 24 ) {
r.l = (a.m.u << (24 - b)) + ((a.m.l >> b) & 0xffffff00L);
r.u = (a.m.u >> b) & 0xffffff00L;
r.l = ((a.m.u << (24 - b)) & 0xffffffffL) + ((a.m.l >> b) & 0xffffff00L);
r.u = (a.m.u >> b) & ~0xffL;
}
else if ( b < 48 ) {
r.l = (a.m.u >> (b - 24)) & 0xffffff00L;
r.u = (a.m.u >> 24) & 0xffffff00L;
r.u = (a.m.u >> 24) & ~0xffL;
}
else {
r.l = (a.m.u >> 24) & 0xffffff00L;
r.l = (a.m.u >> 24) & ~0xffL;
r.u = r.l;
}
return r;
@ -239,7 +241,7 @@ Fix48 operator >> (const Fix48& a, int b)
// error handling
void Fix24::overflow(long& i) const
void Fix24::overflow(_G_int32_t& i) const
{
(*Fix24_overflow_handler)(i);
}
@ -249,7 +251,7 @@ void Fix48::overflow(twolongs& i) const
(*Fix48_overflow_handler)(i);
}
void Fix24::range_error(long& i) const
void Fix24::range_error(_G_int32_t& i) const
{
(*Fix24_range_error_handler)(i);
}
@ -303,15 +305,15 @@ void set_range_error_handler(Fix24_peh handler24, Fix48_peh handler48) {
set_Fix48_range_error_handler(handler48);
}
void Fix24_overflow_saturate(long& i)
void Fix24_overflow_saturate(_G_int32_t& i)
{ i = (i > 0 ? Fix24_m_min : Fix24_m_max); }
void Fix24_ignore(long&) {}
void Fix24_warning(long&)
void Fix24_ignore(_G_int32_t&) {}
void Fix24_warning(_G_int32_t&)
{ cerr << "warning: Fix24 result out of range\n"; }
void Fix24_overflow_warning_saturate(long& i)
void Fix24_overflow_warning_saturate(_G_int32_t& i)
{ cerr << "warning: Fix24 result out of range\n";
Fix24_overflow_saturate(i); }
void Fix24_abort(long&)
void Fix24_abort(_G_int32_t&)
{ cerr << "error: Fix24 result out of range\n"; abort(); }
void Fix48_ignore(twolongs&) {}

View File

@ -79,7 +79,7 @@ MLCG::reset()
seedTwo = (seedTwo % 2147483397) + 1;
}
unsigned long MLCG::asLong()
_G_uint32_t MLCG::asLong()
{
_G_int32_t k = seedOne % 53668;

View File

@ -28,7 +28,11 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#include <builtin.h>
extern "C" {
#if 1
#include <rx.h>
#else
#include <regex.h>
#endif
}
#include <Regex.h>
@ -46,17 +50,18 @@ Regex::Regex(const char* t, int fast, int bufsize,
{
int tlen = (t == 0)? 0 : strlen(t);
buf = new re_pattern_buffer;
memset (buf, 0, sizeof(re_pattern_buffer));
reg = new re_registers;
if (fast)
buf->fastmap = (char*)malloc(256);
else
buf->fastmap = 0;
buf->translate = (char*)transtable;
buf->translate = (unsigned char*)transtable;
if (tlen > bufsize)
bufsize = tlen;
buf->allocated = bufsize;
buf->buffer = (char *)malloc(buf->allocated);
char* msg = re_compile_pattern((const char*)t, tlen, buf);
const char* msg = re_compile_pattern((const char*)t, tlen, buf);
if (msg != 0)
(*lib_error_handler)("Regex", msg);
else if (fast)

View File

@ -25,7 +25,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#include <builtin.h>
#include "SLList.h"
void BaseSLList::error(const char* msg)
void BaseSLList::error(const char* msg) const
{
(*lib_error_handler)("SLList", msg);
}
@ -184,7 +184,7 @@ void BaseSLList::del_after(Pix p)
delete_node(t);
}
int BaseSLList::owns(Pix p)
int BaseSLList::owns(Pix p) const
{
BaseSLNode* t = last;
if (t != 0 && p != 0)
@ -227,7 +227,7 @@ void BaseSLList::del_front()
delete_node(t);
}
int BaseSLList::OK()
int BaseSLList::OK() const
{
int v = 1;
if (last != 0)

View File

@ -29,10 +29,6 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#include <new.h>
#include <builtin.h>
// extern "C" {
#include <regex.h>
// }
void String::error(const char* msg) const
{
(*lib_error_handler)("String", msg);
@ -171,7 +167,8 @@ StrRep* Salloc(StrRep* old, const char* src, int srclen, int newlen)
// generally be faster in the long run to get new space & copy
// than to call realloc
StrRep* Sresize(StrRep* old, int newlen)
static StrRep*
Sresize(StrRep* old, int newlen)
{
if (old == &_nilStrRep) old = 0;
StrRep* rep;
@ -191,6 +188,14 @@ StrRep* Sresize(StrRep* old, int newlen)
return rep;
}
void
String::alloc (int newsize)
{
unsigned short old_len = rep->len;
rep = Sresize(rep, newsize);
rep->len = old_len;
}
// like allocate, but we know that src is a StrRep
StrRep* Scopy(StrRep* old, const StrRep* s)
@ -960,56 +965,38 @@ int split(const String& src, String results[], int n, const Regex& r)
#if defined(__GNUG__) && !defined(_G_NO_NRV)
String join(String src[], int n, const String& separator) return x;
{
String sep = separator;
int xlen = 0;
for (int i = 0; i < n; ++i)
xlen += src[i].length();
xlen += (n - 1) * sep.length();
x.alloc(xlen);
int j = 0;
for (i = 0; i < n - 1; ++i)
{
ncopy(src[i].chars(), &(x.rep->s[j]), src[i].length());
j += src[i].length();
ncopy(sep.chars(), &(x.rep->s[j]), sep.length());
j += sep.length();
}
ncopy0(src[i].chars(), &(x.rep->s[j]), src[i].length());
}
#else
String join(String src[], int n, const String& separator)
{
String x;
String sep = separator;
int xlen = 0;
for (int i = 0; i < n; ++i)
xlen += src[i].length();
xlen += (n - 1) * sep.length();
x.alloc(xlen);
int j = 0;
for (i = 0; i < n - 1; ++i)
{
ncopy(src[i].chars(), &(x.rep->s[j]), src[i].length());
j += src[i].length();
ncopy(sep.chars(), &(x.rep->s[j]), sep.length());
j += sep.length();
}
ncopy0(src[i].chars(), &(x.rep->s[j]), src[i].length());
return x;
}
#define RETURN(r) return
#define RETURNS(r) return r;
#define RETURN_OBJECT(TYPE, NAME) /* nothing */
#else /* _G_NO_NRV */
#define RETURN(r) return r
#define RETURNS(r) /* nothing */
#define RETURN_OBJECT(TYPE, NAME) TYPE NAME;
#endif
String join(String src[], int n, const String& separator) RETURNS(x)
{
RETURN_OBJECT(String,x)
String sep = separator;
int xlen = 0;
for (int i = 0; i < n; ++i)
xlen += src[i].length();
xlen += (n - 1) * sep.length();
x.rep = Sresize (x.rep, xlen);
int j = 0;
for (i = 0; i < n - 1; ++i)
{
ncopy(src[i].chars(), &(x.rep->s[j]), src[i].length());
j += src[i].length();
ncopy(sep.chars(), &(x.rep->s[j]), sep.length());
j += sep.length();
}
ncopy0(src[i].chars(), &(x.rep->s[j]), src[i].length());
RETURN(x);
}
/*
misc

View File

@ -26,7 +26,7 @@ typedef _VOLATILE_VOID (*NoReturnFunc)(void);
This is to avoid a warning from g++ that a `volatile' function does return. */
#define ABORT() ((NoReturnFunc)abort)()
#else
#define ABORT abort()
#define ABORT() abort()
#endif
_VOLATILE_VOID default_one_arg_error_handler(const char* msg)

View File

@ -0,0 +1,79 @@
/* This is part of GNU C++ Library.
Copyright (C) 1994 Free Software Foundation
This file is part of the GNU C++ Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/* terminate(), unexpected(), set_terminate(), set_unexpected() as
well as the default terminate func and default unexpected func */
#if 0
extern int printf();
#endif
typedef void (*vfp)();
void
__default_terminate()
{
abort();
}
void
__default_unexpected()
{
__default_terminate();
}
static vfp __terminate_func = __default_terminate;
static vfp __unexpected_func = __default_unexpected;
vfp
set_terminate(func)
vfp func;
{
vfp old = __terminate_func;
__terminate_func = func;
return old;
}
vfp
set_unexpected(func)
vfp func;
{
vfp old = __unexpected_func;
__unexpected_func = func;
return old;
}
void
terminate()
{
__terminate_func();
}
void
unexpected()
{
__unexpected_func();
}

View File

@ -37,6 +37,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#if !_G_HAVE_SYS_RESOURCE || !defined(RUSAGE_SELF)
#define USE_TIMES
#include <sys/param.h>
#include <sys/types.h>
#include <sys/times.h>
#if !defined (HZ) && defined(CLK_TCK)
#define HZ CLK_TCK

View File

@ -44,7 +44,8 @@ extern int errno;
The position in the buffer that corresponds to the position
in external file system is file_ptr().
This is normally egptr(), except in putback mode, when it is _save_egptr.
This is normally _IO_read_end, except in putback mode,
when it is _IO_save_end.
If the field _fb._offset is >= 0, it gives the offset in
the file as a whole corresponding to eGptr(). (???)
@ -238,7 +239,7 @@ _IO_do_write(fp, data, to_do)
fp->_cur_column = _IO_adjust_column(fp->_cur_column - 1, data, to_do) + 1;
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
fp->_IO_write_end = (fp->_flags & _IO_LINE_BUF+_IO_UNBUFFERED) ? fp->_IO_buf_base
fp->_IO_write_end = (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) ? fp->_IO_buf_base
: fp->_IO_buf_end;
return count != to_do ? EOF : 0;
}
@ -311,7 +312,7 @@ int _IO_file_overflow (f, ch)
f->_IO_write_end = f->_IO_buf_end;
f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
if (f->_flags & _IO_LINE_BUF+_IO_UNBUFFERED)
if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
f->_IO_write_end = f->_IO_write_ptr;
f->_flags |= _IO_CURRENTLY_PUTTING;
}
@ -389,10 +390,10 @@ _IO_file_seekoff(fp, offset, mode)
switch (dir)
{
case _IO_seek_cur:
if (fp->_offset == _IO_pos_BAD)
goto dumb;
/* Adjust for read-ahead (bytes is buffer). */
offset -= fp->_IO_read_end - fp->_IO_read_ptr;
if (fp->_offset == _IO_pos_BAD)
goto dumb;
/* Make offset absolute, assuming current pointer is file_ptr(). */
offset += _IO_pos_as_off(fp->_offset);
@ -414,24 +415,27 @@ _IO_file_seekoff(fp, offset, mode)
}
/* At this point, dir==_IO_seek_set. */
#ifdef TODO
/* If destination is within current buffer, optimize: */
if (fp->_offset != IO_pos_BAD && fp->_IO_read_base != NULL)
if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
&& !_IO_in_backup (fp))
{
/* Offset relative to start of main get area. */
_IO_pos_t rel_offset = offset - _fb._offset
+ (eGptr()-Gbase());
_IO_pos_t rel_offset = offset - fp->_offset
+ (fp->_IO_read_end - fp->_IO_read_base);
if (rel_offset >= 0)
{
#if 0
if (_IO_in_backup(fp))
_IO_switch_to_main_get_area(fp);
if (rel_offset <= _IO_read_end - _IO_read_base)
#endif
if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
{
_IO_setg(fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
fp->_IO_read_end);
_IO_setp(fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
return offset;
}
#ifdef TODO
/* If we have streammarkers, seek forward by reading ahead. */
if (_IO_have_markers(fp))
{
@ -441,7 +445,9 @@ _IO_file_seekoff(fp, offset, mode)
goto dumb;
return offset;
}
#endif
}
#ifdef TODO
if (rel_offset < 0 && rel_offset >= Bbase() - Bptr())
{
if (!_IO_in_backup(fp))
@ -449,8 +455,10 @@ _IO_file_seekoff(fp, offset, mode)
gbump(fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
return offset;
}
#endif
}
#ifdef TODO
_IO_unsave_markers(fp);
#endif

View File

@ -23,7 +23,7 @@ This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#include <libioP.h>
#ifdef USE_DTOA
#ifdef _IO_USE_DTOA
/****************************************************************
*
* The author of this software is David M. Gay.
@ -489,7 +489,7 @@ s2b
#endif
{
int i, k;
long x, y;
_G_int32_t x, y;
x = (nd + 8) / 9;
for(k = 0, y = 1; x > y; y <<= 1, k++) ;
@ -643,7 +643,7 @@ mult
xbe = xb + wb;
xc0 = c->x;
for(; xb < xbe; xb++, xc0++) {
if (y = *xb & 0xffff) {
if ((y = *xb & 0xffff)) {
x = xa;
xc = xc0;
carry = 0;
@ -657,7 +657,7 @@ mult
while(x < xae);
*xc = carry;
}
if (y = *xb >> 16) {
if ((y = *xb >> 16)) {
x = xa;
xc = xc0;
carry = 0;
@ -794,9 +794,9 @@ diff
#endif
{
int i, wa, wb;
long borrow, y; /* We need signed shifts here. */
_G_int32_t borrow, y; /* We need signed shifts here. */
unsigned32 *xa, *xae, *xb, *xbe, *xc;
long z;
_G_int32_t z;
i = cmp(a,b);
if (!i) {
@ -856,7 +856,7 @@ ulp
(double x)
#endif
{
register long L;
register _G_int32_t L;
double a;
L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
@ -879,7 +879,7 @@ ulp
else {
word0(a) = 0;
L -= Exp_shift;
word1(a) = L >= 31 ? 1 : 1 << 31 - L;
word1(a) = L >= 31 ? 1 : 1 << (31 - L);
}
}
#endif
@ -913,16 +913,16 @@ b2d
k = hi0bits(y);
*e = 32 - k;
if (k < Ebits) {
d0 = Exp_1 | y >> Ebits - k;
d0 = Exp_1 | y >> (Ebits - k);
w = xa > xa0 ? *--xa : 0;
d1 = y << (32-Ebits) + k | w >> Ebits - k;
d1 = y << ((32-Ebits) + k) | w >> (Ebits - k);
goto ret_d;
}
z = xa > xa0 ? *--xa : 0;
if (k -= Ebits) {
d0 = Exp_1 | y << k | z >> 32 - k;
d0 = Exp_1 | y << k | z >> (32 - k);
y = xa > xa0 ? *--xa : 0;
d1 = z << k | y >> 32 - k;
d1 = z << k | y >> (32 - k);
}
else {
d0 = Exp_1 | y;
@ -974,9 +974,9 @@ d2b
z |= Exp_msk11;
#endif
if (y = d1) {
if (k = lo0bits(&y)) {
x[0] = y | z << 32 - k;
if ((y = d1)) {
if ((k = lo0bits(&y))) {
x[0] = y | z << (32 - k);
z >>= k;
}
else
@ -1091,7 +1091,7 @@ _IO_strtod
e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
CONST char *s, *s0, *s1;
double aadj, aadj1, adj, rv, rv0;
long L;
_G_int32_t L;
unsigned32 y, z;
Bigint _bb, _b_avail, _bd, _bd0, _bs, _delta;
Bigint *bb = Binit(&_bb);
@ -1280,7 +1280,7 @@ _IO_strtod
/* Get starting approximation = rv * 10**e1 */
if (e1 > 0) {
if (i = e1 & 15)
if ((i = e1 & 15))
rv *= tens[i];
if (e1 &= ~15) {
if (e1 > DBL_MAX_10_EXP) {
@ -1320,7 +1320,7 @@ _IO_strtod
}
else if (e1 < 0) {
e1 = -e1;
if (i = e1 & 15)
if ((i = e1 & 15))
rv /= tens[i];
if (e1 &= ~15) {
e1 >>= 4;
@ -1588,7 +1588,7 @@ _IO_strtod
z = word0(rv) & Exp_mask;
if (y == z) {
/* Can we stop now? */
L = (long)aadj;
L = (_G_int32_t)aadj;
aadj -= L;
/* The tolerances below are conservative. */
if (dsign || word1(rv) || word0(rv) & Bndry_mask) {
@ -1620,10 +1620,10 @@ quorem
#endif
{
int n;
long borrow, y;
_G_int32_t borrow, y;
unsigned32 carry, q, ys;
unsigned32 *bx, *bxe, *sx, *sxe;
long z;
_G_int32_t z;
unsigned32 si, zs;
n = S->wds;
@ -1777,7 +1777,7 @@ _IO_dtoa
int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
spec_case, try_quick;
long L;
_G_int32_t L;
#ifndef Sudden_Underflow
int denorm;
#endif
@ -1874,8 +1874,8 @@ _IO_dtoa
unsigned32 x;
i = bbits + be + (Bias + (P-1) - 1);
x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32
: word1(d) << 32 - i;
x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32)
: word1(d) << (32 - i);
d2 = x;
word0(d2) -= 31*Exp_msk1; /* adjust exponent */
i -= (Bias + (P-1) - 1) + 1;
@ -2006,7 +2006,7 @@ _IO_dtoa
}
d /= ds;
}
else if (j1 = -k) {
else if ((j1 = -k)) {
d *= tens[j1 & 0xf];
for(j = j1 >> 4; j; j >>= 1, i++)
if (j & 1) {
@ -2039,7 +2039,7 @@ _IO_dtoa
*/
eps = 0.5/tens[ilim-1] - eps;
for(i = 0;;) {
L = (long)d;
L = (_G_int32_t)d;
d -= L;
*s++ = '0' + (int)L;
if (d < eps)
@ -2057,7 +2057,7 @@ _IO_dtoa
/* Generate ilim digits, then fix them up. */
eps *= tens[ilim-1];
for(i = 1;; i++, d *= 10.) {
L = (long)d;
L = (_G_int32_t)d;
d -= L;
*s++ = '0' + (int)L;
if (i == ilim) {
@ -2092,7 +2092,7 @@ _IO_dtoa
goto one_digit;
}
for(i = 1;; i++) {
L = (long)(d / ds);
L = (_G_int32_t)(d / ds);
d -= L*ds;
#ifdef Check_FLT_ROUNDS
/* If FLT_ROUNDS == 2, L will usually be high by 1 */
@ -2104,7 +2104,7 @@ _IO_dtoa
*s++ = '0' + (int)L;
if (i == ilim) {
d += d;
if (d > ds || d == ds && L & 1) {
if (d > ds || (d == ds && L & 1)) {
bump_up:
while(*--s == '9')
if (s == s0) {
@ -2169,7 +2169,7 @@ _IO_dtoa
b_avail = b;
b = b_tmp;
}
if (j = b5 - m5)
if ((j = b5 - m5))
b = pow5mult(b, j);
}
else
@ -2203,7 +2203,7 @@ _IO_dtoa
* and for all and pass them and a shift to quorem, so it
* can do shifts and ors to compute the numerator for q.
*/
if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f)
if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f))
i = 32 - i;
if (i > 4) {
i -= 4;
@ -2276,15 +2276,15 @@ _IO_dtoa
goto ret;
}
#endif
if (j < 0 || j == 0 && !mode
if (j < 0 || (j == 0 && !mode
#ifndef ROUND_BIASED
&& !(word1(d) & 1)
#endif
) {
)) {
if (j1 > 0) {
b = lshift(b, 1);
j1 = cmp(b, S);
if ((j1 > 0 || j1 == 0 && dig & 1)
if ((j1 > 0 || (j1 == 0 && dig & 1))
&& dig++ == '9')
goto round_9_up;
}
@ -2324,7 +2324,7 @@ _IO_dtoa
b = lshift(b, 1);
j = cmp(b, S);
if (j > 0 || j == 0 && dig & 1) {
if (j > 0 || (j == 0 && dig & 1)) {
roundoff:
while(*--s == '9')
if (s == s0) {
@ -2354,4 +2354,4 @@ _IO_dtoa
*rve = s;
return s0;
}
#endif /* USE_DTOA */
#endif /* _IO_USE_DTOA */

View File

@ -0,0 +1,55 @@
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 1994 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/* Written by Per Bothner (bothner@cygnus.com). */
#include <iostream.h>
#include "libioP.h"
// These method are provided for backward compatibility reasons.
// It's generally poor style to use them.
// They are not supported by the ANSI/ISO working paper.
_IO_istream_withassign& _IO_istream_withassign::operator=(istream& rhs)
{
if (&rhs != (istream*)this)
{
if (!(_flags & (unsigned int)ios::dont_close)) delete rdbuf();
init (rhs.rdbuf ());
_flags |= ios::dont_close;
_gcount = 0;
}
return *this;
}
_IO_ostream_withassign& _IO_ostream_withassign::operator=(ostream& rhs)
{
if (&rhs != (ostream*)this)
{
if (!(_flags & (unsigned int)ios::dont_close)) delete rdbuf();
init (rhs.rdbuf ());
_flags |= ios::dont_close;
}
return *this;
}

View File

@ -32,9 +32,7 @@ _IO_fclose(fp)
register _IO_FILE *fp;
{
int status = 0;
COERCE_FILE(fp);
if ((fp->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC)
return EOF;
CHECK_FILE(fp, EOF);
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
status = _IO_file_close_it(fp);
fp->_jumps->__finish(fp);

View File

@ -32,7 +32,7 @@ _IO_fgetpos(fp, posp)
_IO_fpos_t *posp;
{
_IO_fpos_t pos;
COERCE_FILE(fp);
CHECK_FILE(fp, EOF);
pos = _IO_seekoff(fp, 0, _IO_seek_cur|_IO_seek_not_in|_IO_seek_not_out);
if (pos == _IO_pos_BAD)
{

View File

@ -33,7 +33,7 @@ _IO_fread(buf, size, count, fp)
{
_IO_size_t bytes_requested = size*count;
_IO_size_t bytes_read;
COERCE_FILE(fp);
CHECK_FILE(fp, 0);
if (bytes_requested == 0)
return 0;
bytes_read = _IO_sgetn(fp, (char *)buf, bytes_requested);

View File

@ -40,7 +40,7 @@ _IO_fscanf
{
int ret;
va_list args;
COERCE_FILE(fp);
CHECK_FILE(fp, EOF);
_IO_va_start(args, format);
ret = _IO_vfscanf(fp, format, args, NULL);
va_end(args);

View File

@ -30,7 +30,7 @@ _IO_fsetpos(fp, posp)
_IO_FILE* fp;
const _IO_fpos_t *posp;
{
COERCE_FILE(fp);
CHECK_FILE(fp, EOF);
if (_IO_seekpos(fp, *posp, 0) == _IO_pos_BAD)
{
/*ANSI explicily requires setting errno to a positive value on failure.*/

View File

@ -0,0 +1,102 @@
/*
Copyright (C) 1994 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifdef __STDC__
#include <stdlib.h>
#endif
#include "libioP.h"
#include <string.h>
#include <errno.h>
/* Read up to (and including) a TERMINATOR from FP into *LINEPTR
(and null-terminate it). *LINEPTR is a pointer returned from malloc (or
NULL), pointing to *N characters of space. It is realloc'ed as
necessary. Returns the number of characters read (not including the
null terminator), or -1 on error or EOF. */
_IO_ssize_t
_IO_getdelim (lineptr, n, delimiter, fp)
char **lineptr;
_IO_size_t *n;
int delimiter;
_IO_FILE *fp;
{
register _IO_ssize_t cur_len = 0;
_IO_ssize_t len;
if (lineptr == NULL || n == NULL)
{
#ifdef EINVAL
errno = EINVAL;
#endif
return -1;
}
CHECK_FILE (fp, -1);
if (_IO_ferror (fp))
return -1;
if (*lineptr == NULL || *n == 0)
{
*n = 120;
*lineptr = (char *) malloc (*n);
if (*lineptr == NULL)
return -1;
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len <= 0)
{
if (__underflow (fp) == EOF)
return -1;
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
for (;;)
{
_IO_size_t needed;
char *t;
t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
if (t != NULL)
len = (t - fp->_IO_read_ptr) + 1;
/* make enough space for len+1 (for final NUL) bytes. */
needed = cur_len + len + 1;
if (needed > *n)
{
if (t == NULL && needed < 2 * *n)
needed = 2 * *n; /* Be generous. */
*n = needed;
*lineptr = (char *) realloc (*lineptr, needed);
if (*lineptr == NULL)
return -1;
}
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
cur_len += len;
if (t != NULL || __underflow (fp) == EOF)
break;
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
lineptr[cur_len] = '\0';
return cur_len;
}

View File

@ -70,6 +70,8 @@ istream& istream::get(char& c)
_gcount = 1;
}
}
else
_gcount = 0;
return *this;
}
@ -87,13 +89,13 @@ int istream::peek()
istream& istream::ignore(int n /* = 1 */, int delim /* = EOF */)
{
_gcount = 0;
if (ipfx1()) {
register streambuf* sb = _strbuf;
if (delim == EOF) {
_gcount = sb->ignore(n);
return *this;
}
_gcount = 0;
for (;;) {
#if 0
if (n != MAXINT) // FIXME
@ -120,6 +122,8 @@ istream& istream::read(char *s, int n)
if (_gcount != n)
set(ios::failbit|ios::eofbit);
}
else
_gcount = 0;
return *this;
}
@ -307,6 +311,13 @@ READ_INT(unsigned long long)
READ_INT(bool)
#endif
istream& istream::operator>>(long double& x)
{
if (ipfx0())
scan("%lg", &x);
return *this;
}
istream& istream::operator>>(double& x)
{
if (ipfx0())
@ -552,7 +563,7 @@ ostream& ostream::operator<<(double n)
prec = 6; /* default */
// Do actual conversion.
#ifdef USE_DTOA
#ifdef _IO_USE_DTOA
if (_IO_outfloat(n, rdbuf(), format_char, width(0),
prec, flags(),
flags() & ios::showpos ? '+' : 0,
@ -710,7 +721,7 @@ streampos ostream::tellp()
ostream& ostream::flush()
{
if (_strbuf->_jumps->__sync(_strbuf))
if (_strbuf->sync())
set(ios::badbit);
return *this;
}

View File

@ -29,7 +29,7 @@ _IO_ungetc(c, fp)
int c;
_IO_FILE *fp;
{
COERCE_FILE(fp);
CHECK_FILE(fp, EOF);
if (c == EOF)
return EOF;
return _IO_sputbackc(fp, (unsigned char)c);

View File

@ -196,7 +196,7 @@ _IO_vfprintf(fp, fmt0, ap)
#ifdef FLOATING_POINT
int softsign; /* temporary negative sign for floats */
double _double; /* double precision arguments %[eEfgG] */
#ifndef USE_DTOA
#ifndef _IO_USE_DTOA
int fpprec; /* `extra' floating precision in [eEfgG] */
#endif
#endif
@ -256,7 +256,7 @@ _IO_vfprintf(fp, fmt0, ap)
flags = 0;
dprec = 0;
#if defined(FLOATING_POINT) && !defined (USE_DTOA)
#if defined(FLOATING_POINT) && !defined (_IO_USE_DTOA)
fpprec = 0;
#endif
width = 0;
@ -362,7 +362,7 @@ reswitch: switch (ch) {
case 'g':
case 'G':
_double = va_arg(ap, double);
#ifdef USE_DTOA
#ifdef _IO_USE_DTOA
{
int fmt_flags = 0;
int fill = ' ';
@ -564,7 +564,7 @@ number: if ((dprec = prec) >= 0)
/*
* compute actual size, so we know how much to pad.
*/
#if defined(FLOATING_POINT) && !defined (USE_DTOA)
#if defined(FLOATING_POINT) && !defined (_IO_USE_DTOA)
fieldsz = size + fpprec;
#else
fieldsz = size;
@ -602,7 +602,7 @@ number: if ((dprec = prec) >= 0)
/* the string or number proper */
PRINT(cp, size);
#if defined(FLOATING_POINT) && !defined (USE_DTOA)
#if defined(FLOATING_POINT) && !defined (_IO_USE_DTOA)
/* trailing f.p. zeroes */
PAD_0(fpprec);
#endif
@ -622,7 +622,7 @@ number: if ((dprec = prec) >= 0)
/* NOTREACHED */
}
#if defined(FLOATING_POINT) && !defined(USE_DTOA)
#if defined(FLOATING_POINT) && !defined(_IO_USE_DTOA)
static char *exponent(register char *p, register int exp, int fmtch)
{
@ -882,4 +882,4 @@ eformat: if (expcnt) {
return (t - startp);
}
#endif /* defined(FLOATING_POINT) && !defined(USE_DTOA) */
#endif /* defined(FLOATING_POINT) && !defined(_IO_USE_DTOA) */

View File

@ -105,7 +105,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
extern u_long strtoul __P((const char*, char**, int));
extern long strtol __P((const char*, char**, int));
static const u_char *__sccl __P((char *tab, const u_char *fmt));
#ifndef USE_DTOA
#ifndef _IO_USE_DTOA
extern double atof();
#endif
@ -655,7 +655,7 @@ again: c = *fmt++;
if ((flags & SUPPRESS) == 0) {
double res;
*p = 0;
#ifdef USE_DTOA
#ifdef _IO_USE_DTOA
res = _IO_strtod(buf, NULL);
#else
res = atof(buf);

View File

@ -68,6 +68,19 @@ stdiobuf::~stdiobuf()
streamsize stdiobuf::sys_read(char* buf, streamsize size)
{
// A minor optimization, but it makes a noticable difference.
// A bigger optimization would be to write stdiobuf::underflow,
// but that has some modularity disadvantages. Re-evaluate that
// after we have gotten rid of the double indirection. FIXME
if (size == 1)
{
register ch = getc(_file);
if (ch == EOF)
return 0;
*buf = (char)ch;
return 1;
}
else
return fread(buf, 1, size, _file);
}

View File

@ -76,7 +76,7 @@ char *strstreambuf::str()
return base();
}
_IO_ssize_t strstreambuf::pcount() { return _IO_str_count (this); }
_IO_ssize_t strstreambuf::pcount () { return _IO_write_ptr - _IO_write_base; }
int strstreambuf::overflow(int c /* = EOF */)
{