- added implementation of stdc++ for haiku
- this differs slightly from the one that lives in buildtools/gcc as it has been "ported" to the newer libio that haiku uses as part of its own libroot git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9906 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,4 +4,5 @@ SubInclude OBOS_TOP src libs freetype2 ;
|
||||
SubInclude OBOS_TOP src libs zlib ;
|
||||
SubInclude OBOS_TOP src libs png ;
|
||||
SubInclude OBOS_TOP src libs termcap ;
|
||||
SubInclude OBOS_TOP src libs stdc++ ;
|
||||
SubInclude OBOS_TOP src libs pdflib ;
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
SubDir OBOS_TOP src libs stdc++ ;
|
||||
|
||||
local savedCcFlags = $(CCFLAGS) ;
|
||||
CCFLAGS = ;
|
||||
local savedC++Flags = $(C++FLAGS) ;
|
||||
C++FLAGS = ;
|
||||
|
||||
# define header-searchpaths all by ourselves, as including system headers
|
||||
# messes things up:
|
||||
# use the following paths to make use of the headers contained in glibc,
|
||||
# but this doesn't work yet, as the libio we are using here and the one
|
||||
# contained in our libroot are different versions.
|
||||
HDRS =
|
||||
[ FDirName $(OBOS_TOP) src kernel libroot posix glibc libio ]
|
||||
[ FDirName $(OBOS_TOP) src kernel libroot posix glibc stdlib ]
|
||||
[ FDirName $(OBOS_TOP) src kernel libroot posix glibc stdio-common ]
|
||||
[ FDirName $(OBOS_TOP) src kernel libroot posix glibc include ]
|
||||
[ FDirName $(OBOS_TOP) src kernel libroot posix glibc include arch x86 ]
|
||||
[ FDirName $(OBOS_TOP) headers cpp ]
|
||||
[ FDirName $(OBOS_TOP) src kernel libroot posix glibc ]
|
||||
[ FDirName $(OBOS_TOP) headers posix ]
|
||||
[ FDirName $(OBOS_TOP) headers os ]
|
||||
[ FDirName $(OBOS_TOP) headers os kernel ]
|
||||
[ FDirName $(OBOS_TOP) headers os storage ]
|
||||
[ FDirName $(OBOS_TOP) headers os support ]
|
||||
$(LIBGCC_DIR)/include ; # such that include_next will work
|
||||
|
||||
# some source-files generate several different objects, depending on
|
||||
# the defines that are used during the compilation call.
|
||||
# So we explicitly state each of these (with their respective defines):
|
||||
rule GenerateStdC++Object
|
||||
{
|
||||
# GenerateStdC++Object <object> : <source> : <defines> ;
|
||||
local object = [ FGristFiles $(1) ] ;
|
||||
local sources = $(2) ;
|
||||
local defines = $(3) ;
|
||||
|
||||
local source ;
|
||||
|
||||
for source in [ FGristFiles $(sources) ] {
|
||||
CCFLAGS on $(source:S=$(SUFOBJ)) = $(savedCcFlags) -Wno-missing-prototypes ;
|
||||
C++FLAGS on $(source:S=$(SUFOBJ)) = $(savedC++Flags) -nostdinc++ -fno-implicit-templates
|
||||
-Wno-sign-compare -fpic ;
|
||||
}
|
||||
|
||||
SetupObjectsDir ;
|
||||
MakeLocateObjects $(object) ;
|
||||
if $(object) {
|
||||
Object $(object) : $(sources) ;
|
||||
} else {
|
||||
Objects $(sources) ;
|
||||
}
|
||||
if $(defines) {
|
||||
if $(object) {
|
||||
ObjectDefines $(object) : $(defines) ;
|
||||
} else {
|
||||
ObjectDefines $(sources) : $(defines) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GenerateStdC++Object cstrio.o
|
||||
: sinst.cc
|
||||
: C EXTRACT INSERT GETLINE
|
||||
;
|
||||
|
||||
GenerateStdC++Object cstrmain.o
|
||||
: sinst.cc
|
||||
: C REP MAIN TRAITS ADDSS ADDPS ADDCS ADDSP ADDSC EQSS EQPS EQSP NESS NEPS
|
||||
NESP LTSS LTPS LTSP GTSS GTPS GTSP LESS LEPS LESP GESS GEPS GESP ;
|
||||
|
||||
GenerateStdC++Object dcomio.o
|
||||
: cinst.cc
|
||||
: D EXTRACT INSERT ;
|
||||
|
||||
GenerateStdC++Object dcomplex.o
|
||||
: cinst.cc
|
||||
: D MAIN ADDCC ADDCF ADDFC SUBCC SUBCF SUBFC MULCC MULCF MULFC DIVCC DIVCF
|
||||
DIVFC PLUS MINUS EQCC EQCF EQFC NECC NECF NEFC ABS ARG POLAR CONJ NORM COS
|
||||
COSH EXP LOG POWCC POWCF POWCI POWFC SIN SINH SQRT ;
|
||||
|
||||
GenerateStdC++Object fcomio.o
|
||||
: cinst.cc
|
||||
: F EXTRACT INSERT ;
|
||||
|
||||
GenerateStdC++Object fcomplex.o
|
||||
: cinst.cc
|
||||
: F MAIN ADDCC ADDCF ADDFC SUBCC SUBCF SUBFC MULCC MULCF MULFC DIVCC DIVCF
|
||||
DIVFC PLUS MINUS EQCC EQCF EQFC NECC NECF NEFC ABS ARG POLAR CONJ NORM COS
|
||||
COSH EXP LOG POWCC POWCF POWCI POWFC SIN SINH SQRT ;
|
||||
|
||||
GenerateStdC++Object ldcomio.o
|
||||
: cinst.cc
|
||||
: LD EXTRACT INSERT ;
|
||||
|
||||
GenerateStdC++Object ldcomplex.o
|
||||
: cinst.cc
|
||||
: LD MAIN ADDCC ADDCF ADDFC SUBCC SUBCF SUBFC MULCC MULCF MULFC DIVCC DIVCF
|
||||
DIVFC PLUS MINUS EQCC EQCF EQFC NECC NECF NEFC ABS ARG POLAR CONJ NORM COS
|
||||
COSH EXP LOG POWCC POWCF POWCI POWFC SIN SINH SQRT ;
|
||||
|
||||
# generate standard objects through our new rule, too:
|
||||
GenerateStdC++Object
|
||||
: cmathi.cc
|
||||
cstdlibi.cc
|
||||
cstringi.cc
|
||||
stdexcepti.cc ;
|
||||
|
||||
# c++ parts from libio:
|
||||
GenerateStdC++Object
|
||||
: builtinbuf.cc
|
||||
editbuf.cc
|
||||
filebuf.cc
|
||||
fstream.cc
|
||||
indstream.cc
|
||||
ioassign.cc
|
||||
ioextend.cc
|
||||
iomanip.cc
|
||||
iostream.cc
|
||||
isgetline.cc
|
||||
isgetsb.cc
|
||||
isscan.cc
|
||||
osform.cc
|
||||
parsestream.cc
|
||||
pfstream.cc
|
||||
PlotFile.cc
|
||||
procbuf.cc
|
||||
sbform.cc
|
||||
sbgetline.cc
|
||||
sbscan.cc
|
||||
SFile.cc
|
||||
stdexcepti.cc
|
||||
stdiostream.cc
|
||||
stdstrbufs.cc
|
||||
stdstreams.cc
|
||||
stlinst.cc
|
||||
stream.cc
|
||||
streambuf.cc
|
||||
strstream.cc ;
|
||||
|
||||
# stuff imported from libiberty:
|
||||
GenerateStdC++Object
|
||||
: basename.c getpagesize.c insque.c sigsetmask.c strerror.c vfork.c ;
|
||||
|
||||
SharedLibraryFromObjects stdc++.r4.so :
|
||||
basename.o
|
||||
builtinbuf.o
|
||||
cmathi.o
|
||||
cstdlibi.o
|
||||
cstringi.o
|
||||
cstrio.o
|
||||
cstrmain.o
|
||||
dcomio.o
|
||||
dcomplex.o
|
||||
editbuf.o
|
||||
fcomio.o
|
||||
fcomplex.o
|
||||
filebuf.o
|
||||
fstream.o
|
||||
getpagesize.o
|
||||
indstream.o
|
||||
insque.o
|
||||
ioassign.o
|
||||
ioextend.o
|
||||
iomanip.o
|
||||
iostream.o
|
||||
isgetline.o
|
||||
isgetsb.o
|
||||
isscan.o
|
||||
ldcomio.o
|
||||
ldcomplex.o
|
||||
osform.o
|
||||
parsestream.o
|
||||
pfstream.o
|
||||
PlotFile.o
|
||||
procbuf.o
|
||||
sbform.o
|
||||
sbgetline.o
|
||||
sbscan.o
|
||||
SFile.o
|
||||
sigsetmask.o
|
||||
stdexcepti.o
|
||||
stdiostream.o
|
||||
stdstrbufs.o
|
||||
stdstreams.o
|
||||
stlinst.o
|
||||
stream.o
|
||||
streambuf.o
|
||||
strerror.o
|
||||
strstream.o
|
||||
vfork.o ;
|
||||
|
||||
CCFLAGS = $(savedCcFlags) ;
|
||||
C++FLAGS = $(savedC++Flags) ;
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988, 1992, 1993 Free Software Foundation
|
||||
written by Doug Lea ([email protected])
|
||||
converted to use iostream library by Per Bothner ([email protected])
|
||||
|
||||
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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with GCC 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 __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <PlotFile.h>
|
||||
|
||||
/*
|
||||
PlotFile implementation module
|
||||
*/
|
||||
|
||||
|
||||
PlotFile& PlotFile:: cmd(char c)
|
||||
{
|
||||
ofstream::put(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: operator<<(const int x)
|
||||
{
|
||||
#if defined(convex)
|
||||
ofstream::put((char)(x>>8));
|
||||
ofstream::put((char)(x&0377));
|
||||
#else
|
||||
ofstream::put((char)(x&0377));
|
||||
ofstream::put((char)(x>>8));
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: operator<<(const char *s)
|
||||
{
|
||||
*(ofstream*)this << s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PlotFile& PlotFile:: arc(const int xi, const int yi,
|
||||
const int x0, const int y0,
|
||||
const int x1, const int y1)
|
||||
{
|
||||
return cmd('a') << xi << yi << x0 << y0 << x1 << y1;
|
||||
}
|
||||
|
||||
|
||||
PlotFile& PlotFile:: box(const int x0, const int y0,
|
||||
const int x1, const int y1)
|
||||
{
|
||||
line(x0, y0, x0, y1);
|
||||
line(x0, y1, x1, y1);
|
||||
line(x1, y1, x1, y0);
|
||||
return line(x1, y0, x0, y0);
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: circle(const int x, const int y, const int r)
|
||||
{
|
||||
return cmd('c') << x << y << r;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: cont(const int xi, const int yi)
|
||||
{
|
||||
return cmd('n') << xi << yi;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: dot(const int xi, const int yi, const int dx,
|
||||
int n, const int* pat)
|
||||
{
|
||||
cmd('d') << xi << yi << dx << n;
|
||||
while (n-- > 0) *this << *pat++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: erase()
|
||||
{
|
||||
return cmd('e');
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: label(const char* s)
|
||||
{
|
||||
return cmd('t') << s << "\n";
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: line(const int x0, const int y0,
|
||||
const int x1, const int y1)
|
||||
{
|
||||
return cmd('l') << x0 << y0 << x1 << y1;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: linemod(const char* s)
|
||||
{
|
||||
return cmd('f') << s << "\n";
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: move(const int xi, const int yi)
|
||||
{
|
||||
return cmd('m') << xi << yi;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: point(const int xi, const int yi)
|
||||
{
|
||||
return cmd('p') << xi << yi;
|
||||
}
|
||||
|
||||
PlotFile& PlotFile:: space(const int x0, const int y0,
|
||||
const int x1, const int y1)
|
||||
{
|
||||
return cmd('s') << x0 << y0 << x1 << y1;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea ([email protected])
|
||||
|
||||
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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <SFile.h>
|
||||
|
||||
SFile::SFile(const char *filename, int size, int mode, int prot)
|
||||
: fstream(filename, mode, prot)
|
||||
{
|
||||
sz = size;
|
||||
}
|
||||
|
||||
SFile::SFile(int fd, int size)
|
||||
: fstream(fd)
|
||||
{
|
||||
sz = size;
|
||||
}
|
||||
|
||||
void SFile::open(const char *name, int size, int mode, int prot)
|
||||
{
|
||||
fstream::open(name, mode, prot);
|
||||
sz = size;
|
||||
}
|
||||
|
||||
SFile& SFile::get(void* x)
|
||||
{
|
||||
read(x, sz);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SFile& SFile::put(void* x)
|
||||
{
|
||||
write(x, sz);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SFile& SFile::operator[](long i)
|
||||
{
|
||||
if (rdbuf()->pubseekoff(i * sz, ios::beg) == EOF)
|
||||
set(ios::badbit);
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/* ANSI and traditional C compatability macros
|
||||
Copyright 1991, 1992, 1996 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This program 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 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* ANSI and traditional C compatibility macros
|
||||
|
||||
ANSI C is assumed if __STDC__ is #defined.
|
||||
|
||||
Macro ANSI C definition Traditional C definition
|
||||
----- ---- - ---------- ----------- - ----------
|
||||
PTR `void *' `char *'
|
||||
LONG_DOUBLE `long double' `double'
|
||||
VOLATILE `volatile' `'
|
||||
SIGNED `signed' `'
|
||||
PTRCONST `void *const' `char *'
|
||||
ANSI_PROTOTYPES 1 not defined
|
||||
|
||||
CONST is also defined, but is obsolete. Just use const.
|
||||
|
||||
obsolete -- DEFUN (name, arglist, args)
|
||||
|
||||
Defines function NAME.
|
||||
|
||||
ARGLIST lists the arguments, separated by commas and enclosed in
|
||||
parentheses. ARGLIST becomes the argument list in traditional C.
|
||||
|
||||
ARGS list the arguments with their types. It becomes a prototype in
|
||||
ANSI C, and the type declarations in traditional C. Arguments should
|
||||
be separated with `AND'. For functions with a variable number of
|
||||
arguments, the last thing listed should be `DOTS'.
|
||||
|
||||
obsolete -- DEFUN_VOID (name)
|
||||
|
||||
Defines a function NAME, which takes no arguments.
|
||||
|
||||
obsolete -- EXFUN (name, (prototype)) -- obsolete.
|
||||
|
||||
Replaced by PARAMS. Do not use; will disappear someday soon.
|
||||
Was used in external function declarations.
|
||||
In ANSI C it is `NAME PROTOTYPE' (so PROTOTYPE should be enclosed in
|
||||
parentheses). In traditional C it is `NAME()'.
|
||||
For a function that takes no arguments, PROTOTYPE should be `(void)'.
|
||||
|
||||
obsolete -- PROTO (type, name, (prototype) -- obsolete.
|
||||
|
||||
This one has also been replaced by PARAMS. Do not use.
|
||||
|
||||
PARAMS ((args))
|
||||
|
||||
We could use the EXFUN macro to handle prototype declarations, but
|
||||
the name is misleading and the result is ugly. So we just define a
|
||||
simple macro to handle the parameter lists, as in:
|
||||
|
||||
static int foo PARAMS ((int, char));
|
||||
|
||||
This produces: `static int foo();' or `static int foo (int, char);'
|
||||
|
||||
EXFUN would have done it like this:
|
||||
|
||||
static int EXFUN (foo, (int, char));
|
||||
|
||||
but the function is not external...and it's hard to visually parse
|
||||
the function name out of the mess. EXFUN should be considered
|
||||
obsolete; new code should be written to use PARAMS.
|
||||
|
||||
DOTS is also obsolete.
|
||||
|
||||
Examples:
|
||||
|
||||
extern int printf PARAMS ((const char *format, ...));
|
||||
*/
|
||||
|
||||
#ifndef _ANSIDECL_H
|
||||
|
||||
#define _ANSIDECL_H 1
|
||||
|
||||
|
||||
/* Every source file includes this file,
|
||||
so they will all get the switch for lint. */
|
||||
/* LINTLIBRARY */
|
||||
|
||||
|
||||
#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
|
||||
/* All known AIX compilers implement these things (but don't always
|
||||
define __STDC__). The RISC/OS MIPS compiler defines these things
|
||||
in SVR4 mode, but does not define __STDC__. */
|
||||
|
||||
#define PTR void *
|
||||
#define PTRCONST void *CONST
|
||||
#define LONG_DOUBLE long double
|
||||
|
||||
#ifndef IN_GCC
|
||||
#define AND ,
|
||||
#define NOARGS void
|
||||
#define VOLATILE volatile
|
||||
#define SIGNED signed
|
||||
#endif /* ! IN_GCC */
|
||||
|
||||
#define PARAMS(paramlist) paramlist
|
||||
#define ANSI_PROTOTYPES 1
|
||||
|
||||
#define VPARAMS(ARGS) ARGS
|
||||
#define VA_START(va_list,var) va_start(va_list,var)
|
||||
|
||||
/* These are obsolete. Do not use. */
|
||||
#ifndef IN_GCC
|
||||
#define CONST const
|
||||
#define DOTS , ...
|
||||
#define PROTO(type, name, arglist) type name arglist
|
||||
#define EXFUN(name, proto) name proto
|
||||
#define DEFUN(name, arglist, args) name(args)
|
||||
#define DEFUN_VOID(name) name(void)
|
||||
#endif /* ! IN_GCC */
|
||||
|
||||
#else /* Not ANSI C. */
|
||||
|
||||
#define PTR char *
|
||||
#define PTRCONST PTR
|
||||
#define LONG_DOUBLE double
|
||||
|
||||
#ifndef IN_GCC
|
||||
#define AND ;
|
||||
#define NOARGS
|
||||
#define VOLATILE
|
||||
#define SIGNED
|
||||
#endif /* !IN_GCC */
|
||||
|
||||
#ifndef const /* some systems define it in header files for non-ansi mode */
|
||||
#define const
|
||||
#endif
|
||||
|
||||
#define PARAMS(paramlist) ()
|
||||
|
||||
#define VPARAMS(ARGS) (va_alist) va_dcl
|
||||
#define VA_START(va_list,var) va_start(va_list)
|
||||
|
||||
/* These are obsolete. Do not use. */
|
||||
#ifndef IN_GCC
|
||||
#define CONST
|
||||
#define DOTS
|
||||
#define PROTO(type, name, arglist) type name ()
|
||||
#define EXFUN(name, proto) name()
|
||||
#define DEFUN(name, arglist, args) name arglist args;
|
||||
#define DEFUN_VOID(name) name()
|
||||
#endif /* ! IN_GCC */
|
||||
|
||||
#endif /* ANSI C. */
|
||||
|
||||
#endif /* ansidecl.h */
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Return the basename of a pathname.
|
||||
This file is in the public domain. */
|
||||
|
||||
/*
|
||||
NAME
|
||||
basename -- return pointer to last component of a pathname
|
||||
|
||||
SYNOPSIS
|
||||
char *basename (const char *name)
|
||||
|
||||
DESCRIPTION
|
||||
Given a pointer to a string containing a typical pathname
|
||||
(/usr/src/cmd/ls/ls.c for example), returns a pointer to the
|
||||
last component of the pathname ("ls.c" in this case).
|
||||
|
||||
BUGS
|
||||
Presumes a UNIX style path with UNIX style separators.
|
||||
*/
|
||||
|
||||
#include "ansidecl.h"
|
||||
#include "libiberty.h"
|
||||
|
||||
char *
|
||||
basename (name)
|
||||
const char *name;
|
||||
{
|
||||
const char *base = name;
|
||||
|
||||
while (*name)
|
||||
{
|
||||
if (*name++ == '/')
|
||||
{
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
return (char *) base;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 __GNUC__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#define _STREAM_COMPAT
|
||||
#include "builtinbuf.h"
|
||||
#include "iostreamP.h"
|
||||
#if !_IO_UNIFIED_JUMPTABLES
|
||||
int builtinbuf::overflow(int ch) { return _IO_OVERFLOW (this, ch); }
|
||||
|
||||
int builtinbuf::underflow() { return _IO_UNDERFLOW (this); }
|
||||
|
||||
streamsize builtinbuf::xsgetn(char* buf, streamsize n)
|
||||
{ return _IO_XSGETN (this, buf, n); }
|
||||
|
||||
streamsize builtinbuf::xsputn(const char* buf, streamsize n)
|
||||
{ return _IO_XSPUTN (this, buf, n); }
|
||||
|
||||
int builtinbuf::doallocate() { return _IO_DOALLOCATE (this); }
|
||||
|
||||
builtinbuf::~builtinbuf() { _IO_FINISH (this); }
|
||||
|
||||
int builtinbuf::sync() { return _IO_SYNC (this); }
|
||||
|
||||
streambuf* builtinbuf::setbuf(char *buf, int n)
|
||||
{ return (streambuf*)_IO_SETBUF (this, buf, n); }
|
||||
|
||||
streampos builtinbuf::seekoff(streamoff off, _seek_dir dir, int mode)
|
||||
{
|
||||
return _IO_SEEKOFF (this, off, dir, mode);
|
||||
}
|
||||
|
||||
streampos builtinbuf::seekpos(streampos pos, int mode)
|
||||
{
|
||||
return _IO_SEEKPOS (this, pos, mode);
|
||||
}
|
||||
|
||||
int builtinbuf::pbackfail(int c)
|
||||
{ return _IO_PBACKFAIL (this, c); }
|
||||
|
||||
streamsize builtinbuf::sys_read(char* buf, streamsize size)
|
||||
{ return _IO_SYSREAD (this, buf, size); }
|
||||
|
||||
streampos builtinbuf::sys_seek(streamoff off, _seek_dir dir)
|
||||
{ return _IO_SYSSEEK (this, off, dir); }
|
||||
|
||||
streamsize builtinbuf::sys_write(const char* buf, streamsize size)
|
||||
{ return _IO_SYSWRITE (this, buf, size); }
|
||||
|
||||
int builtinbuf::sys_stat(void* buf) // Actually, a (struct stat*)
|
||||
{ return _IO_SYSSTAT (this, buf); }
|
||||
|
||||
int builtinbuf::sys_close()
|
||||
{ return _IO_SYSCLOSE (this); }
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
// Instantiation file for the -*- C++ -*- complex number classes.
|
||||
// Copyright (C) 1994 Free Software Foundation
|
||||
|
||||
#ifdef F
|
||||
typedef float f;
|
||||
#endif
|
||||
#ifdef D
|
||||
typedef double f;
|
||||
#endif
|
||||
#ifdef LD
|
||||
typedef long double f;
|
||||
#endif
|
||||
|
||||
#if defined (MAIN) && defined (__GNUG__)
|
||||
#ifdef F
|
||||
#pragma implementation "fcomplex"
|
||||
#endif
|
||||
#ifdef D
|
||||
#pragma implementation "dcomplex"
|
||||
#endif
|
||||
#ifdef LD
|
||||
#pragma implementation "ldcomplex"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define _G_NO_EXTERN_TEMPLATES
|
||||
#endif
|
||||
#include <std/complext.cc>
|
||||
|
||||
typedef complex<f> c;
|
||||
typedef const c& ccr;
|
||||
|
||||
#ifdef MAIN
|
||||
template c& __doapl (c*, ccr);
|
||||
template c& __doaml (c*, ccr);
|
||||
template c& __doami (c*, ccr);
|
||||
template c& __doadv (c*, ccr);
|
||||
#endif
|
||||
|
||||
#ifdef ADDCC
|
||||
template c operator+ (ccr, ccr);
|
||||
#endif
|
||||
#ifdef ADDCF
|
||||
template c operator+ (ccr, f);
|
||||
#endif
|
||||
#ifdef ADDFC
|
||||
template c operator+ (f, ccr);
|
||||
#endif
|
||||
#ifdef SUBCC
|
||||
template c operator- (ccr, ccr);
|
||||
#endif
|
||||
#ifdef SUBCF
|
||||
template c operator- (ccr, f);
|
||||
#endif
|
||||
#ifdef SUBFC
|
||||
template c operator- (f, ccr);
|
||||
#endif
|
||||
#ifdef MULCC
|
||||
template c operator* (ccr, ccr);
|
||||
#endif
|
||||
#ifdef MULCF
|
||||
template c operator* (ccr, f);
|
||||
#endif
|
||||
#ifdef MULFC
|
||||
template c operator* (f, ccr);
|
||||
#endif
|
||||
#ifdef DIVCC
|
||||
template c operator/ (ccr, ccr);
|
||||
#endif
|
||||
#ifdef DIVCF
|
||||
template c operator/ (ccr, f);
|
||||
#endif
|
||||
#ifdef DIVFC
|
||||
template c operator/ (f, ccr);
|
||||
#endif
|
||||
#ifdef PLUS
|
||||
template c operator+ (ccr);
|
||||
#endif
|
||||
#ifdef MINUS
|
||||
template c operator- (ccr);
|
||||
#endif
|
||||
#ifdef EQCC
|
||||
template bool operator== (ccr, ccr);
|
||||
#endif
|
||||
#ifdef EQCF
|
||||
template bool operator== (ccr, f);
|
||||
#endif
|
||||
#ifdef EQFC
|
||||
template bool operator== (f, ccr);
|
||||
#endif
|
||||
#ifdef NECC
|
||||
template bool operator!= (ccr, ccr);
|
||||
#endif
|
||||
#ifdef NECF
|
||||
template bool operator!= (ccr, f);
|
||||
#endif
|
||||
#ifdef NEFC
|
||||
template bool operator!= (f, ccr);
|
||||
#endif
|
||||
#ifdef ABS
|
||||
template f abs (ccr);
|
||||
#endif
|
||||
#ifdef ARG
|
||||
template f arg (ccr);
|
||||
#endif
|
||||
#ifdef POLAR
|
||||
template c polar (f, f);
|
||||
#endif
|
||||
#ifdef CONJ
|
||||
template c conj (ccr);
|
||||
#endif
|
||||
#ifdef NORM
|
||||
template f norm (ccr);
|
||||
#endif
|
||||
#ifdef COS
|
||||
template c cos (ccr);
|
||||
#endif
|
||||
#ifdef COSH
|
||||
template c cosh (ccr);
|
||||
#endif
|
||||
#ifdef EXP
|
||||
template c exp (ccr);
|
||||
#endif
|
||||
#ifdef LOG
|
||||
template c log (ccr);
|
||||
#endif
|
||||
#ifdef POWCC
|
||||
template c pow (ccr, ccr);
|
||||
#endif
|
||||
#ifdef POWCF
|
||||
template c pow (ccr, f);
|
||||
#endif
|
||||
#ifdef POWCI
|
||||
template c pow (ccr, int);
|
||||
#endif
|
||||
#ifdef POWFC
|
||||
template c pow (f, ccr);
|
||||
#endif
|
||||
#ifdef SIN
|
||||
template c sin (ccr);
|
||||
#endif
|
||||
#ifdef SINH
|
||||
template c sinh (ccr);
|
||||
#endif
|
||||
#ifdef SQRT
|
||||
template c sqrt (ccr);
|
||||
#endif
|
||||
#ifdef EXTRACT
|
||||
template istream& operator>> (istream&, complex<f>&);
|
||||
#endif
|
||||
#ifdef INSERT
|
||||
template ostream& operator<< (ostream&, const complex<f>&);
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
// Implementation file for the -*- C++ -*- math functions header.
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "cmath"
|
||||
#endif
|
||||
#include <cmath>
|
||||
@@ -0,0 +1,222 @@
|
||||
/* config.h. Generated automatically by configure. */
|
||||
/* config.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* Define if using alloca.c. */
|
||||
/* #undef C_ALLOCA */
|
||||
|
||||
/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
|
||||
This function is required for alloca.c support on those systems. */
|
||||
/* #undef CRAY_STACKSEG_END */
|
||||
|
||||
/* Define if you have alloca, as a function or macro. */
|
||||
#define HAVE_ALLOCA 1
|
||||
|
||||
/* Define if you have <alloca.h> and it should be used (not on Ultrix). */
|
||||
#define HAVE_ALLOCA_H 1
|
||||
|
||||
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
|
||||
#define HAVE_SYS_WAIT_H 1
|
||||
|
||||
/* Define if you have <vfork.h>. */
|
||||
/* #undef HAVE_VFORK_H */
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
/* #undef pid_t */
|
||||
|
||||
/* Define if you need to in order for stat and other things to work. */
|
||||
/* #undef _POSIX_SOURCE */
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at run-time.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown
|
||||
*/
|
||||
/* #undef STACK_DIRECTION */
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define vfork as fork if vfork does not work. */
|
||||
#define vfork fork
|
||||
|
||||
/* Define if you have the sys_errlist variable. */
|
||||
/* #undef HAVE_SYS_ERRLIST */
|
||||
|
||||
/* Define if you have the sys_nerr variable. */
|
||||
/* #undef HAVE_SYS_NERR */
|
||||
|
||||
/* Define if you have the sys_siglist variable. */
|
||||
#define HAVE_SYS_SIGLIST 1
|
||||
|
||||
/* Define if you have the strerror function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define if you have the asprintf function. */
|
||||
#define HAVE_ASPRINTF 1
|
||||
|
||||
/* Define if you have the atexit function. */
|
||||
#define HAVE_ATEXIT 1
|
||||
|
||||
/* Define if you have the basename function. */
|
||||
/* #undef HAVE_BASENAME */
|
||||
|
||||
/* Define if you have the bcmp function. */
|
||||
#define HAVE_BCMP 1
|
||||
|
||||
/* Define if you have the bcopy function. */
|
||||
#define HAVE_BCOPY 1
|
||||
|
||||
/* Define if you have the bzero function. */
|
||||
#define HAVE_BZERO 1
|
||||
|
||||
/* Define if you have the calloc function. */
|
||||
#define HAVE_CALLOC 1
|
||||
|
||||
/* Define if you have the clock function. */
|
||||
#define HAVE_CLOCK 1
|
||||
|
||||
/* Define if you have the getcwd function. */
|
||||
#define HAVE_GETCWD 1
|
||||
|
||||
/* Define if you have the getpagesize function. */
|
||||
/* #undef HAVE_GETPAGESIZE */
|
||||
|
||||
/* Define if you have the getrusage function. */
|
||||
#define HAVE_GETRUSAGE 1
|
||||
|
||||
/* Define if you have the gettimeofday function. */
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
|
||||
/* Define if you have the index function. */
|
||||
#define HAVE_INDEX 1
|
||||
|
||||
/* Define if you have the insque function. */
|
||||
/* #undef HAVE_INSQUE */
|
||||
|
||||
/* Define if you have the memchr function. */
|
||||
#define HAVE_MEMCHR 1
|
||||
|
||||
/* Define if you have the memcmp function. */
|
||||
#define HAVE_MEMCMP 1
|
||||
|
||||
/* Define if you have the memcpy function. */
|
||||
#define HAVE_MEMCPY 1
|
||||
|
||||
/* Define if you have the memmove function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define if you have the memset function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define if you have the mkstemps function. */
|
||||
/* #undef HAVE_MKSTEMPS */
|
||||
|
||||
/* Define if you have the on_exit function. */
|
||||
/* #undef HAVE_ON_EXIT */
|
||||
|
||||
/* Define if you have the psignal function. */
|
||||
/* #undef HAVE_PSIGNAL */
|
||||
|
||||
/* Define if you have the putenv function. */
|
||||
#define HAVE_PUTENV 1
|
||||
|
||||
/* Define if you have the random function. */
|
||||
#define HAVE_RANDOM 1
|
||||
|
||||
/* Define if you have the rename function. */
|
||||
#define HAVE_RENAME 1
|
||||
|
||||
/* Define if you have the rindex function. */
|
||||
#define HAVE_RINDEX 1
|
||||
|
||||
/* Define if you have the sbrk function. */
|
||||
#define HAVE_SBRK 1
|
||||
|
||||
/* Define if you have the setenv function. */
|
||||
/* #undef HAVE_SETENV */
|
||||
|
||||
/* Define if you have the sigsetmask function. */
|
||||
/* #undef HAVE_SIGSETMASK */
|
||||
|
||||
/* Define if you have the strcasecmp function. */
|
||||
#define HAVE_STRCASECMP 1
|
||||
|
||||
/* Define if you have the strchr function. */
|
||||
#define HAVE_STRCHR 1
|
||||
|
||||
/* Define if you have the strdup function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define if you have the strerror function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define if you have the strncasecmp function. */
|
||||
#define HAVE_STRNCASECMP 1
|
||||
|
||||
/* Define if you have the strrchr function. */
|
||||
#define HAVE_STRRCHR 1
|
||||
|
||||
/* Define if you have the strsignal function. */
|
||||
#define HAVE_STRSIGNAL 1
|
||||
|
||||
/* Define if you have the strstr function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define if you have the strtod function. */
|
||||
#define HAVE_STRTOD 1
|
||||
|
||||
/* Define if you have the strtol function. */
|
||||
#define HAVE_STRTOL 1
|
||||
|
||||
/* Define if you have the strtoul function. */
|
||||
#define HAVE_STRTOUL 1
|
||||
|
||||
/* Define if you have the sysconf function. */
|
||||
#define HAVE_SYSCONF 1
|
||||
|
||||
/* Define if you have the times function. */
|
||||
#define HAVE_TIMES 1
|
||||
|
||||
/* Define if you have the tmpnam function. */
|
||||
#define HAVE_TMPNAM 1
|
||||
|
||||
/* Define if you have the vasprintf function. */
|
||||
#define HAVE_VASPRINTF 1
|
||||
|
||||
/* Define if you have the vfprintf function. */
|
||||
#define HAVE_VFPRINTF 1
|
||||
|
||||
/* Define if you have the vprintf function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define if you have the vsprintf function. */
|
||||
#define HAVE_VSPRINTF 1
|
||||
|
||||
/* Define if you have the waitpid function. */
|
||||
#define HAVE_WAITPID 1
|
||||
|
||||
/* Define if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define if you have the <sys/file.h> header file. */
|
||||
#define HAVE_SYS_FILE_H 1
|
||||
|
||||
/* Define if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define if you have the <sys/resource.h> header file. */
|
||||
#define HAVE_SYS_RESOURCE_H 1
|
||||
|
||||
/* Define if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
@@ -0,0 +1,7 @@
|
||||
// Implementation file for the -*- C++ -*- standard library header.
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "cstdlib"
|
||||
#endif
|
||||
#include <cstdlib>
|
||||
@@ -0,0 +1,7 @@
|
||||
// Implementation file for the -*- C++ -*- null-terminated string header.
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "cstring"
|
||||
#endif
|
||||
#include <cstring>
|
||||
@@ -0,0 +1,717 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include "libioP.h"
|
||||
#include "editbuf.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* NOTE: Some of the code here is taken from GNU emacs */
|
||||
/* Hence this file falls under the GNU License! */
|
||||
|
||||
// Invariants for edit_streambuf:
|
||||
// An edit_streambuf is associated with a specific edit_string,
|
||||
// which again is a sub-string of a specific edit_buffer.
|
||||
// An edit_streambuf is always in either get mode or put mode, never both.
|
||||
// In get mode, gptr() is the current position,
|
||||
// and pbase(), pptr(), and epptr() are all NULL.
|
||||
// In put mode, pptr() is the current position,
|
||||
// and eback(), gptr(), and egptr() are all NULL.
|
||||
// Any edit_streambuf that is actively doing insertion (as opposed to
|
||||
// replacing) // must have its pptr() pointing to the start of the gap.
|
||||
// Only one edit_streambuf can be actively inserting into a specific
|
||||
// edit_buffer; the edit_buffer's _writer field points to that edit_streambuf.
|
||||
// That edit_streambuf "owns" the gap, and the actual start of the
|
||||
// gap is the pptr() of the edit_streambuf; the edit_buffer::_gap_start pointer
|
||||
// will only be updated on an edit_streambuf::overflow().
|
||||
|
||||
int edit_streambuf::truncate()
|
||||
{
|
||||
str->buffer->delete_range(str->buffer->tell((buf_char*)pptr()),
|
||||
str->buffer->tell(str->end));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef OLD_STDIO
|
||||
inline void disconnect_gap_from_file(edit_buffer* buffer, FILE* fp)
|
||||
{
|
||||
if (buffer->gap_start_ptr != &fp->__bufp)
|
||||
return;
|
||||
buffer->gap_start_normal = fp->__bufp;
|
||||
buffer->gap_start_ptr = &buffer->gap_start_normal;
|
||||
}
|
||||
#endif
|
||||
|
||||
void edit_streambuf::flush_to_buffer(edit_buffer* buffer)
|
||||
{
|
||||
if (pptr() > buffer->_gap_start && pptr() < buffer->gap_end())
|
||||
buffer->_gap_start = pptr();
|
||||
}
|
||||
|
||||
void edit_streambuf::disconnect_gap_from_file(edit_buffer* buffer)
|
||||
{
|
||||
if (buffer->_writer != this) return;
|
||||
flush_to_buffer(buffer);
|
||||
setp(pptr(),pptr());
|
||||
buffer->_writer = NULL;
|
||||
}
|
||||
|
||||
buf_index edit_buffer::tell(buf_char *ptr)
|
||||
{
|
||||
if (ptr <= gap_start())
|
||||
return ptr - data;
|
||||
else
|
||||
return ptr - gap_end() + size1();
|
||||
}
|
||||
|
||||
#if 0
|
||||
buf_index buf_cookie::tell()
|
||||
{
|
||||
return str->buffer->tell(file->__bufp);
|
||||
}
|
||||
#endif
|
||||
|
||||
buf_index edit_buffer::tell(edit_mark*mark)
|
||||
{
|
||||
return tell(data + mark->index_in_buffer(this));
|
||||
}
|
||||
|
||||
// adjust the position of the gap
|
||||
|
||||
void edit_buffer::move_gap(buf_offset pos)
|
||||
{
|
||||
if (pos < size1())
|
||||
gap_left (pos);
|
||||
else if (pos > size1())
|
||||
gap_right (pos);
|
||||
}
|
||||
|
||||
void edit_buffer::gap_left (int pos)
|
||||
{
|
||||
register buf_char *to, *from;
|
||||
register int i;
|
||||
int new_s1;
|
||||
|
||||
i = size1();
|
||||
from = gap_start();
|
||||
to = from + gap_size();
|
||||
new_s1 = size1();
|
||||
|
||||
/* Now copy the characters. To move the gap down,
|
||||
copy characters up. */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* I gets number of characters left to copy. */
|
||||
i = new_s1 - pos;
|
||||
if (i == 0)
|
||||
break;
|
||||
#if 0
|
||||
/* If a quit is requested, stop copying now.
|
||||
Change POS to be where we have actually moved the gap to. */
|
||||
if (QUITP)
|
||||
{
|
||||
pos = new_s1;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* Move at most 32000 chars before checking again for a quit. */
|
||||
if (i > 32000)
|
||||
i = 32000;
|
||||
new_s1 -= i;
|
||||
while (--i >= 0)
|
||||
*--to = *--from;
|
||||
}
|
||||
|
||||
/* Adjust markers, and buffer data structure, to put the gap at POS.
|
||||
POS is where the loop above stopped, which may be what was specified
|
||||
or may be where a quit was detected. */
|
||||
adjust_markers (pos << 1, size1() << 1, gap_size(), data);
|
||||
#ifndef OLD_STDIO
|
||||
_gap_start = data + pos;
|
||||
#else
|
||||
if (gap_start_ptr == &gap_start_normal)
|
||||
gap_start_normal = data + pos;
|
||||
#endif
|
||||
__gap_end_pos = to - data;
|
||||
/* QUIT;*/
|
||||
}
|
||||
|
||||
void edit_buffer::gap_right (int pos)
|
||||
{
|
||||
register buf_char *to, *from;
|
||||
register int i;
|
||||
int new_s1;
|
||||
|
||||
i = size1();
|
||||
to = gap_start();
|
||||
from = i + gap_end();
|
||||
new_s1 = i;
|
||||
|
||||
/* Now copy the characters. To move the gap up,
|
||||
copy characters down. */
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* I gets number of characters left to copy. */
|
||||
i = pos - new_s1;
|
||||
if (i == 0)
|
||||
break;
|
||||
#if 0
|
||||
/* If a quit is requested, stop copying now.
|
||||
Change POS to be where we have actually moved the gap to. */
|
||||
if (QUITP)
|
||||
{
|
||||
pos = new_s1;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* Move at most 32000 chars before checking again for a quit. */
|
||||
if (i > 32000)
|
||||
i = 32000;
|
||||
new_s1 += i;
|
||||
while (--i >= 0)
|
||||
*to++ = *from++;
|
||||
}
|
||||
|
||||
adjust_markers ((size1() + gap_size()) << 1, (pos + gap_size()) << 1,
|
||||
- gap_size(), data);
|
||||
#ifndef OLD_STDIO
|
||||
_gap_start = data+pos;
|
||||
#else
|
||||
if (gap_start_ptr == &gap_start_normal)
|
||||
gap_start_normal = data + pos;
|
||||
#endif
|
||||
__gap_end_pos = from - data;
|
||||
/* QUIT;*/
|
||||
}
|
||||
|
||||
/* make sure that the gap in the current buffer is at least k
|
||||
characters wide */
|
||||
|
||||
void edit_buffer::make_gap(buf_offset k)
|
||||
{
|
||||
register buf_char *p1, *p2, *lim;
|
||||
buf_char *old_data = data;
|
||||
int s1 = size1();
|
||||
|
||||
if (gap_size() >= k)
|
||||
return;
|
||||
|
||||
/* Get more than just enough */
|
||||
if (buf_size > 1000) k += 2000;
|
||||
else k += /*200;*/ 20; // for testing!
|
||||
|
||||
p1 = (buf_char *) realloc (data, s1 + size2() + k);
|
||||
if (p1 == 0)
|
||||
abort(); /*memory_full ();*/
|
||||
|
||||
k -= gap_size(); /* Amount of increase. */
|
||||
|
||||
/* Record new location of text */
|
||||
data = p1;
|
||||
|
||||
/* Transfer the new free space from the end to the gap
|
||||
by shifting the second segment upward */
|
||||
p2 = data + buf_size;
|
||||
p1 = p2 + k;
|
||||
lim = p2 - size2();
|
||||
while (lim < p2)
|
||||
*--p1 = *--p2;
|
||||
|
||||
/* Finish updating text location data */
|
||||
__gap_end_pos += k;
|
||||
|
||||
#ifndef OLD_STDIO
|
||||
_gap_start = data + s1;
|
||||
#else
|
||||
if (gap_start_ptr == &gap_start_normal)
|
||||
gap_start_normal = data + s1;
|
||||
#endif
|
||||
|
||||
/* adjust markers */
|
||||
adjust_markers (s1 << 1, (buf_size << 1) + 1, k, old_data);
|
||||
buf_size += k;
|
||||
}
|
||||
|
||||
/* Add `amount' to the position of every marker in the current buffer
|
||||
whose current position is between `from' (exclusive) and `to' (inclusive).
|
||||
Also, any markers past the outside of that interval, in the direction
|
||||
of adjustment, are first moved back to the near end of the interval
|
||||
and then adjusted by `amount'. */
|
||||
|
||||
void edit_buffer::adjust_markers(register mark_pointer low,
|
||||
register mark_pointer high,
|
||||
int amount, buf_char *old_data)
|
||||
{
|
||||
register struct edit_mark *m;
|
||||
register mark_pointer mpos;
|
||||
/* convert to mark_pointer */
|
||||
amount <<= 1;
|
||||
|
||||
if (_writer)
|
||||
_writer->disconnect_gap_from_file(this);
|
||||
|
||||
for (m = mark_list(); m != NULL; m = m->chain)
|
||||
{
|
||||
mpos = m->_pos;
|
||||
if (amount > 0)
|
||||
{
|
||||
if (mpos > high && mpos < high + amount)
|
||||
mpos = high + amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mpos > low + amount && mpos <= low)
|
||||
mpos = low + amount;
|
||||
}
|
||||
if (mpos > low && mpos <= high)
|
||||
mpos += amount;
|
||||
m->_pos = mpos;
|
||||
}
|
||||
|
||||
// Now adjust files
|
||||
edit_streambuf *file;
|
||||
|
||||
for (file = files; file != NULL; file = file->next) {
|
||||
mpos = file->current() - old_data;
|
||||
if (amount > 0)
|
||||
{
|
||||
if (mpos > high && mpos < high + amount)
|
||||
mpos = high + amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mpos > low + amount && mpos <= low)
|
||||
mpos = low + amount;
|
||||
}
|
||||
if (mpos > low && mpos <= high)
|
||||
mpos += amount;
|
||||
char* new_pos = data + mpos;
|
||||
file->set_current(new_pos, file->is_reading());
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
stdio_
|
||||
__off == index at start of buffer (need only be valid after seek ? )
|
||||
__buf ==
|
||||
|
||||
if read/read_delete/overwrite mode:
|
||||
__endp <= min(*gap_start_ptr, edit_string->end->ptr(buffer))
|
||||
|
||||
if inserting:
|
||||
must have *gap_start_ptr == __bufp && *gap_start_ptr+gap == __endp
|
||||
file->edit_string->end->ptr(buffer) == *gap_start_ptr+end
|
||||
if write_mode:
|
||||
if before gap
|
||||
#endif
|
||||
|
||||
int edit_streambuf::underflow()
|
||||
{
|
||||
if (!(_mode & ios::in))
|
||||
return EOF;
|
||||
struct edit_buffer *buffer = str->buffer;
|
||||
if (!is_reading()) { // Must switch from put to get mode.
|
||||
disconnect_gap_from_file(buffer);
|
||||
set_current(pptr(), 1);
|
||||
}
|
||||
buf_char *str_end = str->end->ptr(buffer);
|
||||
retry:
|
||||
if (gptr() < egptr()) {
|
||||
return *gptr();
|
||||
}
|
||||
if ((buf_char*)gptr() == str_end)
|
||||
return EOF;
|
||||
if (str_end <= buffer->gap_start()) {
|
||||
setg(eback(), gptr(), str_end);
|
||||
goto retry;
|
||||
}
|
||||
if (gptr() < buffer->gap_start()) {
|
||||
setg(eback(), gptr(), buffer->gap_start());
|
||||
goto retry;
|
||||
}
|
||||
if (gptr() == buffer->gap_start()) {
|
||||
disconnect_gap_from_file(buffer);
|
||||
// fp->__offset += fp->__bufp - fp->__buffer;
|
||||
setg(buffer->gap_end(), buffer->gap_end(), str_end);
|
||||
}
|
||||
else
|
||||
setg(eback(), gptr(), str_end);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
int edit_streambuf::overflow(int ch)
|
||||
{
|
||||
if (_mode == ios::in)
|
||||
return EOF;
|
||||
struct edit_buffer *buffer = str->buffer;
|
||||
flush_to_buffer(buffer);
|
||||
if (ch == EOF)
|
||||
return 0;
|
||||
if (is_reading()) { // Must switch from get to put mode.
|
||||
set_current(gptr(), 0);
|
||||
}
|
||||
buf_char *str_end = str->end->ptr(buffer);
|
||||
retry:
|
||||
if (pptr() < epptr()) {
|
||||
*pptr() = ch;
|
||||
pbump(1);
|
||||
return (unsigned char)ch;
|
||||
}
|
||||
if ((buf_char*)pptr() == str_end || inserting()) {
|
||||
/* insert instead */
|
||||
if (buffer->_writer)
|
||||
buffer->_writer->flush_to_buffer(); // Redundant?
|
||||
buffer->_writer = NULL;
|
||||
if (pptr() >= buffer->gap_end())
|
||||
buffer->move_gap(pptr() - buffer->gap_size());
|
||||
else
|
||||
buffer->move_gap(pptr());
|
||||
buffer->make_gap(1);
|
||||
setp(buffer->gap_start(), buffer->gap_end());
|
||||
buffer->_writer = this;
|
||||
*pptr() = ch;
|
||||
pbump(1);
|
||||
return (unsigned char)ch;
|
||||
}
|
||||
if (str_end <= buffer->gap_start()) {
|
||||
// Entire string is left of gap.
|
||||
setp(pptr(), str_end);
|
||||
}
|
||||
else if (pptr() < buffer->gap_start()) {
|
||||
// Current pos is left of gap.
|
||||
setp(pptr(), buffer->gap_start());
|
||||
goto retry;
|
||||
}
|
||||
else if (pptr() == buffer->gap_start()) {
|
||||
// Current pos is at start of gap; move to end of gap.
|
||||
// disconnect_gap_from_file(buffer);
|
||||
setp(buffer->gap_end(), str_end);
|
||||
// __offset += __bufp - __buffer;
|
||||
}
|
||||
else {
|
||||
// Otherwise, current pos is right of gap.
|
||||
setp(pptr(), str_end);
|
||||
}
|
||||
goto retry;
|
||||
}
|
||||
|
||||
void edit_streambuf::set_current(char *new_pos, int reading)
|
||||
{
|
||||
if (reading) {
|
||||
setg(new_pos, new_pos, new_pos);
|
||||
setp(NULL, NULL);
|
||||
}
|
||||
else {
|
||||
setg(NULL, NULL, NULL);
|
||||
setp(new_pos, new_pos);
|
||||
}
|
||||
}
|
||||
|
||||
// Called by fseek(fp, pos, whence) if fp is bound to a edit_buffer.
|
||||
|
||||
streampos edit_streambuf::seekoff(streamoff offset, _seek_dir dir,
|
||||
int /* =ios::in|ios::out*/)
|
||||
{
|
||||
struct edit_buffer *buffer = str->buffer;
|
||||
disconnect_gap_from_file(buffer);
|
||||
buf_index cur_pos = buffer->tell((buf_char*)current());;
|
||||
buf_index start_pos = buffer->tell(str->start);
|
||||
buf_index end_pos = buffer->tell(str->end);
|
||||
switch (dir) {
|
||||
case ios::beg:
|
||||
offset += start_pos;
|
||||
break;
|
||||
case ios::cur:
|
||||
offset += cur_pos;
|
||||
break;
|
||||
case ios::end:
|
||||
offset += end_pos;
|
||||
break;
|
||||
}
|
||||
if (offset < start_pos || offset > end_pos)
|
||||
return EOF;
|
||||
buf_char *new_pos = buffer->data + offset;
|
||||
buf_char* gap_start = buffer->gap_start();
|
||||
if (new_pos > gap_start) {
|
||||
buf_char* gap_end = buffer->gap_end();
|
||||
new_pos += gap_end - gap_start;
|
||||
if (new_pos >= buffer->data + buffer->buf_size) abort(); // Paranoia.
|
||||
}
|
||||
set_current(new_pos, is_reading());
|
||||
return EOF;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int buf_seek(void *arg_cookie, fpos_t * pos, int whence)
|
||||
{
|
||||
struct buf_cookie *cookie = arg_cookie;
|
||||
FILE *file = cookie->file;
|
||||
struct edit_buffer *buffer = cookie->str->buffer;
|
||||
buf_char *str_start = cookie->str->start->ptr(buffer);
|
||||
disconnect_gap_from_file(buffer, cookie->file);
|
||||
fpos_t cur_pos, new_pos;
|
||||
if (file->__bufp <= *buffer->gap_start_ptr
|
||||
|| str_start >= buffer->__gap_end)
|
||||
cur_pos = str_start - file->__bufp;
|
||||
else
|
||||
cur_pos =
|
||||
(*buffer->gap_start_ptr - str_start) + (file->__bufp - __gap_end);
|
||||
end_pos = ...;
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
new_pos = *pos;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
new_pos = cur_pos + *pos;
|
||||
break;
|
||||
case SEEK_END:
|
||||
new_pos = end_pos + *pos;
|
||||
break;
|
||||
}
|
||||
if (new_pos > end_pos) {
|
||||
seek to end_pos;
|
||||
insert_nulls(new_pos - end_pos);
|
||||
return;
|
||||
}
|
||||
if (str_start + new_pos <= *gap_start_ptr &* *gap_start_ptr < end) {
|
||||
__buffer = str_start;
|
||||
__off = 0;
|
||||
__bufp = str_start + new_pos;
|
||||
file->__get_limit =
|
||||
*buffer->gap_start_ptr; /* what if gap_start_ptr == &bufp ??? */
|
||||
} else if () {
|
||||
|
||||
}
|
||||
*pos = new_pos;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Delete characters from `from' up to (but not incl) `to' */
|
||||
|
||||
void edit_buffer::delete_range (buf_index from, buf_index to)
|
||||
{
|
||||
register int numdel;
|
||||
|
||||
if ((numdel = to - from) <= 0)
|
||||
return;
|
||||
|
||||
/* Make sure the gap is somewhere in or next to what we are deleting */
|
||||
if (from > size1())
|
||||
gap_right (from);
|
||||
if (to < size1())
|
||||
gap_left (to);
|
||||
|
||||
/* Relocate all markers pointing into the new, larger gap
|
||||
to point at the end of the text before the gap. */
|
||||
adjust_markers ((to + gap_size()) << 1, (to + gap_size()) << 1,
|
||||
- numdel - gap_size(), data);
|
||||
|
||||
__gap_end_pos = to + gap_size();
|
||||
_gap_start = data + from;
|
||||
}
|
||||
|
||||
void edit_buffer::delete_range(struct edit_mark *start, struct edit_mark *end)
|
||||
{
|
||||
delete_range(tell(start), tell(end));
|
||||
}
|
||||
|
||||
void buf_delete_chars(struct edit_buffer *, struct edit_mark *, size_t)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
edit_streambuf::edit_streambuf(edit_string* bstr, int mode)
|
||||
{
|
||||
_mode = mode;
|
||||
str = bstr;
|
||||
edit_buffer* buffer = bstr->buffer;
|
||||
next = buffer->files;
|
||||
buffer->files = this;
|
||||
char* buf_ptr = bstr->start->ptr(buffer);
|
||||
_inserting = 0;
|
||||
// setb(buf_ptr, buf_ptr, 0);
|
||||
set_current(buf_ptr, !(mode & ios::out+ios::trunc+ios::app));
|
||||
if (_mode & ios::trunc)
|
||||
truncate();
|
||||
if (_mode & ios::ate)
|
||||
seekoff(0, ios::end);
|
||||
}
|
||||
|
||||
// Called by fclose(fp) if fp is bound to a edit_buffer.
|
||||
|
||||
#if 0
|
||||
static int buf_close(void *arg)
|
||||
{
|
||||
register struct buf_cookie *cookie = arg;
|
||||
struct edit_buffer *buffer = cookie->str->buffer;
|
||||
struct buf_cookie **ptr;
|
||||
for (ptr = &buffer->files; *ptr != cookie; ptr = &(*ptr)->next) ;
|
||||
*ptr = cookie->next;
|
||||
disconnect_gap_from_file(buffer, cookie->file);
|
||||
free (cookie);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
edit_streambuf::~edit_streambuf()
|
||||
{
|
||||
if (_mode == ios::out)
|
||||
truncate();
|
||||
// Unlink this from list of files associated with bstr->buffer.
|
||||
edit_streambuf **ptr = &str->buffer->files;
|
||||
for (; *ptr != this; ptr = &(*ptr)->next) { }
|
||||
*ptr = next;
|
||||
|
||||
disconnect_gap_from_file(str->buffer);
|
||||
}
|
||||
|
||||
edit_buffer::edit_buffer()
|
||||
{
|
||||
buf_size = /*200;*/ 15; /* for testing! */
|
||||
data = (buf_char*)malloc(buf_size);
|
||||
files = NULL;
|
||||
#ifndef OLD_STDIO
|
||||
_gap_start = data;
|
||||
_writer = NULL;
|
||||
#else
|
||||
gap_start_normal = data;
|
||||
gap_start_ptr = &gap_start_normal;
|
||||
#endif
|
||||
__gap_end_pos = buf_size;
|
||||
start_mark.chain = &end_mark;
|
||||
start_mark._pos = 0;
|
||||
end_mark.chain = NULL;
|
||||
end_mark._pos = 2 * buf_size + 1;
|
||||
}
|
||||
|
||||
// Allocate a new mark, which is adjusted by 'delta' bytes from 'this'.
|
||||
// Restrict new mark to lie within 'str'.
|
||||
|
||||
edit_mark::edit_mark(struct edit_string *str, long delta)
|
||||
{
|
||||
struct edit_buffer *buf = str->buffer;
|
||||
chain = buf->start_mark.chain;
|
||||
buf->start_mark.chain = this;
|
||||
mark_pointer size1 = buf->size1() << 1;
|
||||
int gap_size = buf->gap_size() << 1;
|
||||
delta <<= 1;
|
||||
|
||||
// check if new and old marks are opposite sides of gap
|
||||
if (_pos <= size1 && _pos + delta > size1)
|
||||
delta += gap_size;
|
||||
else if (_pos >= size1 + gap_size && _pos + delta < size1 + gap_size)
|
||||
delta -= gap_size;
|
||||
|
||||
_pos = _pos + delta;
|
||||
if (_pos < str->start->_pos & ~1)
|
||||
_pos = (str->start->_pos & ~ 1) + (_pos & 1);
|
||||
else if (_pos >= str->end->_pos)
|
||||
_pos = (str->end->_pos & ~ 1) + (_pos & 1);
|
||||
}
|
||||
|
||||
// A (slow) way to find the buffer a mark belongs to.
|
||||
|
||||
edit_buffer * edit_mark::buffer()
|
||||
{
|
||||
struct edit_mark *mark;
|
||||
for (mark = this; mark->chain != NULL; mark = mark->chain) ;
|
||||
// Assume that the last mark on the chain is the end_mark.
|
||||
return (edit_buffer *)((char*)mark - offsetof(edit_buffer, end_mark));
|
||||
}
|
||||
|
||||
edit_mark::~edit_mark()
|
||||
{
|
||||
// Must unlink mark from chain of owning buffer
|
||||
struct edit_buffer *buf = buffer();
|
||||
if (this == &buf->start_mark || this == &buf->end_mark) abort();
|
||||
edit_mark **ptr;
|
||||
for (ptr = &buf->start_mark.chain; *ptr != this; ptr = &(*ptr)->chain) ;
|
||||
*ptr = this->chain;
|
||||
}
|
||||
|
||||
int edit_string::length() const
|
||||
{
|
||||
ptrdiff_t delta = end->ptr(buffer) - start->ptr(buffer);
|
||||
if (end->ptr(buffer) <= buffer->gap_start() ||
|
||||
start->ptr(buffer) >= buffer->gap_end())
|
||||
return delta;
|
||||
return delta - buffer->gap_size();
|
||||
}
|
||||
|
||||
buf_char * edit_string::copy_bytes(int *lenp) const
|
||||
{
|
||||
char *new_str;
|
||||
int len1, len2;
|
||||
buf_char *start1, *start2;
|
||||
start1 = start->ptr(buffer);
|
||||
if (end->ptr(buffer) <= buffer->gap_start()
|
||||
|| start->ptr(buffer) >= buffer->gap_end()) {
|
||||
len1 = end->ptr(buffer) - start1;
|
||||
len2 = 0;
|
||||
start2 = NULL; // To avoid a warning from g++.
|
||||
}
|
||||
else {
|
||||
len1 = buffer->gap_start() - start1;
|
||||
start2 = buffer->gap_end();
|
||||
len2 = end->ptr(buffer) - start2;
|
||||
}
|
||||
new_str = (char*)malloc(len1 + len2 + 1);
|
||||
memcpy(new_str, start1, len1);
|
||||
if (len2 > 0) memcpy(new_str + len1, start2, len2);
|
||||
new_str[len1+len2] = '\0';
|
||||
*lenp = len1+len2;
|
||||
return new_str;
|
||||
}
|
||||
|
||||
// Replace the buf_chars in 'this' with ones from 'src'.
|
||||
// Equivalent to deleting this, then inserting src, except tries
|
||||
// to leave marks in place: Marks whose offset from the start
|
||||
// of 'this' is less than 'src->length()' will still have the
|
||||
// same offset in 'this' when done.
|
||||
|
||||
void edit_string::assign(struct edit_string *src)
|
||||
{
|
||||
edit_streambuf dst_file(this, ios::out);
|
||||
if (buffer == src->buffer /*&& ???*/) { /* overly conservative */
|
||||
int src_len;
|
||||
buf_char *new_str;
|
||||
new_str = src->copy_bytes(&src_len);
|
||||
dst_file.sputn(new_str, src_len);
|
||||
free (new_str);
|
||||
} else {
|
||||
edit_streambuf src_file(src, ios::in);
|
||||
for ( ; ; ) {
|
||||
int ch = src_file.sbumpc();
|
||||
if (ch == EOF) break;
|
||||
dst_file.sputc(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993, 1995, 1999 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#include "iostreamP.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "builtinbuf.h"
|
||||
|
||||
void filebuf::init()
|
||||
{
|
||||
_IO_file_init(reinterpret_cast<_IO_FILE_plus*>(this));
|
||||
}
|
||||
|
||||
filebuf::filebuf()
|
||||
{
|
||||
_IO_file_init(reinterpret_cast<_IO_FILE_plus*>(this));
|
||||
}
|
||||
|
||||
#if !_IO_UNIFIED_JUMPTABLES
|
||||
/* This is like "new filebuf()", but it uses the _IO_file_jump jumptable,
|
||||
for eficiency. */
|
||||
|
||||
filebuf* filebuf::__new()
|
||||
{
|
||||
filebuf *fb = new filebuf;
|
||||
_IO_JUMPS(fb) = &_IO_file_jumps;
|
||||
fb->_vtable() = builtinbuf_vtable;
|
||||
return fb;
|
||||
}
|
||||
#endif
|
||||
|
||||
filebuf::filebuf(int fd)
|
||||
{
|
||||
_IO_file_init(reinterpret_cast<_IO_FILE_plus*>(this));
|
||||
_IO_file_attach(this, fd);
|
||||
}
|
||||
|
||||
filebuf::filebuf(int fd, char* p, int len)
|
||||
{
|
||||
_IO_file_init(reinterpret_cast<_IO_FILE_plus*>(this));
|
||||
_IO_file_attach(this, fd);
|
||||
setbuf(p, len);
|
||||
}
|
||||
|
||||
filebuf::~filebuf()
|
||||
{
|
||||
if (_IO_file_is_open(this))
|
||||
{
|
||||
_IO_do_flush (this);
|
||||
if (!(xflags() & _IO_DELETE_DONT_CLOSE))
|
||||
_IO_SYSCLOSE (this);
|
||||
}
|
||||
}
|
||||
|
||||
filebuf* filebuf::open(const char *filename, ios::openmode mode, int prot)
|
||||
{
|
||||
if (_IO_file_is_open (this))
|
||||
return NULL;
|
||||
int posix_mode;
|
||||
int read_write;
|
||||
if (mode & ios::app)
|
||||
mode |= ios::out;
|
||||
if ((mode & (ios::in|ios::out)) == (ios::in|ios::out)) {
|
||||
posix_mode = O_RDWR;
|
||||
read_write = 0;
|
||||
}
|
||||
else if (mode & ios::out)
|
||||
posix_mode = O_WRONLY, read_write = _IO_NO_READS;
|
||||
else if (mode & (int)ios::in)
|
||||
posix_mode = O_RDONLY, read_write = _IO_NO_WRITES;
|
||||
else
|
||||
posix_mode = 0, read_write = _IO_NO_READS+_IO_NO_WRITES;
|
||||
if (mode & ios::binary)
|
||||
{
|
||||
mode &= ~ios::binary;
|
||||
#ifdef O_BINARY
|
||||
/* This is a (mis-)feature of DOS/Windows C libraries. */
|
||||
posix_mode |= O_BINARY;
|
||||
#endif
|
||||
}
|
||||
if ((mode & (int)ios::trunc) || mode == (int)ios::out)
|
||||
posix_mode |= O_TRUNC;
|
||||
if (mode & ios::app)
|
||||
posix_mode |= O_APPEND, read_write |= _IO_IS_APPENDING;
|
||||
if (!(mode & (int)ios::nocreate) && mode != ios::in)
|
||||
posix_mode |= O_CREAT;
|
||||
if (mode & (int)ios::noreplace)
|
||||
posix_mode |= O_EXCL;
|
||||
#if _G_HAVE_IO_FILE_OPEN
|
||||
if (!_IO_file_open (this, filename, posix_mode, prot,
|
||||
read_write, 0))
|
||||
return NULL;
|
||||
if (mode & ios::ate) {
|
||||
if (pubseekoff(0, ios::end) == EOF) {
|
||||
_IO_un_link (reinterpret_cast<_IO_FILE_plus*>(this));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
#else
|
||||
int fd = ::open(filename, posix_mode, prot);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
_fileno = fd;
|
||||
xsetflags(read_write, _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
|
||||
if (mode & ios::ate) {
|
||||
if (pubseekoff(0, ios::end) == EOF)
|
||||
return NULL;
|
||||
}
|
||||
_IO_link_in(this);
|
||||
return this;
|
||||
#endif
|
||||
}
|
||||
|
||||
filebuf* filebuf::open(const char *filename, const char *mode)
|
||||
{
|
||||
#if _G_IO_IO_FILE_VERSION == 0x20001
|
||||
return (filebuf*)_IO_file_fopen(this, filename, mode, 0);
|
||||
#else
|
||||
return (filebuf*)_IO_file_fopen(this, filename, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
filebuf* filebuf::attach(int fd)
|
||||
{
|
||||
return (filebuf*)_IO_file_attach(this, fd);
|
||||
}
|
||||
|
||||
streambuf* filebuf::setbuf(char* p, int len)
|
||||
{
|
||||
return (streambuf*)_IO_file_setbuf (this, p, len);
|
||||
}
|
||||
|
||||
int filebuf::doallocate() { return _IO_file_doallocate(this); }
|
||||
|
||||
int filebuf::overflow(int c)
|
||||
{
|
||||
return _IO_file_overflow(this, c);
|
||||
}
|
||||
|
||||
int filebuf::underflow()
|
||||
{
|
||||
return _IO_file_underflow(this);
|
||||
}
|
||||
|
||||
int filebuf::sync()
|
||||
{
|
||||
return _IO_file_sync(this);
|
||||
}
|
||||
|
||||
streampos filebuf::seekoff(streamoff offset, _seek_dir dir, int mode)
|
||||
{
|
||||
return _IO_file_seekoff (this, offset, dir, mode);
|
||||
}
|
||||
|
||||
filebuf* filebuf::close()
|
||||
{
|
||||
return (_IO_file_close_it(this) ? (filebuf*)NULL : this);
|
||||
}
|
||||
|
||||
streamsize filebuf::sys_read(char* buf, streamsize size)
|
||||
{
|
||||
return _IO_file_read(this, buf, size);
|
||||
}
|
||||
|
||||
streampos filebuf::sys_seek(streamoff offset, _seek_dir dir)
|
||||
{
|
||||
return _IO_file_seek(this, offset, dir);
|
||||
}
|
||||
|
||||
streamsize filebuf::sys_write(const char *buf, streamsize n)
|
||||
{
|
||||
return _IO_file_write (this, buf, n);
|
||||
}
|
||||
|
||||
int filebuf::sys_stat(void* st)
|
||||
{
|
||||
return _IO_file_stat (this, st);
|
||||
}
|
||||
|
||||
int filebuf::sys_close()
|
||||
{
|
||||
return _IO_file_close (this);
|
||||
}
|
||||
|
||||
streamsize filebuf::xsputn(const char *s, streamsize n)
|
||||
{
|
||||
return _IO_file_xsputn(this, s, n);
|
||||
}
|
||||
|
||||
streamsize filebuf::xsgetn(char *s, streamsize n)
|
||||
{
|
||||
// FIXME: OPTIMIZE THIS (specifically, when unbuffered()).
|
||||
return streambuf::xsgetn(s, n);
|
||||
}
|
||||
|
||||
// Non-ANSI AT&T-ism: Default open protection.
|
||||
const int filebuf::openprot = 0644;
|
||||
@@ -0,0 +1,110 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#define _STREAM_COMPAT
|
||||
extern "C" {
|
||||
#include "libioP.h"
|
||||
}
|
||||
#include <fstream.h>
|
||||
|
||||
inline void
|
||||
fstreambase::__fb_init()
|
||||
{
|
||||
#ifdef _IO_NEW_STREAMS
|
||||
#if !_IO_UNIFIED_JUMPTABLES
|
||||
/* Uses the _IO_file_jump jumptable, for eficiency. */
|
||||
__my_fb._jumps = &_IO_file_jumps;
|
||||
__my_fb._vtable() = builtinbuf_vtable;
|
||||
#endif
|
||||
init (&__my_fb);
|
||||
#else
|
||||
init(filebuf::__new());
|
||||
_flags &= ~ios::dont_close;
|
||||
#endif
|
||||
}
|
||||
|
||||
fstreambase::fstreambase()
|
||||
{
|
||||
__fb_init ();
|
||||
}
|
||||
|
||||
fstreambase::fstreambase(int fd)
|
||||
{
|
||||
__fb_init ();
|
||||
_IO_file_attach(rdbuf(), fd);
|
||||
}
|
||||
|
||||
fstreambase::fstreambase(const char *name, int mode, int prot)
|
||||
{
|
||||
__fb_init ();
|
||||
if (!rdbuf()->open(name, mode, prot))
|
||||
set(ios::badbit);
|
||||
}
|
||||
|
||||
fstreambase::fstreambase(int fd, char *p, int l)
|
||||
{
|
||||
#ifdef _IO_NEW_STREAMS
|
||||
__fb_init ();
|
||||
#else
|
||||
init(filebuf::__new());
|
||||
#endif
|
||||
_IO_file_attach(rdbuf(), fd);
|
||||
_IO_file_setbuf(rdbuf(), p, l);
|
||||
}
|
||||
|
||||
void fstreambase::open(const char *name, int mode, int prot)
|
||||
{
|
||||
clear();
|
||||
if (!rdbuf()->open(name, mode, prot))
|
||||
set(ios::badbit);
|
||||
}
|
||||
|
||||
void fstreambase::close()
|
||||
{
|
||||
if (!rdbuf()->close())
|
||||
set(ios::failbit);
|
||||
}
|
||||
|
||||
void fstreambase::attach(int fd)
|
||||
{
|
||||
if (!rdbuf()->attach(fd))
|
||||
set(ios::failbit);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int mode_to_sys(enum open_mode mode)
|
||||
{
|
||||
return O_WRONLY;
|
||||
}
|
||||
|
||||
static char* fopen_cmd_arg(io_mode i)
|
||||
{
|
||||
return "w";
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,96 @@
|
||||
/* Emulation of getpagesize() for systems that need it. */
|
||||
|
||||
/*
|
||||
|
||||
NAME
|
||||
|
||||
getpagesize -- return the number of bytes in page of memory
|
||||
|
||||
SYNOPSIS
|
||||
|
||||
int getpagesize (void)
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Returns the number of bytes in a page of memory. This is the
|
||||
granularity of many of the system memory management routines.
|
||||
No guarantee is made as to whether or not it is the same as the
|
||||
basic memory management hardware page size.
|
||||
|
||||
BUGS
|
||||
|
||||
Is intended as a reasonable replacement for systems where this
|
||||
is not provided as a system call. The value of 4096 may or may
|
||||
not be correct for the systems where it is returned as the default
|
||||
value.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef VMS
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#undef GNU_OUR_PAGESIZE
|
||||
#if defined (HAVE_SYSCONF) && defined (HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#ifdef _SC_PAGESIZE
|
||||
#define GNU_OUR_PAGESIZE sysconf(_SC_PAGESIZE)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GNU_OUR_PAGESIZE
|
||||
# ifdef PAGESIZE
|
||||
# define GNU_OUR_PAGESIZE PAGESIZE
|
||||
# else /* no PAGESIZE */
|
||||
# ifdef EXEC_PAGESIZE
|
||||
# define GNU_OUR_PAGESIZE EXEC_PAGESIZE
|
||||
# else /* no EXEC_PAGESIZE */
|
||||
# ifdef NBPG
|
||||
# define GNU_OUR_PAGESIZE (NBPG * CLSIZE)
|
||||
# ifndef CLSIZE
|
||||
# define CLSIZE 1
|
||||
# endif /* CLSIZE */
|
||||
# else /* no NBPG */
|
||||
# ifdef NBPC
|
||||
# define GNU_OUR_PAGESIZE NBPC
|
||||
# else /* no NBPC */
|
||||
# define GNU_OUR_PAGESIZE 4096 /* Just punt and use reasonable value */
|
||||
# endif /* NBPC */
|
||||
# endif /* NBPG */
|
||||
# endif /* EXEC_PAGESIZE */
|
||||
# endif /* PAGESIZE */
|
||||
#endif /* GNU_OUR_PAGESIZE */
|
||||
|
||||
int
|
||||
getpagesize ()
|
||||
{
|
||||
return (GNU_OUR_PAGESIZE);
|
||||
}
|
||||
|
||||
#else /* VMS */
|
||||
|
||||
#if 0 /* older distributions of gcc-vms are missing <syidef.h> */
|
||||
#include <syidef.h>
|
||||
#endif
|
||||
#ifndef SYI$_PAGE_SIZE /* VMS V5.4 and earlier didn't have this yet */
|
||||
#define SYI$_PAGE_SIZE 4452
|
||||
#endif
|
||||
extern unsigned long lib$getsyi(const unsigned short *,...);
|
||||
|
||||
int getpagesize ()
|
||||
{
|
||||
long pagsiz = 0L;
|
||||
unsigned short itmcod = SYI$_PAGE_SIZE;
|
||||
|
||||
(void) lib$getsyi (&itmcod, (void *) &pagsiz);
|
||||
if (pagsiz == 0L)
|
||||
pagsiz = 512L; /* VAX default */
|
||||
return (int) pagsiz;
|
||||
}
|
||||
|
||||
#endif /* VMS */
|
||||
@@ -0,0 +1,121 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <indstream.h>
|
||||
|
||||
indirectbuf::indirectbuf(streambuf *get, streambuf *put, int delete_mode)
|
||||
: streambuf()
|
||||
{
|
||||
_get_stream = get;
|
||||
_put_stream = put == NULL ? get : put;
|
||||
_delete_flags = delete_mode;
|
||||
}
|
||||
|
||||
indirectbuf::~indirectbuf()
|
||||
{
|
||||
if (_delete_flags & ios::in) delete get_stream();
|
||||
if (_delete_flags & ios::out) delete put_stream();
|
||||
}
|
||||
|
||||
streamsize indirectbuf::xsputn(const char* s, streamsize n)
|
||||
{
|
||||
return put_stream()->sputn(s, n);
|
||||
}
|
||||
|
||||
streamsize indirectbuf::xsgetn(char* s, streamsize n)
|
||||
{
|
||||
return get_stream()->sgetn(s, n);
|
||||
}
|
||||
|
||||
int indirectbuf::overflow(int c /* = EOF */)
|
||||
{
|
||||
if (c == EOF)
|
||||
return put_stream()->overflow(c);
|
||||
else
|
||||
return put_stream()->sputc(c);
|
||||
}
|
||||
|
||||
int indirectbuf::underflow()
|
||||
{
|
||||
return get_stream()->sgetc();
|
||||
}
|
||||
|
||||
int indirectbuf::uflow()
|
||||
{
|
||||
return get_stream()->sbumpc();
|
||||
}
|
||||
|
||||
streampos indirectbuf::seekoff(streamoff off, _seek_dir dir, int mode)
|
||||
{
|
||||
int ret_val = 0;
|
||||
int select = mode == 0 ? (ios::in|ios::out) : mode;
|
||||
streambuf *gbuf = (select & ios::in) ? get_stream() : (streambuf*)NULL;
|
||||
streambuf *pbuf = (select & ios::out) ? put_stream() : (streambuf*)NULL;
|
||||
if (gbuf == pbuf)
|
||||
ret_val = gbuf->seekoff(off, dir, mode);
|
||||
else {
|
||||
if (gbuf)
|
||||
ret_val = gbuf->seekoff(off, dir, ios::in);
|
||||
if (pbuf && ret_val != EOF)
|
||||
ret_val = pbuf->seekoff(off, dir, ios::out);
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
streampos indirectbuf::seekpos(streampos pos, int mode)
|
||||
{
|
||||
int ret_val = EOF;
|
||||
int select = mode == 0 ? (ios::in|ios::out) : mode;
|
||||
streambuf *gbuf = (select & ios::in) ? get_stream() : (streambuf*)NULL;
|
||||
streambuf *pbuf = (select & ios::out) ? put_stream() : (streambuf*)NULL;
|
||||
if (gbuf == pbuf && gbuf != NULL)
|
||||
ret_val = gbuf->seekpos(pos, mode);
|
||||
else {
|
||||
if (gbuf)
|
||||
ret_val = gbuf->seekpos(pos, ios::in);
|
||||
if (pbuf && ret_val != EOF)
|
||||
ret_val = pbuf->seekpos(pos, ios::out);
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
int indirectbuf::sync()
|
||||
{
|
||||
streambuf *gbuf = get_stream();
|
||||
int get_ret_val = gbuf ? gbuf->sync() : 0;
|
||||
streambuf *pbuf = put_stream();
|
||||
int put_ret_val = (pbuf && pbuf != gbuf) ? pbuf->sync() : 0;
|
||||
return get_ret_val || put_ret_val;
|
||||
}
|
||||
|
||||
int indirectbuf::pbackfail(int c)
|
||||
{
|
||||
return get_stream()->sputbackc(c);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/* insque(3C) routines
|
||||
This file is in the public domain. */
|
||||
|
||||
/*
|
||||
NAME
|
||||
insque, remque -- insert, remove an element from a queue
|
||||
|
||||
SYNOPSIS
|
||||
struct qelem {
|
||||
struct qelem *q_forw;
|
||||
struct qelem *q_back;
|
||||
char q_data[];
|
||||
};
|
||||
|
||||
void insque (struct qelem *elem, struct qelem *pred)
|
||||
|
||||
void remque (struct qelem *elem)
|
||||
|
||||
DESCRIPTION
|
||||
Routines to manipulate queues built from doubly linked lists.
|
||||
The insque routine inserts ELEM in the queue immediately after
|
||||
PRED. The remque routine removes ELEM from its containing queue.
|
||||
*/
|
||||
|
||||
|
||||
struct qelem {
|
||||
struct qelem *q_forw;
|
||||
struct qelem *q_back;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
insque (elem, pred)
|
||||
struct qelem *elem;
|
||||
struct qelem *pred;
|
||||
{
|
||||
elem -> q_forw = pred -> q_forw;
|
||||
pred -> q_forw -> q_back = elem;
|
||||
elem -> q_back = pred;
|
||||
pred -> q_forw = elem;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
remque (elem)
|
||||
struct qelem *elem;
|
||||
{
|
||||
elem -> q_forw -> q_back = elem -> q_back;
|
||||
elem -> q_back -> q_forw = elem -> q_forw;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/* 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#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)
|
||||
{
|
||||
init (rhs.rdbuf ());
|
||||
_gcount = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
_IO_ostream_withassign& _IO_ostream_withassign::operator=(ostream& rhs)
|
||||
{
|
||||
if (&rhs != (ostream*)this)
|
||||
init (rhs.rdbuf ());
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
static int __xalloc = 0;
|
||||
|
||||
int ios::xalloc()
|
||||
{
|
||||
return __xalloc++;
|
||||
}
|
||||
|
||||
static ios::fmtflags __used_fmt_flags
|
||||
= ios::skipws | ios::left | ios::right | ios::internal
|
||||
| ios::dec | ios::oct | ios::hex | ios::showbase | ios::showpoint
|
||||
| ios::uppercase | ios::showpos | ios::scientific | ios::fixed
|
||||
#ifndef _IO_NEW_STREAMS
|
||||
| ios::dont_close
|
||||
#endif
|
||||
| ios::unitbuf | ios::stdio;
|
||||
|
||||
ios::fmtflags ios::bitalloc()
|
||||
{
|
||||
fmtflags bit_to_try = (fmtflags)1;
|
||||
for (; bit_to_try; bit_to_try <<= 1)
|
||||
{
|
||||
if ((__used_fmt_flags & bit_to_try) == 0)
|
||||
{
|
||||
__used_fmt_flags |= bit_to_try;
|
||||
return bit_to_try;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// NOTE: This implementation of ios::iword and ios::pword assumes
|
||||
// that these methods are seldom used, so we want to minimize
|
||||
// the space and time overhead when NOT using these methods.
|
||||
//
|
||||
// ANSI specifies two conceptually-infinite arrays, one whose
|
||||
// elements are longs, and one whose elements are (void*)s.
|
||||
// We implement this as a single array, each of whose element is
|
||||
// a (struct ptr_and_long), which has space for both a long and a void*.
|
||||
// We also specify that (the i field of) the 0'th element of the array
|
||||
// contains the allocated length of the array (not counting that
|
||||
// initial element).
|
||||
|
||||
struct ptr_and_long {
|
||||
void *p;
|
||||
long i;
|
||||
};
|
||||
|
||||
static struct ptr_and_long&
|
||||
get_array_element(ios& io, int index)
|
||||
{
|
||||
if (index < 0)
|
||||
io._throw_failure();
|
||||
register struct ptr_and_long *array = (ptr_and_long*)io._arrays;
|
||||
int old_length = array == NULL ? 0 : array[0].i;
|
||||
if (index >= old_length)
|
||||
{
|
||||
register int i;
|
||||
int new_length = index + 10;
|
||||
register struct ptr_and_long *new_array
|
||||
= new ptr_and_long[1 + new_length];
|
||||
if (array != NULL)
|
||||
{
|
||||
for (i = 1; i <= old_length; i++)
|
||||
new_array[i] = array[i];
|
||||
delete [] array;
|
||||
}
|
||||
for (i = old_length + 1; i <= new_length; i++)
|
||||
{
|
||||
new_array[i].i = 0;
|
||||
new_array[i].p = NULL;
|
||||
}
|
||||
new_array[0].i = new_length;
|
||||
new_array[0].p = NULL;
|
||||
io._arrays = (void*)new_array;
|
||||
array = new_array;
|
||||
}
|
||||
return array[index+1];
|
||||
}
|
||||
|
||||
long& ios::iword(int index)
|
||||
{
|
||||
return get_array_element(*this, index).i;
|
||||
}
|
||||
|
||||
void*& ios::pword(int index)
|
||||
{
|
||||
return get_array_element(*this, index).p;
|
||||
}
|
||||
|
||||
long ios::iword(int index) const
|
||||
{
|
||||
if (index < 0)
|
||||
_throw_failure();
|
||||
register struct ptr_and_long *pl_array = (ptr_and_long*)_arrays;
|
||||
int len = pl_array == NULL ? 0 : pl_array[0].i;
|
||||
return index >= len ? 0 : pl_array[index+1].i;
|
||||
}
|
||||
|
||||
void* ios::pword(int index) const
|
||||
{
|
||||
if (index < 0)
|
||||
_throw_failure();
|
||||
register struct ptr_and_long *pl_array = (ptr_and_long*)_arrays;
|
||||
int len = pl_array == NULL ? 0 : pl_array[0].i;
|
||||
return index >= len ? 0 : pl_array[index+1].p;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "iomanip.h"
|
||||
|
||||
|
||||
// Those functions are called through a pointer,
|
||||
// thus it does not make sense, to inline them.
|
||||
|
||||
ios & __iomanip_setbase (ios& i, int n)
|
||||
{
|
||||
ios::fmtflags b;
|
||||
switch (n)
|
||||
{
|
||||
case 8:
|
||||
b = ios::oct; break;
|
||||
case 10:
|
||||
b = ios::dec; break;
|
||||
case 16:
|
||||
b = ios::hex; break;
|
||||
default:
|
||||
b = 0;
|
||||
}
|
||||
i.setf(b, ios::basefield);
|
||||
return i;
|
||||
}
|
||||
|
||||
ios & __iomanip_setfill (ios& i, int n)
|
||||
{
|
||||
//FIXME if ( i.flags() & ios::widechar )
|
||||
i.fill( (char) n);
|
||||
//FIXME else
|
||||
//FIXME i.fill( (wchar) n);
|
||||
return i;
|
||||
}
|
||||
|
||||
ios & __iomanip_setprecision (ios& i, int n)
|
||||
{
|
||||
i.precision(n);
|
||||
return i;
|
||||
}
|
||||
ios & __iomanip_setw (ios& i, int n)
|
||||
{
|
||||
i.width(n);
|
||||
return i;
|
||||
}
|
||||
|
||||
ios & __iomanip_setiosflags (ios& i, ios::fmtflags n)
|
||||
{
|
||||
i.setf(n,n);
|
||||
return i;
|
||||
}
|
||||
|
||||
ios & __iomanip_resetiosflags (ios& i, ios::fmtflags n)
|
||||
{
|
||||
i.setf(0,n);
|
||||
return i;
|
||||
}
|
||||
|
||||
template class smanip<int>;
|
||||
template class smanip<ios::fmtflags>;
|
||||
template istream& operator>>(istream&, const smanip<int>&);
|
||||
template istream& operator>>(istream&, const smanip<ios::fmtflags>&);
|
||||
template ostream& operator<<(ostream&, const smanip<int>&);
|
||||
template ostream& operator<<(ostream&, const smanip<ios::fmtflags>&);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include "streambuf.h"
|
||||
#include "libioP.h"
|
||||
@@ -0,0 +1,153 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include <libioP.h>
|
||||
#include "iostream.h"
|
||||
#include <string.h>
|
||||
|
||||
istream& istream::getline(char* buf, int len, char delim)
|
||||
{
|
||||
_gcount = 0;
|
||||
if (len <= 0)
|
||||
{
|
||||
set(ios::failbit);
|
||||
return *this;
|
||||
}
|
||||
int ch;
|
||||
if (ipfx1())
|
||||
{
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
streambuf *sb = rdbuf();
|
||||
_gcount = _IO_getline_info(sb, buf, len - 1, delim, -1, &ch);
|
||||
if (ch != EOF)
|
||||
ch = sb->sbumpc();
|
||||
if (ch == EOF)
|
||||
set (_gcount == 0 ? (ios::failbit|ios::eofbit) : ios::eofbit);
|
||||
else if (ch != (unsigned char) delim)
|
||||
{
|
||||
set(ios::failbit);
|
||||
sb->sungetc(); // Leave delimiter unread.
|
||||
}
|
||||
isfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
else
|
||||
ch = EOF;
|
||||
buf[_gcount] = '\0';
|
||||
if (ch == (unsigned char)delim)
|
||||
_gcount++; // The delimiter is counted in the gcount().
|
||||
return *this;
|
||||
}
|
||||
|
||||
istream& istream::get(char* buf, int len, char delim)
|
||||
{
|
||||
_gcount = 0;
|
||||
if (len <= 0)
|
||||
{
|
||||
set(ios::failbit);
|
||||
return *this;
|
||||
}
|
||||
if (ipfx1())
|
||||
{
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
streambuf *sbuf = rdbuf();
|
||||
int ch;
|
||||
_gcount = _IO_getline_info(sbuf, buf, len - 1, delim, -1, &ch);
|
||||
if (_gcount == 0 && ch == EOF)
|
||||
set(ios::failbit|ios::eofbit);
|
||||
isfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
buf[_gcount] = '\0';
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// from Doug Schmidt
|
||||
|
||||
#define CHUNK_SIZE 512
|
||||
|
||||
/* Reads an arbitrarily long input line terminated by a user-specified
|
||||
TERMINATOR. Super-nifty trick using recursion avoids unnecessary calls
|
||||
to NEW! */
|
||||
|
||||
char *_sb_readline (streambuf *sb, long& total, char terminator)
|
||||
{
|
||||
char buf[CHUNK_SIZE];
|
||||
char *ptr;
|
||||
int ch;
|
||||
|
||||
_IO_size_t count = _IO_getline_info(sb, buf, CHUNK_SIZE, terminator,
|
||||
-1, &ch);
|
||||
if (ch != EOF)
|
||||
ch = sb->sbumpc();
|
||||
long old_total = total;
|
||||
total += count;
|
||||
if (ch != EOF && ch != terminator) {
|
||||
total++; // Include ch in total.
|
||||
ptr = _sb_readline(sb, total, terminator);
|
||||
if (ptr) {
|
||||
memcpy(ptr + old_total, buf, count);
|
||||
ptr[old_total+count] = ch;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ptr = new char[total+1];
|
||||
if (ptr != NULL) {
|
||||
ptr[total] = '\0';
|
||||
memcpy(ptr + total - count, buf, count);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* Reads an arbitrarily long input line terminated by TERMINATOR.
|
||||
This routine allocates its own memory, so the user should
|
||||
only supply the address of a (char *). */
|
||||
|
||||
istream& istream::gets(char **s, char delim /* = '\n' */)
|
||||
{
|
||||
if (ipfx1()) {
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
long size = 0;
|
||||
streambuf *sb = rdbuf();
|
||||
*s = _sb_readline (sb, size, delim);
|
||||
_gcount = *s ? size : 0;
|
||||
if (sb->_flags & _IO_EOF_SEEN) {
|
||||
set(ios::eofbit);
|
||||
if (_gcount == 0)
|
||||
set(ios::failbit);
|
||||
}
|
||||
isfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
else {
|
||||
_gcount = 0;
|
||||
*s = NULL;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include "libioP.h"
|
||||
#include "iostream.h"
|
||||
#include <string.h>
|
||||
|
||||
istream& istream::get(streambuf& sb, char delim /* = '\n' */)
|
||||
{
|
||||
_gcount = 0;
|
||||
if (ipfx1())
|
||||
{
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
register streambuf* isb = rdbuf();
|
||||
for (;;)
|
||||
{
|
||||
streamsize len = isb->_IO_read_end - isb->_IO_read_ptr;
|
||||
if (len <= 0)
|
||||
if (__underflow(isb) == EOF)
|
||||
break;
|
||||
else
|
||||
len = isb->_IO_read_end - isb->_IO_read_ptr;
|
||||
char *delimp = (char*)memchr((void*)isb->_IO_read_ptr, delim, len);
|
||||
if (delimp != NULL)
|
||||
len = delimp - isb->_IO_read_ptr;
|
||||
int written = sb.sputn(isb->_IO_read_ptr, len);
|
||||
isb->_IO_read_ptr += written;
|
||||
_gcount += written;
|
||||
if (written != len)
|
||||
{
|
||||
set(ios::failbit);
|
||||
break;
|
||||
}
|
||||
if (delimp != NULL)
|
||||
break;
|
||||
}
|
||||
isfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include "libioP.h"
|
||||
#include <iostream.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
istream& istream::scan(const char *format ...)
|
||||
{
|
||||
if (ipfx0()) {
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
_strbuf->vscan(format, ap, this);
|
||||
va_end(ap);
|
||||
isfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
istream& istream::vscan(const char *format, _IO_va_list args)
|
||||
{
|
||||
if (ipfx0())
|
||||
{
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
_strbuf->vscan(format, args, this);
|
||||
isfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/* Function declarations for libiberty.
|
||||
Written by Cygnus Support, 1994.
|
||||
|
||||
The libiberty library provides a number of functions which are
|
||||
missing on some operating systems. We do not declare those here,
|
||||
to avoid conflicts with the system header files on operating
|
||||
systems that do support those functions. In this file we only
|
||||
declare those functions which are specific to libiberty. */
|
||||
|
||||
#ifndef LIBIBERTY_H
|
||||
#define LIBIBERTY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ansidecl.h"
|
||||
|
||||
/* Build an argument vector from a string. Allocates memory using
|
||||
malloc. Use freeargv to free the vector. */
|
||||
|
||||
extern char **buildargv PARAMS ((char *));
|
||||
|
||||
/* Free a vector returned by buildargv. */
|
||||
|
||||
extern void freeargv PARAMS ((char **));
|
||||
|
||||
/* Duplicate an argument vector. Allocates memory using malloc. Use
|
||||
freeargv to free the vector. */
|
||||
|
||||
extern char **dupargv PARAMS ((char **));
|
||||
|
||||
|
||||
/* Return the last component of a path name. Note that we can't use a
|
||||
prototype here because the parameter is declared inconsistently
|
||||
across different systems, sometimes as "char *" and sometimes as
|
||||
"const char *" */
|
||||
|
||||
#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__)
|
||||
extern char *basename PARAMS ((const char *));
|
||||
#else
|
||||
extern char *basename ();
|
||||
#endif
|
||||
|
||||
/* Concatenate an arbitrary number of strings, up to (char *) NULL.
|
||||
Allocates memory using xmalloc. */
|
||||
|
||||
extern char *concat PARAMS ((const char *, ...));
|
||||
|
||||
/* Check whether two file descriptors refer to the same file. */
|
||||
|
||||
extern int fdmatch PARAMS ((int fd1, int fd2));
|
||||
|
||||
/* Get the amount of time the process has run, in microseconds. */
|
||||
|
||||
extern long get_run_time PARAMS ((void));
|
||||
|
||||
/* Choose a temporary directory to use for scratch files. */
|
||||
|
||||
extern char *choose_temp_base PARAMS ((void));
|
||||
|
||||
/* Allocate memory filled with spaces. Allocates using malloc. */
|
||||
|
||||
extern const char *spaces PARAMS ((int count));
|
||||
|
||||
/* Return the maximum error number for which strerror will return a
|
||||
string. */
|
||||
|
||||
extern int errno_max PARAMS ((void));
|
||||
|
||||
/* Return the name of an errno value (e.g., strerrno (EINVAL) returns
|
||||
"EINVAL"). */
|
||||
|
||||
extern const char *strerrno PARAMS ((int));
|
||||
|
||||
/* Given the name of an errno value, return the value. */
|
||||
|
||||
extern int strtoerrno PARAMS ((const char *));
|
||||
|
||||
/* ANSI's strerror(), but more robust. */
|
||||
|
||||
extern char *xstrerror PARAMS ((int));
|
||||
|
||||
/* Return the maximum signal number for which strsignal will return a
|
||||
string. */
|
||||
|
||||
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"). */
|
||||
|
||||
extern const char *strsigno PARAMS ((int));
|
||||
|
||||
/* Given the name of a signal, return its number. */
|
||||
|
||||
extern int strtosigno PARAMS ((const char *));
|
||||
|
||||
/* Register a function to be run by xexit. Returns 0 on success. */
|
||||
|
||||
extern int xatexit PARAMS ((void (*fn) (void)));
|
||||
|
||||
/* Exit, calling all the functions registered with xatexit. */
|
||||
|
||||
#ifndef __GNUC__
|
||||
extern void xexit PARAMS ((int status));
|
||||
#else
|
||||
void xexit PARAMS ((int status)) __attribute__ ((noreturn));
|
||||
#endif
|
||||
|
||||
/* Set the program name used by xmalloc. */
|
||||
|
||||
extern void xmalloc_set_program_name PARAMS ((const char *));
|
||||
|
||||
/* Allocate memory without fail. If malloc fails, this will print a
|
||||
message to stderr (using the name set by xmalloc_set_program_name,
|
||||
if any) and then call xexit. */
|
||||
|
||||
#ifdef ANSI_PROTOTYPES
|
||||
/* Get a definition for size_t. */
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
extern PTR xmalloc PARAMS ((size_t));
|
||||
|
||||
/* Reallocate memory without fail. This works like xmalloc.
|
||||
|
||||
FIXME: We do not declare the parameter types for the same reason as
|
||||
xmalloc. */
|
||||
|
||||
extern PTR xrealloc PARAMS ((PTR, size_t));
|
||||
|
||||
/* Allocate memory without fail and set it to zero. This works like
|
||||
xmalloc. */
|
||||
|
||||
extern PTR xcalloc PARAMS ((size_t, size_t));
|
||||
|
||||
/* Copy a string into a memory buffer without fail. */
|
||||
|
||||
extern char *xstrdup PARAMS ((const char *));
|
||||
|
||||
/* hex character manipulation routines */
|
||||
|
||||
#define _hex_array_size 256
|
||||
#define _hex_bad 99
|
||||
extern char _hex_value[_hex_array_size];
|
||||
extern void hex_init PARAMS ((void));
|
||||
#define hex_p(c) (hex_value (c) != _hex_bad)
|
||||
/* If you change this, note well: Some code relies on side effects in
|
||||
the argument being performed exactly once. */
|
||||
#define hex_value(c) (_hex_value[(unsigned char) (c)])
|
||||
|
||||
/* Definitions used by the pexecute routine. */
|
||||
|
||||
#define PEXECUTE_FIRST 1
|
||||
#define PEXECUTE_LAST 2
|
||||
#define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST)
|
||||
#define PEXECUTE_SEARCH 4
|
||||
#define PEXECUTE_VERBOSE 8
|
||||
|
||||
/* Execute a program. */
|
||||
|
||||
extern int pexecute PARAMS ((const char *, char * const *, const char *,
|
||||
const char *, char **, char **, int));
|
||||
|
||||
/* Wait for pexecute to finish. */
|
||||
|
||||
extern int pwait PARAMS ((int, int *, int));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* ! defined (LIBIBERTY_H) */
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include "libioP.h"
|
||||
#include <iostream.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
ostream& ostream::form(const char *format ...)
|
||||
{
|
||||
if (opfx()) {
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
_IO_vfprintf(rdbuf(), format, ap);
|
||||
va_end(ap);
|
||||
osfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ostream& ostream::vform(const char *format, _IO_va_list args)
|
||||
{
|
||||
if (opfx()) {
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
_IO_vfprintf(rdbuf(), format, args);
|
||||
osfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ostream& ostream::operator<<(const void *p)
|
||||
{
|
||||
if (opfx()) {
|
||||
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
|
||||
_strbuf);
|
||||
form("%p", p);
|
||||
osfx();
|
||||
_IO_cleanup_region_end (0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include "libioP.h"
|
||||
#include "parsestream.h"
|
||||
#include <stdlib.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 = (char*)malloc(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 i; // Suppress warnings.
|
||||
#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
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include "libioP.h"
|
||||
#include <pfstream.h>
|
||||
#include <procbuf.h>
|
||||
|
||||
ipfstream::ipfstream(const char *name, int mode, int prot)
|
||||
{
|
||||
const char* p;
|
||||
|
||||
// Look for '| command' (as used by ftp).
|
||||
for (p = name; *p == ' ' || *p == '\t'; p++) ;
|
||||
if (*p == '|') {
|
||||
procbuf *pbuf = new procbuf();
|
||||
init(pbuf);
|
||||
if (!pbuf->open(p+1, mode))
|
||||
set(ios::badbit);
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for 'command |'
|
||||
while (*p) p++; // Point to last
|
||||
while (p[-1] == ' ' || p[-1] == '\t' || p[-1] == '\n') p--;
|
||||
if (p[-1] == '|') {
|
||||
// Must remove the final '|'.
|
||||
p--;
|
||||
#if !defined (__GNUC__) || defined (__STRICT_ANSI__)
|
||||
char *command = new char[p-name+1];
|
||||
#else
|
||||
char command[p-name+1];
|
||||
#endif
|
||||
memcpy(command, name, p-name);
|
||||
command[p-name] = '\0';
|
||||
|
||||
procbuf *pbuf = new procbuf();
|
||||
if (pbuf->open(command, mode))
|
||||
set(ios::badbit);
|
||||
#if !defined (__GNUC__) || defined (__STRICT_ANSI__)
|
||||
delete command;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
init(new filebuf());
|
||||
if (!rdbuf()->open(name, mode, prot))
|
||||
set(ios::badbit);
|
||||
}
|
||||
|
||||
opfstream::opfstream(const char *name, int mode, int prot)
|
||||
{
|
||||
const char *p;
|
||||
// Look for '| command'.
|
||||
for (p = name; *p == ' ' || *p == '\t'; p++) ;
|
||||
if (*p == '|') {
|
||||
procbuf *pbuf = new procbuf();
|
||||
init(pbuf);
|
||||
if (!pbuf->open(p+1, mode))
|
||||
set(ios::badbit);
|
||||
}
|
||||
else {
|
||||
init(new filebuf());
|
||||
if (!rdbuf()->open(name, mode, prot))
|
||||
set(ios::badbit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "libioP.h"
|
||||
#include "procbuf.h"
|
||||
|
||||
procbuf::procbuf(const char *command, int mode) : filebuf()
|
||||
{
|
||||
_IO_proc_open(this, command, (mode & ios::in) ? "r" : "w");
|
||||
}
|
||||
|
||||
procbuf *procbuf::open(const char *command, int mode)
|
||||
{
|
||||
return (procbuf*)_IO_proc_open(this, command, (mode & ios::in) ? "r" : "w");
|
||||
}
|
||||
|
||||
/* #define USE_SIGMASK */
|
||||
|
||||
int procbuf::sys_close()
|
||||
{
|
||||
return _IO_proc_close(this);
|
||||
}
|
||||
|
||||
procbuf::~procbuf()
|
||||
{
|
||||
close();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include "libioP.h"
|
||||
#include "streambuf.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
int streambuf::vform(char const *fmt0, _IO_va_list ap)
|
||||
{
|
||||
return _IO_vfprintf(this, fmt0, ap);
|
||||
}
|
||||
int streambuf::form(char const *format ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int count = _IO_vfprintf(this, format, ap);
|
||||
va_end(ap);
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include "libioP.h"
|
||||
#include "streambuf.h"
|
||||
|
||||
long streambuf::sgetline(char* buf, _IO_size_t n, char delim, int extract_delim)
|
||||
{
|
||||
return _IO_getline_info(this, buf, n, delim, extract_delim, (int *) 0);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include "libioP.h"
|
||||
#include "streambuf.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
int streambuf::vscan(char const *fmt0, _IO_va_list ap, ios* stream /* = NULL*/)
|
||||
{
|
||||
int errcode = 0;
|
||||
int count = _IO_vfscanf(this, fmt0, ap, &errcode);
|
||||
if (stream)
|
||||
stream->setstate((ios::iostate)errcode);
|
||||
return count;
|
||||
}
|
||||
int streambuf::scan(char const *format ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int count = _IO_vfscanf(this, format, ap, NULL);
|
||||
va_end(ap);
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Version of sigsetmask.c
|
||||
Written by Steve Chamberlain (sac@cygnus.com).
|
||||
Contributed by Cygnus Support.
|
||||
This file is in the public doamin. */
|
||||
|
||||
/* Set the current signal mask to the set provided, and return the
|
||||
previous value */
|
||||
|
||||
#define _POSIX_SOURCE
|
||||
#include <ansidecl.h>
|
||||
/* Including <sys/types.h> seems to be needed by ISC. */
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef SIG_SETMASK
|
||||
int
|
||||
DEFUN(sigsetmask,(set),
|
||||
int set)
|
||||
{
|
||||
sigset_t new;
|
||||
sigset_t old;
|
||||
|
||||
sigemptyset (&new);
|
||||
if (set != 0) {
|
||||
abort(); /* FIXME, we don't know how to translate old mask to new */
|
||||
}
|
||||
sigprocmask(SIG_SETMASK, &new, &old);
|
||||
return 1; /* FIXME, we always return 1 as old value. */
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,135 @@
|
||||
// Instantiation file for the -*- C++ -*- string classes.
|
||||
// Copyright (C) 1994 Free Software Foundation
|
||||
|
||||
// This file is part of the GNU ANSI 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 this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 Jason Merrill based upon the specification by Takanori Adachi
|
||||
// in ANSI X3J16/94-0013R2.
|
||||
|
||||
#ifdef __GNUG__
|
||||
#ifdef TRAITS
|
||||
#ifdef C
|
||||
#pragma implementation "std/straits.h"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef C
|
||||
typedef char c;
|
||||
#endif
|
||||
#ifdef W
|
||||
typedef wchar_t c;
|
||||
#endif
|
||||
|
||||
#if defined(TRAITS) && !defined(C)
|
||||
template class string_char_traits <c>;
|
||||
#else
|
||||
/* string_char_traits<char> is already explicitly specialized in
|
||||
std/straits.h. */
|
||||
#endif
|
||||
|
||||
typedef basic_string <c> s;
|
||||
|
||||
#ifdef MAIN
|
||||
template class basic_string <c>;
|
||||
#endif
|
||||
|
||||
#ifdef ADDSS
|
||||
template s operator+ (const s&, const s&);
|
||||
#endif
|
||||
#ifdef ADDPS
|
||||
template s operator+ (const c*, const s&);
|
||||
#endif
|
||||
#ifdef ADDCS
|
||||
template s operator+ (c, const s&);
|
||||
#endif
|
||||
#ifdef ADDSP
|
||||
template s operator+ (const s&, const c*);
|
||||
#endif
|
||||
#ifdef ADDSC
|
||||
template s operator+ (const s&, c);
|
||||
#endif
|
||||
#ifdef EQSS
|
||||
template bool operator== (const s&, const s&);
|
||||
#endif
|
||||
#ifdef EQPS
|
||||
template bool operator== (const c*, const s&);
|
||||
#endif
|
||||
#ifdef EQSP
|
||||
template bool operator== (const s&, const c*);
|
||||
#endif
|
||||
#ifdef NESS
|
||||
template bool operator!= (const s&, const s&);
|
||||
#endif
|
||||
#ifdef NEPS
|
||||
template bool operator!= (const c*, const s&);
|
||||
#endif
|
||||
#ifdef NESP
|
||||
template bool operator!= (const s&, const c*);
|
||||
#endif
|
||||
#ifdef LTSS
|
||||
template bool operator< (const s&, const s&);
|
||||
#endif
|
||||
#ifdef LTPS
|
||||
template bool operator< (const c*, const s&);
|
||||
#endif
|
||||
#ifdef LTSP
|
||||
template bool operator< (const s&, const c*);
|
||||
#endif
|
||||
#ifdef GTSS
|
||||
template bool operator> (const s&, const s&);
|
||||
#endif
|
||||
#ifdef GTPS
|
||||
template bool operator> (const c*, const s&);
|
||||
#endif
|
||||
#ifdef GTSP
|
||||
template bool operator> (const s&, const c*);
|
||||
#endif
|
||||
#ifdef LESS
|
||||
template bool operator<= (const s&, const s&);
|
||||
#endif
|
||||
#ifdef LEPS
|
||||
template bool operator<= (const c*, const s&);
|
||||
#endif
|
||||
#ifdef LESP
|
||||
template bool operator<= (const s&, const c*);
|
||||
#endif
|
||||
#ifdef GESS
|
||||
template bool operator>= (const s&, const s&);
|
||||
#endif
|
||||
#ifdef GEPS
|
||||
template bool operator>= (const c*, const s&);
|
||||
#endif
|
||||
#ifdef GESP
|
||||
template bool operator>= (const s&, const c*);
|
||||
#endif
|
||||
#ifdef EXTRACT
|
||||
template istream& operator>> (istream&, s&);
|
||||
#endif // EXTRACT
|
||||
#ifdef INSERT
|
||||
template ostream& operator<< (ostream&, const s&);
|
||||
#endif // INSERT
|
||||
#ifdef GETLINE
|
||||
template istream& getline (istream&, s&, c);
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
// Implementation file for Exception Support for -*- C++ -*-
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "stdexcept"
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
// Entry points for string.
|
||||
|
||||
void
|
||||
__out_of_range (const char *s)
|
||||
{
|
||||
throw std::out_of_range (s);
|
||||
}
|
||||
|
||||
void __length_error (const char *s)
|
||||
{
|
||||
throw std::length_error (s);
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "libioP.h"
|
||||
#include <stdiostream.h>
|
||||
|
||||
// A stdiobuf is "tied" to a FILE object (as used by the stdio package).
|
||||
// Thus a stdiobuf is always synchronized with the corresponding FILE,
|
||||
// though at the cost of some overhead. (If you use the implementation
|
||||
// of stdio supplied with this library, you don't need stdiobufs.)
|
||||
// This implementation inherits from filebuf, but implement the virtual
|
||||
// functions sys_read/..., using the stdio functions fread/... instead
|
||||
// of the low-level read/... system calls. This has the advantage that
|
||||
// we get all of the nice filebuf semantics automatically, though
|
||||
// with some overhead.
|
||||
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1
|
||||
#endif
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2
|
||||
#endif
|
||||
|
||||
stdiobuf::stdiobuf(FILE *f) : filebuf(fileno(f))
|
||||
{
|
||||
_file = f;
|
||||
// Turn off buffer in stdiobuf. Instead, rely on buffering in (FILE).
|
||||
// Thus the stdiobuf will be synchronized with the FILE.
|
||||
setbuf(NULL, 0);
|
||||
}
|
||||
|
||||
stdiobuf::~stdiobuf()
|
||||
{
|
||||
/* Only needed if we're buffered. Not buffered is the default. */
|
||||
_IO_do_flush((_IO_FILE*)this);
|
||||
}
|
||||
|
||||
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 int ch = getc(_file);
|
||||
if (ch == EOF)
|
||||
return 0;
|
||||
*buf = (char)ch;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return fread(buf, 1, size, _file);
|
||||
}
|
||||
|
||||
streamsize stdiobuf::sys_write(const char *buf, streamsize n)
|
||||
{
|
||||
_IO_ssize_t count = fwrite(buf, 1, n, _file);
|
||||
if (_offset >= 0)
|
||||
_offset += n;
|
||||
return count;
|
||||
}
|
||||
|
||||
streampos stdiobuf::sys_seek(streamoff offset, _seek_dir dir)
|
||||
{
|
||||
// Normally, equivalent to: fdir=dir
|
||||
int fdir =
|
||||
(dir == ios::beg) ? SEEK_SET :
|
||||
(dir == ios::cur) ? SEEK_CUR :
|
||||
(dir == ios::end) ? SEEK_END :
|
||||
dir;
|
||||
return fseek(_file, offset, fdir);
|
||||
}
|
||||
|
||||
int stdiobuf::sys_close()
|
||||
{
|
||||
int status = fclose(_file);
|
||||
_file = NULL;
|
||||
return status;
|
||||
}
|
||||
|
||||
int stdiobuf::sync()
|
||||
{
|
||||
if (_IO_do_flush((_IO_FILE*)this))
|
||||
return EOF;
|
||||
if (!(xflags() & _IO_NO_WRITES))
|
||||
if (fflush(_file))
|
||||
return EOF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stdiobuf::overflow(int c /* = EOF*/)
|
||||
{
|
||||
if (filebuf::overflow(c) == EOF)
|
||||
return EOF;
|
||||
if (c != EOF)
|
||||
return c;
|
||||
return fflush(_file);
|
||||
}
|
||||
|
||||
streamsize stdiobuf::xsputn(const char* s, streamsize n)
|
||||
{
|
||||
if (buffered ())
|
||||
{
|
||||
// The filebuf implementation of sputn loses.
|
||||
return streambuf::xsputn(s, n);
|
||||
}
|
||||
else
|
||||
return fwrite (s, 1, n, _file);
|
||||
}
|
||||
|
||||
void stdiobuf::buffered (int b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
if (_flags & _IO_UNBUFFERED)
|
||||
{ /* Was unbuffered, make it buffered. */
|
||||
_flags &= ~_IO_UNBUFFERED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(_flags & _IO_UNBUFFERED))
|
||||
{ /* Was buffered, make it unbuffered. */
|
||||
setbuf(NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
|
||||
/* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
|
||||
for C++ code. Compare stdfiles.c.
|
||||
(The difference is that here the vtable field is set to
|
||||
point to builtinbuf's vtable, so the objects are effectively
|
||||
of class builtinbuf.) */
|
||||
|
||||
#include "libioP.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if !defined(filebuf_vtable) && defined(__cplusplus)
|
||||
#ifdef __GNUC__
|
||||
extern char filebuf_vtable[]
|
||||
asm (_G_VTABLE_LABEL_PREFIX
|
||||
#if _G_VTABLE_LABEL_HAS_LENGTH
|
||||
"7"
|
||||
#endif
|
||||
"filebuf");
|
||||
#else /* !__GNUC__ */
|
||||
#if _G_VTABLE_LABEL_HAS_LENGTH
|
||||
#define filebuf_vtable _G_VTABLE_LABEL_PREFIX_ID##7filebuf
|
||||
#else
|
||||
#define filebuf_vtable _G_VTABLE_LABEL_PREFIX_ID##filebuf
|
||||
#endif
|
||||
extern char filebuf_vtable[];
|
||||
#endif /* !__GNUC__ */
|
||||
#endif /* !defined(filebuf_vtable) && defined(__cplusplus) */
|
||||
|
||||
#ifndef STD_VTABLE
|
||||
#define STD_VTABLE (const struct _IO_jump_t *)filebuf_vtable
|
||||
#endif
|
||||
|
||||
#ifdef _STDIO_USES_IOSTREAM
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
|
||||
struct _IO_FILE_plus NAME \
|
||||
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), STD_VTABLE}
|
||||
#else
|
||||
#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
|
||||
struct _IO_FILE_plus NAME = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), STD_VTABLE}
|
||||
#endif
|
||||
|
||||
DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
|
||||
DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS);
|
||||
DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_.file,
|
||||
_IO_NO_READS+_IO_UNBUFFERED);
|
||||
|
||||
_IO_FILE_plus *_IO_list_all = &_IO_stderr_;
|
||||
#else /* !_STDIO_USES_IOSTREAM */
|
||||
#include "stdiostream.h"
|
||||
|
||||
struct _IO_fake_stdiobuf {
|
||||
struct {
|
||||
_IO_FILE file;
|
||||
const void *vtable;
|
||||
} s;
|
||||
FILE *stdio_file;
|
||||
};
|
||||
|
||||
/* Define stdiobuf_vtable as a name for the virtual function table
|
||||
of the stdiobuf class. */
|
||||
#ifndef stdiobuf_vtable
|
||||
#ifdef __GNUC__
|
||||
extern struct _IO_jump_t stdiobuf_vtable
|
||||
asm (_G_VTABLE_LABEL_PREFIX
|
||||
#if _G_VTABLE_LABEL_HAS_LENGTH
|
||||
"8"
|
||||
#endif
|
||||
"stdiobuf");
|
||||
#else /* !__GNUC__ */
|
||||
#if _G_VTABLE_LABEL_HAS_LENGTH
|
||||
#define stdiobuf_vtable _G_VTABLE_LABEL_PREFIX_ID##8stdiobuf
|
||||
#else
|
||||
#define stdiobuf_vtable _G_VTABLE_LABEL_PREFIX_ID##stdiobuf
|
||||
#endif
|
||||
extern struct _IO_jump_t stdiobuf_vtable;
|
||||
#endif /* !__GNUC__ */
|
||||
#endif /* !stdiobuf_vtable */
|
||||
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
#define DEF_STDIOFILE(NAME, FD, FILE, FLAGS, CHAIN) \
|
||||
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
|
||||
struct _IO_fake_stdiobuf NAME = \
|
||||
{{{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+_IO_UNBUFFERED+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
|
||||
0, 0, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock},\
|
||||
&stdiobuf_vtable}, FILE}
|
||||
#else
|
||||
#define DEF_STDIOFILE(NAME, FD, FILE, FLAGS, CHAIN) \
|
||||
struct _IO_fake_stdiobuf NAME = \
|
||||
{{{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+_IO_UNBUFFERED+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD}, \
|
||||
&stdiobuf_vtable}, FILE}
|
||||
#endif
|
||||
|
||||
DEF_STDIOFILE(_IO_stdin_buf, 0, stdin, _IO_NO_WRITES, &_IO_stderr_.file);
|
||||
DEF_STDIOFILE(_IO_stdout_buf, 1, stdout, _IO_NO_READS, &_IO_stdin_buf.s.file);
|
||||
DEF_STDIOFILE(_IO_stderr_buf, 2, stderr, _IO_NO_READS, &_IO_stdout_buf.s.file);
|
||||
|
||||
_IO_FILE_plus *_IO_list_all
|
||||
= reinterpret_cast<_IO_FILE_plus*>(&_IO_stderr_buf.s);
|
||||
#endif /* !_STDIO_USES_IOSTREAM */
|
||||
@@ -0,0 +1,152 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#include "libioP.h"
|
||||
#include "streambuf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// The ANSI draft requires that operations on cin/cout/cerr can be
|
||||
// mixed with operations on stdin/stdout/stderr on a character by
|
||||
// character basis. This normally requires that the streambuf's
|
||||
// used by cin/cout/cerr be stdiostreams. However, if the stdio
|
||||
// implementation is the one that is built using this library,
|
||||
// then we don't need to, since in that case stdin/stdout/stderr
|
||||
// are identical to _IO_stdin/_IO_stdout/_IO_stderr.
|
||||
|
||||
#include <libio.h>
|
||||
|
||||
#ifdef _STDIO_USES_IOSTREAM
|
||||
#define CIN_SBUF _IO_stdin_
|
||||
#define COUT_SBUF _IO_stdout_
|
||||
#define CERR_SBUF _IO_stderr_
|
||||
#else
|
||||
#define CIN_SBUF _IO_stdin_buf
|
||||
#define COUT_SBUF _IO_stdout_buf
|
||||
#define CERR_SBUF _IO_stderr_buf
|
||||
static int use_stdiobuf = 1;
|
||||
#endif
|
||||
|
||||
#define cin CIN
|
||||
#define cout COUT
|
||||
#define cerr CERR
|
||||
#define clog CLOG
|
||||
#include "iostream.h"
|
||||
#undef cin
|
||||
#undef cout
|
||||
#undef cerr
|
||||
#undef clog
|
||||
|
||||
#ifdef __GNUG__
|
||||
#define PAD 0 /* g++ allows 0-length arrays. */
|
||||
#else
|
||||
#define PAD 1
|
||||
#endif
|
||||
struct _fake_istream {
|
||||
struct myfields {
|
||||
#ifdef __GNUC__
|
||||
_ios_fields *vb; /* pointer to virtual base class ios */
|
||||
_IO_ssize_t _gcount;
|
||||
#else
|
||||
/* This is supposedly correct for cfront. */
|
||||
_IO_ssize_t _gcount;
|
||||
void *vptr;
|
||||
_ios_fields *vb; /* pointer to virtual base class ios */
|
||||
#endif
|
||||
} mine;
|
||||
_ios_fields base;
|
||||
char filler[sizeof(struct istream)-sizeof(struct _ios_fields)+PAD];
|
||||
};
|
||||
struct _fake_ostream {
|
||||
struct myfields {
|
||||
#ifndef __GNUC__
|
||||
void *vptr;
|
||||
#endif
|
||||
_ios_fields *vb; /* pointer to virtual base class ios */
|
||||
} mine;
|
||||
_ios_fields base;
|
||||
char filler[sizeof(struct ostream)-sizeof(struct _ios_fields)+PAD];
|
||||
};
|
||||
|
||||
|
||||
#ifdef _IO_NEW_STREAMS
|
||||
#define STD_STR(SBUF, TIE, EXTRA_FLAGS) \
|
||||
(streambuf*)&SBUF, TIE, 0, ios::skipws|ios::dec|EXTRA_FLAGS, ' ',0,0,6
|
||||
#else
|
||||
#define STD_STR(SBUF, TIE, EXTRA_FLAGS) \
|
||||
(streambuf*)&SBUF, TIE, 0, ios::dont_close|ios::dec|ios::skipws|EXTRA_FLAGS, ' ',0,0,6
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define OSTREAM_DEF(NAME, SBUF, TIE, EXTRA_FLAGS, ASM) \
|
||||
_fake_ostream NAME ASM = { {&NAME.base}, {STD_STR(SBUF, TIE, EXTRA_FLAGS) }};
|
||||
#define ISTREAM_DEF(NAME, SBUF, TIE, EXTRA_FLAGS) \
|
||||
_fake_istream NAME = { {&NAME.base}, {STD_STR(SBUF, TIE, EXTRA_FLAGS) }};
|
||||
#else
|
||||
#define OSTREAM_DEF(NAME, SBUF, TIE, EXTRA_FLAGS) \
|
||||
_fake_ostream NAME = { {0, &NAME.base}, {STD_STR(SBUF, TIE, EXTRA_FLAGS) }};
|
||||
#define ISTREAM_DEF(NAME, SBUF, TIE, EXTRA_FLAGS) \
|
||||
_fake_istream NAME = {{0, 0, &NAME.base}, {STD_STR(SBUF, TIE, EXTRA_FLAGS)}};
|
||||
#endif
|
||||
|
||||
OSTREAM_DEF(cout, COUT_SBUF, NULL, 0, )
|
||||
OSTREAM_DEF(cerr, CERR_SBUF,(ostream*)&cout, ios::unitbuf, )
|
||||
ISTREAM_DEF(cin, CIN_SBUF, (ostream*)&cout, 0)
|
||||
|
||||
/* Only for (partial) compatibility with AT&T's library. */
|
||||
#if _G_CLOG_CONFLICT
|
||||
OSTREAM_DEF(clog, CERR_SBUF, (ostream*)&cout, 0, __asm__ ("__IO_clog"))
|
||||
#else
|
||||
OSTREAM_DEF(clog, CERR_SBUF, (ostream*)&cout, 0, )
|
||||
#endif
|
||||
|
||||
// Switches between using _IO_std{in,out,err} and __std{in,out,err}_buf
|
||||
// for standard streams. This does not normally need to be called
|
||||
// explicitly, but is provided for AT&T compatibility.
|
||||
|
||||
int ios::sync_with_stdio(int new_state)
|
||||
{
|
||||
#ifdef _STDIO_USES_IOSTREAM
|
||||
// It is always synced.
|
||||
return 0;
|
||||
#else
|
||||
if (new_state == use_stdiobuf) // The usual case now.
|
||||
return use_stdiobuf;
|
||||
if (new_state) {
|
||||
cin.base._strbuf = (streambuf*)&_IO_stdin_buf;
|
||||
cout.base._strbuf = (streambuf*)&_IO_stdout_buf;
|
||||
cerr.base._strbuf = (streambuf*)&_IO_stderr_buf;
|
||||
clog.base._strbuf = (streambuf*)&_IO_stderr_buf;
|
||||
} else {
|
||||
cin.base._strbuf = (streambuf*)_IO_stdin;
|
||||
cout.base._strbuf = (streambuf*)_IO_stdout;
|
||||
cerr.base._strbuf = (streambuf*)_IO_stderr;
|
||||
clog.base._strbuf = (streambuf*)_IO_stderr;
|
||||
}
|
||||
int old_state = use_stdiobuf;
|
||||
use_stdiobuf = new_state;
|
||||
return old_state;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Instantiation file for the -*- C++ -*- Standard Library allocator templates
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#include <alloc.h>
|
||||
|
||||
#ifndef __USE_MALLOC
|
||||
template class __default_alloc_template<__NODE_ALLOCATOR_THREADS, 0>;
|
||||
#endif
|
||||
|
||||
template class __malloc_alloc_template<0>;
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "libioP.h"
|
||||
#include "stream.h"
|
||||
#include "strstream.h"
|
||||
|
||||
static char Buffer[_IO_BUFSIZ];
|
||||
#define EndBuffer (Buffer+_IO_BUFSIZ)
|
||||
static char* next_chunk = Buffer; // Start of available part of Buffer.
|
||||
|
||||
char* form(const char* format, ...)
|
||||
{
|
||||
int space_left = EndBuffer - next_chunk;
|
||||
// If less that 25% of the space is available start over.
|
||||
if (space_left < (_IO_BUFSIZ>>2))
|
||||
next_chunk = Buffer;
|
||||
char* buf = next_chunk;
|
||||
|
||||
strstreambuf stream(buf, EndBuffer-buf-1, buf);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
stream.vform(format, ap);
|
||||
va_end(ap);
|
||||
stream.sputc(0);
|
||||
next_chunk = buf + stream.pcount();
|
||||
return buf;
|
||||
}
|
||||
|
||||
#define u_long unsigned long
|
||||
|
||||
static char* itoa(unsigned long i, int size, int neg, int base)
|
||||
{
|
||||
// Conservative estimate: If base==2, might need 8 characters
|
||||
// for each input byte, but normally 3 is plenty.
|
||||
int needed = size ? size
|
||||
: (base >= 8 ? 3 : 8) * sizeof(unsigned long) + 2;
|
||||
int space_left = EndBuffer - next_chunk;
|
||||
if (space_left <= needed)
|
||||
next_chunk = Buffer; // start over.
|
||||
|
||||
char* buf = next_chunk;
|
||||
|
||||
register char* ptr = buf+needed+1;
|
||||
next_chunk = ptr;
|
||||
|
||||
if (needed < (2+neg) || ptr > EndBuffer)
|
||||
return NULL;
|
||||
*--ptr = 0;
|
||||
|
||||
if (i == 0)
|
||||
*--ptr = '0';
|
||||
while (i != 0 && ptr > buf) {
|
||||
int ch = i % base;
|
||||
i = i / base;
|
||||
if (ch >= 10)
|
||||
ch += 'a' - 10;
|
||||
else
|
||||
ch += '0';
|
||||
*--ptr = ch;
|
||||
}
|
||||
if (neg)
|
||||
*--ptr = '-';
|
||||
if (size == 0)
|
||||
return ptr;
|
||||
while (ptr > buf)
|
||||
*--ptr = ' ';
|
||||
return buf;
|
||||
}
|
||||
|
||||
char* dec(long i, int len /* = 0 */)
|
||||
{
|
||||
if (i >= 0) return itoa((unsigned long)i, len, 0, 10);
|
||||
else return itoa((unsigned long)(-i), len, 1, 10);
|
||||
}
|
||||
char* dec(int i, int len /* = 0 */)
|
||||
{
|
||||
if (i >= 0) return itoa((unsigned long)i, len, 0, 10);
|
||||
else return itoa((unsigned long)(-i), len, 1, 10);
|
||||
}
|
||||
char* dec(unsigned long i, int len /* = 0 */)
|
||||
{
|
||||
return itoa(i, len, 0, 10);
|
||||
}
|
||||
char* dec(unsigned int i, int len /* = 0 */)
|
||||
{
|
||||
return itoa(i, len, 0, 10);
|
||||
}
|
||||
|
||||
char* hex(long i, int len /* = 0 */)
|
||||
{
|
||||
return itoa((unsigned long)i, len, 0, 16);
|
||||
}
|
||||
char* hex(int i, int len /* = 0 */)
|
||||
{
|
||||
return itoa((unsigned long)i, len, 0, 16);
|
||||
}
|
||||
char* hex(unsigned long i, int len /* = 0 */)
|
||||
{
|
||||
return itoa(i, len, 0, 16);
|
||||
}
|
||||
char* hex(unsigned int i, int len /* = 0 */)
|
||||
{
|
||||
return itoa(i, len, 0, 16);
|
||||
}
|
||||
|
||||
char* oct(long i, int len /* = 0 */)
|
||||
{
|
||||
return itoa((unsigned long)i, len, 0, 8);
|
||||
}
|
||||
char* oct(int i, int len /* = 0 */)
|
||||
{
|
||||
return itoa((unsigned long)i, len, 0, 8);
|
||||
}
|
||||
char* oct(unsigned long i, int len /* = 0 */)
|
||||
{
|
||||
return itoa(i, len, 0, 8);
|
||||
}
|
||||
char* oct(unsigned int i, int len /* = 0 */)
|
||||
{
|
||||
return itoa(i, len, 0, 8);
|
||||
}
|
||||
|
||||
static char *str(const char* s, int len, int width)
|
||||
{
|
||||
if (width < len)
|
||||
width = len;
|
||||
int space_left = EndBuffer - next_chunk;
|
||||
if (space_left <= width + 1)
|
||||
next_chunk = Buffer; // start over.
|
||||
char* buf = next_chunk;
|
||||
memset (buf, ' ', width - len);
|
||||
memcpy (buf + width - len, s, len);
|
||||
buf[width] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
char* str(const char* s, int width)
|
||||
{
|
||||
return str (s, strlen (s), width);
|
||||
}
|
||||
|
||||
char* chr(char ch, int width)
|
||||
{
|
||||
char c = ch;
|
||||
return str (&c, 1, width);
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1991, 1992, 1993, 1995 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#define _STREAM_COMPAT
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include "iostreamP.h"
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
void streambuf::_un_link() { _IO_un_link(reinterpret_cast<_IO_FILE_plus*>(this)); }
|
||||
|
||||
void streambuf::_link_in() { _IO_link_in(reinterpret_cast<_IO_FILE_plus*>(this)); }
|
||||
|
||||
int streambuf::switch_to_get_mode()
|
||||
{ return _IO_switch_to_get_mode(this); }
|
||||
|
||||
void streambuf::free_backup_area()
|
||||
{ _IO_free_backup_area(this); }
|
||||
|
||||
#if 0
|
||||
int streambuf::switch_to_put_mode()
|
||||
{ return _IO_:switch_to_put_mode(this); }
|
||||
#endif
|
||||
|
||||
int __overflow(streambuf* sb, int c)
|
||||
{
|
||||
return sb->overflow(c);
|
||||
}
|
||||
|
||||
int streambuf::underflow()
|
||||
{ return EOF; }
|
||||
|
||||
int streambuf::uflow()
|
||||
{ return _IO_default_uflow (this); }
|
||||
|
||||
int streambuf::overflow(int /* = EOF */)
|
||||
{ return EOF; }
|
||||
|
||||
streamsize streambuf::xsputn(register const char* s, streamsize n)
|
||||
{ return _IO_default_xsputn(this, s, n); }
|
||||
|
||||
streamsize streambuf::xsgetn(char* s, streamsize n)
|
||||
{ return _IO_default_xsgetn(this, s, n); }
|
||||
|
||||
int streambuf::ignore(int n)
|
||||
{
|
||||
register int more = n;
|
||||
for (;;) {
|
||||
int count = _IO_read_end - _IO_read_ptr; // Data available.
|
||||
if (count > 0) {
|
||||
if (count > more)
|
||||
count = more;
|
||||
_IO_read_ptr += count;
|
||||
more -= count;
|
||||
}
|
||||
if (more == 0 || __underflow(this) == EOF)
|
||||
break;
|
||||
}
|
||||
return n - more;
|
||||
}
|
||||
|
||||
int streambuf::sync()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int streambuf::pbackfail(int c)
|
||||
{
|
||||
return _IO_default_pbackfail(this, c);
|
||||
}
|
||||
|
||||
streambuf* streambuf::setbuf(char* p, int len)
|
||||
{
|
||||
if (sync() == EOF)
|
||||
return NULL;
|
||||
if (p == NULL || len == 0) {
|
||||
unbuffered(1);
|
||||
setb(_shortbuf, _shortbuf+1, 0);
|
||||
}
|
||||
else {
|
||||
unbuffered(0);
|
||||
setb(p, p+len, 0);
|
||||
}
|
||||
setp(0, 0);
|
||||
setg(0, 0, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
streampos streambuf::seekpos(streampos pos, int mode)
|
||||
{
|
||||
return seekoff(pos, ios::beg, mode);
|
||||
}
|
||||
|
||||
streampos streambuf::sseekpos(streampos pos, int mode)
|
||||
{
|
||||
return _IO_seekpos (this, pos, mode);
|
||||
}
|
||||
|
||||
void streambuf::setb(char* b, char* eb, int a)
|
||||
{ _IO_setb(this, b, eb, a); }
|
||||
|
||||
int streambuf::doallocate() { return _IO_default_doallocate(this); }
|
||||
|
||||
void streambuf::doallocbuf() { _IO_doallocbuf(this); }
|
||||
|
||||
#if !_IO_UNIFIED_JUMPTABLES
|
||||
/* The following are jump table entries that just call the virtual method */
|
||||
|
||||
static int _IO_sb_overflow(_IO_FILE *fp, int c)
|
||||
{ return ((streambuf*)fp)->overflow(c); }
|
||||
static int _IO_sb_underflow(_IO_FILE *fp)
|
||||
{ return ((streambuf*)fp)->underflow(); }
|
||||
static _IO_size_t _IO_sb_xsputn(_IO_FILE *fp, const void *s, _IO_size_t n)
|
||||
{ return ((streambuf*)fp)->xsputn((const char*)s, n); }
|
||||
static _IO_size_t _IO_sb_xsgetn(_IO_FILE *fp, void *s, _IO_size_t n)
|
||||
{ return ((streambuf*)fp)->xsgetn((char*)s, n); }
|
||||
static int _IO_sb_close(_IO_FILE *fp)
|
||||
{ return ((streambuf*)fp)->sys_close(); }
|
||||
static int _IO_sb_stat(_IO_FILE *fp, void *b)
|
||||
{ return ((streambuf*)fp)->sys_stat(b); }
|
||||
static int _IO_sb_doallocate(_IO_FILE *fp)
|
||||
{ return ((streambuf*)fp)->doallocate(); }
|
||||
|
||||
static _IO_pos_t _IO_sb_seekoff(_IO_FILE *fp, _IO_off_t pos, int dir, int mode)
|
||||
{
|
||||
return ((streambuf*)fp)->seekoff(pos, (ios::seek_dir)dir, mode);
|
||||
}
|
||||
|
||||
static _IO_pos_t _IO_sb_seekpos(_IO_FILE *fp, _IO_pos_t pos, int mode)
|
||||
{
|
||||
return ((streambuf*)fp)->seekpos(pos, mode);
|
||||
}
|
||||
|
||||
static int _IO_sb_pbackfail(_IO_FILE *fp, int ch)
|
||||
{ return ((streambuf*)fp)->pbackfail(ch); }
|
||||
static void _IO_sb_finish(_IO_FILE *fp, int)
|
||||
{ ((streambuf*)fp)->~streambuf(); }
|
||||
static _IO_ssize_t _IO_sb_read(_IO_FILE *fp, void *buf, _IO_ssize_t n)
|
||||
{ return ((streambuf*)fp)->sys_read((char*)buf, n); }
|
||||
static _IO_ssize_t _IO_sb_write(_IO_FILE *fp, const void *buf, _IO_ssize_t n)
|
||||
{ return ((streambuf*)fp)->sys_write((const char*)buf, n); }
|
||||
static int _IO_sb_sync(_IO_FILE *fp)
|
||||
{ return ((streambuf*)fp)->sync(); }
|
||||
static _IO_pos_t _IO_sb_seek(_IO_FILE *fp, _IO_off_t off, int dir)
|
||||
{ return ((streambuf*)fp)->sys_seek(off, (_seek_dir)dir); }
|
||||
static _IO_FILE* _IO_sb_setbuf(_IO_FILE *fp, char *buf, _IO_ssize_t n)
|
||||
{ return ((streambuf*)fp)->setbuf(buf, n); }
|
||||
|
||||
/* This callbacks in this jumptable just call the corresponding
|
||||
virtual function, so that C functions can access (potentially user-defined)
|
||||
streambuf-derived objects.
|
||||
Contrast the builtinbuf class, which does the converse: Allow
|
||||
C++ virtual calls to be used on _IO_FILE objects that are builtin
|
||||
(or defined by C code). */
|
||||
|
||||
|
||||
struct _IO_jump_t _IO_streambuf_jumps = {
|
||||
JUMP_INIT_DUMMY,
|
||||
JUMP_INIT(finish, _IO_sb_finish),
|
||||
JUMP_INIT(overflow, _IO_sb_overflow),
|
||||
JUMP_INIT(underflow, _IO_sb_underflow),
|
||||
JUMP_INIT(uflow, _IO_default_uflow),
|
||||
JUMP_INIT(pbackfail, _IO_sb_pbackfail),
|
||||
JUMP_INIT(xsputn, _IO_sb_xsputn),
|
||||
JUMP_INIT(xsgetn, _IO_sb_xsgetn),
|
||||
JUMP_INIT(seekoff, _IO_sb_seekoff),
|
||||
JUMP_INIT(seekpos, _IO_sb_seekpos),
|
||||
JUMP_INIT(setbuf, _IO_sb_setbuf),
|
||||
JUMP_INIT(sync, _IO_sb_sync),
|
||||
JUMP_INIT(doallocate, _IO_sb_doallocate),
|
||||
JUMP_INIT(read, _IO_sb_read),
|
||||
JUMP_INIT(write, _IO_sb_write),
|
||||
JUMP_INIT(seek, _IO_sb_seek),
|
||||
JUMP_INIT(close, _IO_sb_close),
|
||||
JUMP_INIT(stat, _IO_sb_stat)
|
||||
};
|
||||
#endif
|
||||
|
||||
streambuf::streambuf(int flags)
|
||||
{
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
_lock = new _IO_lock_t;
|
||||
#endif
|
||||
_IO_init(this, flags);
|
||||
#if !_IO_UNIFIED_JUMPTABLES
|
||||
_jumps = &_IO_streambuf_jumps;
|
||||
#endif
|
||||
}
|
||||
|
||||
streambuf::~streambuf()
|
||||
{
|
||||
_IO_default_finish(this,0);
|
||||
#ifdef _IO_MTSAFE_IO
|
||||
if (this != _IO_stdin && this != _IO_stdout && this != _IO_stderr)
|
||||
delete _lock;
|
||||
#endif
|
||||
}
|
||||
|
||||
streampos
|
||||
streambuf::seekoff(streamoff, _seek_dir, int /*=ios::in|ios::out*/)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
|
||||
streampos
|
||||
streambuf::sseekoff(streamoff o , _seek_dir d, int m /*=ios::in|ios::out*/)
|
||||
{
|
||||
return _IO_seekoff (this, o, d, m);
|
||||
}
|
||||
|
||||
int streambuf::sputbackc(char c)
|
||||
{
|
||||
return _IO_sputbackc(this, c);
|
||||
}
|
||||
|
||||
int streambuf::sungetc()
|
||||
{
|
||||
return _IO_sungetc(this);
|
||||
}
|
||||
|
||||
#if 0 /* Work in progress */
|
||||
void streambuf::collumn(int c)
|
||||
{
|
||||
if (c == -1)
|
||||
_collumn = -1;
|
||||
else
|
||||
_collumn = c - (_IO_write_ptr - _IO_write_base);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int streambuf::get_column()
|
||||
{
|
||||
if (_cur_column)
|
||||
return _IO_adjust_column(_cur_column - 1, pbase(), pptr() - pbase());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int streambuf::set_column(int i)
|
||||
{
|
||||
_cur_column = i+1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int streambuf::flush_all() { return _IO_flush_all (); }
|
||||
|
||||
void streambuf::flush_all_linebuffered()
|
||||
{ _IO_flush_all_linebuffered(); }
|
||||
|
||||
int streambuf::sys_stat(void *)
|
||||
{
|
||||
#ifdef EIO
|
||||
errno = EIO;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
streamsize streambuf::sys_read(char* /*buf*/, streamsize /*size*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
streamsize streambuf::sys_write(const char* /*buf*/, streamsize /*size*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
streampos streambuf::sys_seek(streamoff, _seek_dir)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
|
||||
int streambuf::sys_close() { return 0; /* Suceess; do nothing */ }
|
||||
|
||||
#if _G_IO_IO_FILE_VERSION == 0x20001
|
||||
int streambuf::showmanyc()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void streambuf::imbue(void *)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
streammarker::streammarker(streambuf *sb)
|
||||
{
|
||||
_IO_init_marker(this, sb);
|
||||
}
|
||||
|
||||
streammarker::~streammarker()
|
||||
{
|
||||
_IO_remove_marker(this);
|
||||
}
|
||||
|
||||
#define BAD_DELTA EOF
|
||||
|
||||
int streammarker::delta(streammarker& other_mark)
|
||||
{
|
||||
return _IO_marker_difference(this, &other_mark);
|
||||
}
|
||||
|
||||
int streammarker::delta()
|
||||
{
|
||||
return _IO_marker_delta(this);
|
||||
}
|
||||
|
||||
int streambuf::seekmark(streammarker& mark, int delta /* = 0 */)
|
||||
{
|
||||
return _IO_seekmark(this, &mark, delta);
|
||||
}
|
||||
|
||||
void streambuf::unsave_markers()
|
||||
{
|
||||
_IO_unsave_markers(this);
|
||||
}
|
||||
|
||||
int ios::readable() { return !(rdbuf()->_flags & _IO_NO_READS); }
|
||||
int ios::writable() { return !(rdbuf()->_flags & _IO_NO_WRITES); }
|
||||
int ios::is_open() { return rdbuf()
|
||||
&& (rdbuf()->_flags & _IO_NO_READS+_IO_NO_WRITES)
|
||||
!= _IO_NO_READS+_IO_NO_WRITES; }
|
||||
|
||||
#if defined(linux)
|
||||
#define IO_CLEANUP
|
||||
#endif
|
||||
|
||||
#ifdef IO_CLEANUP
|
||||
IO_CLEANUP
|
||||
#else
|
||||
struct __io_defs {
|
||||
~__io_defs() { _IO_cleanup (); }
|
||||
};
|
||||
__io_defs io_defs__;
|
||||
#endif
|
||||
@@ -0,0 +1,831 @@
|
||||
/* Extended support for using errno values.
|
||||
Written by Fred Fish. fnf@cygnus.com
|
||||
This file is in the public domain. --Per Bothner. */
|
||||
|
||||
#include "ansidecl.h"
|
||||
#include "libiberty.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_SYS_ERRLIST
|
||||
/* Note that errno.h (not sure what OS) or stdio.h (BSD 4.4, at least)
|
||||
might declare sys_errlist in a way that the compiler might consider
|
||||
incompatible with our later declaration, perhaps by using const
|
||||
attributes. So we hide the declaration in errno.h (if any) using a
|
||||
macro. */
|
||||
#define sys_errlist sys_errlist__
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_SYS_ERRLIST
|
||||
#undef sys_errlist
|
||||
#endif
|
||||
|
||||
/* Routines imported from standard C runtime libraries. */
|
||||
|
||||
#ifdef __STDC__
|
||||
#include <stddef.h>
|
||||
extern void *malloc (size_t size); /* 4.10.3.3 */
|
||||
extern void *memset (void *s, int c, size_t n); /* 4.11.6.1 */
|
||||
#else /* !__STDC__ */
|
||||
extern char *malloc (); /* Standard memory allocater */
|
||||
extern char *memset ();
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
static void init_error_tables PARAMS ((void));
|
||||
|
||||
/* Translation table for errno values. See intro(2) in most UNIX systems
|
||||
Programmers Reference Manuals.
|
||||
|
||||
Note that this table is generally only accessed when it is used at runtime
|
||||
to initialize errno name and message tables that are indexed by errno
|
||||
value.
|
||||
|
||||
Not all of these errnos will exist on all systems. This table is the only
|
||||
thing that should have to be updated as new error numbers are introduced.
|
||||
It's sort of ugly, but at least its portable. */
|
||||
|
||||
struct error_info
|
||||
{
|
||||
int value; /* The numeric value from <errno.h> */
|
||||
const char *name; /* The equivalent symbolic value */
|
||||
#ifndef HAVE_SYS_ERRLIST
|
||||
const char *msg; /* Short message about this value */
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef HAVE_SYS_ERRLIST
|
||||
# define ENTRY(value, name, msg) {value, name, msg}
|
||||
#else
|
||||
# define ENTRY(value, name, msg) {value, name}
|
||||
#endif
|
||||
|
||||
static const struct error_info error_table[] =
|
||||
{
|
||||
#if defined (EPERM)
|
||||
ENTRY(EPERM, "EPERM", "Not owner"),
|
||||
#endif
|
||||
#if defined (ENOENT)
|
||||
ENTRY(ENOENT, "ENOENT", "No such file or directory"),
|
||||
#endif
|
||||
#if defined (ESRCH)
|
||||
ENTRY(ESRCH, "ESRCH", "No such process"),
|
||||
#endif
|
||||
#if defined (EINTR)
|
||||
ENTRY(EINTR, "EINTR", "Interrupted system call"),
|
||||
#endif
|
||||
#if defined (EIO)
|
||||
ENTRY(EIO, "EIO", "I/O error"),
|
||||
#endif
|
||||
#if defined (ENXIO)
|
||||
ENTRY(ENXIO, "ENXIO", "No such device or address"),
|
||||
#endif
|
||||
#if defined (E2BIG)
|
||||
ENTRY(E2BIG, "E2BIG", "Arg list too long"),
|
||||
#endif
|
||||
#if defined (ENOEXEC)
|
||||
ENTRY(ENOEXEC, "ENOEXEC", "Exec format error"),
|
||||
#endif
|
||||
#if defined (EBADF)
|
||||
ENTRY(EBADF, "EBADF", "Bad file number"),
|
||||
#endif
|
||||
#if defined (ECHILD)
|
||||
ENTRY(ECHILD, "ECHILD", "No child processes"),
|
||||
#endif
|
||||
#if defined (EWOULDBLOCK) /* Put before EAGAIN, sometimes aliased */
|
||||
ENTRY(EWOULDBLOCK, "EWOULDBLOCK", "Operation would block"),
|
||||
#endif
|
||||
#if defined (EAGAIN)
|
||||
ENTRY(EAGAIN, "EAGAIN", "No more processes"),
|
||||
#endif
|
||||
#if defined (ENOMEM)
|
||||
ENTRY(ENOMEM, "ENOMEM", "Not enough space"),
|
||||
#endif
|
||||
#if defined (EACCES)
|
||||
ENTRY(EACCES, "EACCES", "Permission denied"),
|
||||
#endif
|
||||
#if defined (EFAULT)
|
||||
ENTRY(EFAULT, "EFAULT", "Bad address"),
|
||||
#endif
|
||||
#if defined (ENOTBLK)
|
||||
ENTRY(ENOTBLK, "ENOTBLK", "Block device required"),
|
||||
#endif
|
||||
#if defined (EBUSY)
|
||||
ENTRY(EBUSY, "EBUSY", "Device busy"),
|
||||
#endif
|
||||
#if defined (EEXIST)
|
||||
ENTRY(EEXIST, "EEXIST", "File exists"),
|
||||
#endif
|
||||
#if defined (EXDEV)
|
||||
ENTRY(EXDEV, "EXDEV", "Cross-device link"),
|
||||
#endif
|
||||
#if defined (ENODEV)
|
||||
ENTRY(ENODEV, "ENODEV", "No such device"),
|
||||
#endif
|
||||
#if defined (ENOTDIR)
|
||||
ENTRY(ENOTDIR, "ENOTDIR", "Not a directory"),
|
||||
#endif
|
||||
#if defined (EISDIR)
|
||||
ENTRY(EISDIR, "EISDIR", "Is a directory"),
|
||||
#endif
|
||||
#if defined (EINVAL)
|
||||
ENTRY(EINVAL, "EINVAL", "Invalid argument"),
|
||||
#endif
|
||||
#if defined (ENFILE)
|
||||
ENTRY(ENFILE, "ENFILE", "File table overflow"),
|
||||
#endif
|
||||
#if defined (EMFILE)
|
||||
ENTRY(EMFILE, "EMFILE", "Too many open files"),
|
||||
#endif
|
||||
#if defined (ENOTTY)
|
||||
ENTRY(ENOTTY, "ENOTTY", "Not a typewriter"),
|
||||
#endif
|
||||
#if defined (ETXTBSY)
|
||||
ENTRY(ETXTBSY, "ETXTBSY", "Text file busy"),
|
||||
#endif
|
||||
#if defined (EFBIG)
|
||||
ENTRY(EFBIG, "EFBIG", "File too large"),
|
||||
#endif
|
||||
#if defined (ENOSPC)
|
||||
ENTRY(ENOSPC, "ENOSPC", "No space left on device"),
|
||||
#endif
|
||||
#if defined (ESPIPE)
|
||||
ENTRY(ESPIPE, "ESPIPE", "Illegal seek"),
|
||||
#endif
|
||||
#if defined (EROFS)
|
||||
ENTRY(EROFS, "EROFS", "Read-only file system"),
|
||||
#endif
|
||||
#if defined (EMLINK)
|
||||
ENTRY(EMLINK, "EMLINK", "Too many links"),
|
||||
#endif
|
||||
#if defined (EPIPE)
|
||||
ENTRY(EPIPE, "EPIPE", "Broken pipe"),
|
||||
#endif
|
||||
#if defined (EDOM)
|
||||
ENTRY(EDOM, "EDOM", "Math argument out of domain of func"),
|
||||
#endif
|
||||
#if defined (ERANGE)
|
||||
ENTRY(ERANGE, "ERANGE", "Math result not representable"),
|
||||
#endif
|
||||
#if defined (ENOMSG)
|
||||
ENTRY(ENOMSG, "ENOMSG", "No message of desired type"),
|
||||
#endif
|
||||
#if defined (EIDRM)
|
||||
ENTRY(EIDRM, "EIDRM", "Identifier removed"),
|
||||
#endif
|
||||
#if defined (ECHRNG)
|
||||
ENTRY(ECHRNG, "ECHRNG", "Channel number out of range"),
|
||||
#endif
|
||||
#if defined (EL2NSYNC)
|
||||
ENTRY(EL2NSYNC, "EL2NSYNC", "Level 2 not synchronized"),
|
||||
#endif
|
||||
#if defined (EL3HLT)
|
||||
ENTRY(EL3HLT, "EL3HLT", "Level 3 halted"),
|
||||
#endif
|
||||
#if defined (EL3RST)
|
||||
ENTRY(EL3RST, "EL3RST", "Level 3 reset"),
|
||||
#endif
|
||||
#if defined (ELNRNG)
|
||||
ENTRY(ELNRNG, "ELNRNG", "Link number out of range"),
|
||||
#endif
|
||||
#if defined (EUNATCH)
|
||||
ENTRY(EUNATCH, "EUNATCH", "Protocol driver not attached"),
|
||||
#endif
|
||||
#if defined (ENOCSI)
|
||||
ENTRY(ENOCSI, "ENOCSI", "No CSI structure available"),
|
||||
#endif
|
||||
#if defined (EL2HLT)
|
||||
ENTRY(EL2HLT, "EL2HLT", "Level 2 halted"),
|
||||
#endif
|
||||
#if defined (EDEADLK)
|
||||
ENTRY(EDEADLK, "EDEADLK", "Deadlock condition"),
|
||||
#endif
|
||||
#if defined (ENOLCK)
|
||||
ENTRY(ENOLCK, "ENOLCK", "No record locks available"),
|
||||
#endif
|
||||
#if defined (EBADE)
|
||||
ENTRY(EBADE, "EBADE", "Invalid exchange"),
|
||||
#endif
|
||||
#if defined (EBADR)
|
||||
ENTRY(EBADR, "EBADR", "Invalid request descriptor"),
|
||||
#endif
|
||||
#if defined (EXFULL)
|
||||
ENTRY(EXFULL, "EXFULL", "Exchange full"),
|
||||
#endif
|
||||
#if defined (ENOANO)
|
||||
ENTRY(ENOANO, "ENOANO", "No anode"),
|
||||
#endif
|
||||
#if defined (EBADRQC)
|
||||
ENTRY(EBADRQC, "EBADRQC", "Invalid request code"),
|
||||
#endif
|
||||
#if defined (EBADSLT)
|
||||
ENTRY(EBADSLT, "EBADSLT", "Invalid slot"),
|
||||
#endif
|
||||
#if defined (EDEADLOCK)
|
||||
ENTRY(EDEADLOCK, "EDEADLOCK", "File locking deadlock error"),
|
||||
#endif
|
||||
#if defined (EBFONT)
|
||||
ENTRY(EBFONT, "EBFONT", "Bad font file format"),
|
||||
#endif
|
||||
#if defined (ENOSTR)
|
||||
ENTRY(ENOSTR, "ENOSTR", "Device not a stream"),
|
||||
#endif
|
||||
#if defined (ENODATA)
|
||||
ENTRY(ENODATA, "ENODATA", "No data available"),
|
||||
#endif
|
||||
#if defined (ETIME)
|
||||
ENTRY(ETIME, "ETIME", "Timer expired"),
|
||||
#endif
|
||||
#if defined (ENOSR)
|
||||
ENTRY(ENOSR, "ENOSR", "Out of streams resources"),
|
||||
#endif
|
||||
#if defined (ENONET)
|
||||
ENTRY(ENONET, "ENONET", "Machine is not on the network"),
|
||||
#endif
|
||||
#if defined (ENOPKG)
|
||||
ENTRY(ENOPKG, "ENOPKG", "Package not installed"),
|
||||
#endif
|
||||
#if defined (EREMOTE)
|
||||
ENTRY(EREMOTE, "EREMOTE", "Object is remote"),
|
||||
#endif
|
||||
#if defined (ENOLINK)
|
||||
ENTRY(ENOLINK, "ENOLINK", "Link has been severed"),
|
||||
#endif
|
||||
#if defined (EADV)
|
||||
ENTRY(EADV, "EADV", "Advertise error"),
|
||||
#endif
|
||||
#if defined (ESRMNT)
|
||||
ENTRY(ESRMNT, "ESRMNT", "Srmount error"),
|
||||
#endif
|
||||
#if defined (ECOMM)
|
||||
ENTRY(ECOMM, "ECOMM", "Communication error on send"),
|
||||
#endif
|
||||
#if defined (EPROTO)
|
||||
ENTRY(EPROTO, "EPROTO", "Protocol error"),
|
||||
#endif
|
||||
#if defined (EMULTIHOP)
|
||||
ENTRY(EMULTIHOP, "EMULTIHOP", "Multihop attempted"),
|
||||
#endif
|
||||
#if defined (EDOTDOT)
|
||||
ENTRY(EDOTDOT, "EDOTDOT", "RFS specific error"),
|
||||
#endif
|
||||
#if defined (EBADMSG)
|
||||
ENTRY(EBADMSG, "EBADMSG", "Not a data message"),
|
||||
#endif
|
||||
#if defined (ENAMETOOLONG)
|
||||
ENTRY(ENAMETOOLONG, "ENAMETOOLONG", "File name too long"),
|
||||
#endif
|
||||
#if defined (EOVERFLOW)
|
||||
ENTRY(EOVERFLOW, "EOVERFLOW", "Value too large for defined data type"),
|
||||
#endif
|
||||
#if defined (ENOTUNIQ)
|
||||
ENTRY(ENOTUNIQ, "ENOTUNIQ", "Name not unique on network"),
|
||||
#endif
|
||||
#if defined (EBADFD)
|
||||
ENTRY(EBADFD, "EBADFD", "File descriptor in bad state"),
|
||||
#endif
|
||||
#if defined (EREMCHG)
|
||||
ENTRY(EREMCHG, "EREMCHG", "Remote address changed"),
|
||||
#endif
|
||||
#if defined (ELIBACC)
|
||||
ENTRY(ELIBACC, "ELIBACC", "Can not access a needed shared library"),
|
||||
#endif
|
||||
#if defined (ELIBBAD)
|
||||
ENTRY(ELIBBAD, "ELIBBAD", "Accessing a corrupted shared library"),
|
||||
#endif
|
||||
#if defined (ELIBSCN)
|
||||
ENTRY(ELIBSCN, "ELIBSCN", ".lib section in a.out corrupted"),
|
||||
#endif
|
||||
#if defined (ELIBMAX)
|
||||
ENTRY(ELIBMAX, "ELIBMAX", "Attempting to link in too many shared libraries"),
|
||||
#endif
|
||||
#if defined (ELIBEXEC)
|
||||
ENTRY(ELIBEXEC, "ELIBEXEC", "Cannot exec a shared library directly"),
|
||||
#endif
|
||||
#if defined (EILSEQ)
|
||||
ENTRY(EILSEQ, "EILSEQ", "Illegal byte sequence"),
|
||||
#endif
|
||||
#if defined (ENOSYS)
|
||||
ENTRY(ENOSYS, "ENOSYS", "Operation not applicable"),
|
||||
#endif
|
||||
#if defined (ELOOP)
|
||||
ENTRY(ELOOP, "ELOOP", "Too many symbolic links encountered"),
|
||||
#endif
|
||||
#if defined (ERESTART)
|
||||
ENTRY(ERESTART, "ERESTART", "Interrupted system call should be restarted"),
|
||||
#endif
|
||||
#if defined (ESTRPIPE)
|
||||
ENTRY(ESTRPIPE, "ESTRPIPE", "Streams pipe error"),
|
||||
#endif
|
||||
#if defined (ENOTEMPTY)
|
||||
ENTRY(ENOTEMPTY, "ENOTEMPTY", "Directory not empty"),
|
||||
#endif
|
||||
#if defined (EUSERS)
|
||||
ENTRY(EUSERS, "EUSERS", "Too many users"),
|
||||
#endif
|
||||
#if defined (ENOTSOCK)
|
||||
ENTRY(ENOTSOCK, "ENOTSOCK", "Socket operation on non-socket"),
|
||||
#endif
|
||||
#if defined (EDESTADDRREQ)
|
||||
ENTRY(EDESTADDRREQ, "EDESTADDRREQ", "Destination address required"),
|
||||
#endif
|
||||
#if defined (EMSGSIZE)
|
||||
ENTRY(EMSGSIZE, "EMSGSIZE", "Message too long"),
|
||||
#endif
|
||||
#if defined (EPROTOTYPE)
|
||||
ENTRY(EPROTOTYPE, "EPROTOTYPE", "Protocol wrong type for socket"),
|
||||
#endif
|
||||
#if defined (ENOPROTOOPT)
|
||||
ENTRY(ENOPROTOOPT, "ENOPROTOOPT", "Protocol not available"),
|
||||
#endif
|
||||
#if defined (EPROTONOSUPPORT)
|
||||
ENTRY(EPROTONOSUPPORT, "EPROTONOSUPPORT", "Protocol not supported"),
|
||||
#endif
|
||||
#if defined (ESOCKTNOSUPPORT)
|
||||
ENTRY(ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT", "Socket type not supported"),
|
||||
#endif
|
||||
#if defined (EOPNOTSUPP)
|
||||
ENTRY(EOPNOTSUPP, "EOPNOTSUPP", "Operation not supported on transport endpoint"),
|
||||
#endif
|
||||
#if defined (EPFNOSUPPORT)
|
||||
ENTRY(EPFNOSUPPORT, "EPFNOSUPPORT", "Protocol family not supported"),
|
||||
#endif
|
||||
#if defined (EAFNOSUPPORT)
|
||||
ENTRY(EAFNOSUPPORT, "EAFNOSUPPORT", "Address family not supported by protocol"),
|
||||
#endif
|
||||
#if defined (EADDRINUSE)
|
||||
ENTRY(EADDRINUSE, "EADDRINUSE", "Address already in use"),
|
||||
#endif
|
||||
#if defined (EADDRNOTAVAIL)
|
||||
ENTRY(EADDRNOTAVAIL, "EADDRNOTAVAIL","Cannot assign requested address"),
|
||||
#endif
|
||||
#if defined (ENETDOWN)
|
||||
ENTRY(ENETDOWN, "ENETDOWN", "Network is down"),
|
||||
#endif
|
||||
#if defined (ENETUNREACH)
|
||||
ENTRY(ENETUNREACH, "ENETUNREACH", "Network is unreachable"),
|
||||
#endif
|
||||
#if defined (ENETRESET)
|
||||
ENTRY(ENETRESET, "ENETRESET", "Network dropped connection because of reset"),
|
||||
#endif
|
||||
#if defined (ECONNABORTED)
|
||||
ENTRY(ECONNABORTED, "ECONNABORTED", "Software caused connection abort"),
|
||||
#endif
|
||||
#if defined (ECONNRESET)
|
||||
ENTRY(ECONNRESET, "ECONNRESET", "Connection reset by peer"),
|
||||
#endif
|
||||
#if defined (ENOBUFS)
|
||||
ENTRY(ENOBUFS, "ENOBUFS", "No buffer space available"),
|
||||
#endif
|
||||
#if defined (EISCONN)
|
||||
ENTRY(EISCONN, "EISCONN", "Transport endpoint is already connected"),
|
||||
#endif
|
||||
#if defined (ENOTCONN)
|
||||
ENTRY(ENOTCONN, "ENOTCONN", "Transport endpoint is not connected"),
|
||||
#endif
|
||||
#if defined (ESHUTDOWN)
|
||||
ENTRY(ESHUTDOWN, "ESHUTDOWN", "Cannot send after transport endpoint shutdown"),
|
||||
#endif
|
||||
#if defined (ETOOMANYREFS)
|
||||
ENTRY(ETOOMANYREFS, "ETOOMANYREFS", "Too many references: cannot splice"),
|
||||
#endif
|
||||
#if defined (ETIMEDOUT)
|
||||
ENTRY(ETIMEDOUT, "ETIMEDOUT", "Connection timed out"),
|
||||
#endif
|
||||
#if defined (ECONNREFUSED)
|
||||
ENTRY(ECONNREFUSED, "ECONNREFUSED", "Connection refused"),
|
||||
#endif
|
||||
#if defined (EHOSTDOWN)
|
||||
ENTRY(EHOSTDOWN, "EHOSTDOWN", "Host is down"),
|
||||
#endif
|
||||
#if defined (EHOSTUNREACH)
|
||||
ENTRY(EHOSTUNREACH, "EHOSTUNREACH", "No route to host"),
|
||||
#endif
|
||||
#if defined (EALREADY)
|
||||
ENTRY(EALREADY, "EALREADY", "Operation already in progress"),
|
||||
#endif
|
||||
#if defined (EINPROGRESS)
|
||||
ENTRY(EINPROGRESS, "EINPROGRESS", "Operation now in progress"),
|
||||
#endif
|
||||
#if defined (ESTALE)
|
||||
ENTRY(ESTALE, "ESTALE", "Stale NFS file handle"),
|
||||
#endif
|
||||
#if defined (EUCLEAN)
|
||||
ENTRY(EUCLEAN, "EUCLEAN", "Structure needs cleaning"),
|
||||
#endif
|
||||
#if defined (ENOTNAM)
|
||||
ENTRY(ENOTNAM, "ENOTNAM", "Not a XENIX named type file"),
|
||||
#endif
|
||||
#if defined (ENAVAIL)
|
||||
ENTRY(ENAVAIL, "ENAVAIL", "No XENIX semaphores available"),
|
||||
#endif
|
||||
#if defined (EISNAM)
|
||||
ENTRY(EISNAM, "EISNAM", "Is a named type file"),
|
||||
#endif
|
||||
#if defined (EREMOTEIO)
|
||||
ENTRY(EREMOTEIO, "EREMOTEIO", "Remote I/O error"),
|
||||
#endif
|
||||
ENTRY(0, NULL, NULL)
|
||||
};
|
||||
|
||||
#ifdef EVMSERR
|
||||
/* This is not in the table, because the numeric value of EVMSERR (32767)
|
||||
lies outside the range of sys_errlist[]. */
|
||||
static struct { int value; const char *name, *msg; }
|
||||
evmserr = { EVMSERR, "EVMSERR", "VMS-specific error" };
|
||||
#endif
|
||||
|
||||
/* Translation table allocated and initialized at runtime. Indexed by the
|
||||
errno value to find the equivalent symbolic value. */
|
||||
|
||||
static const char **error_names;
|
||||
static int num_error_names = 0;
|
||||
|
||||
/* Translation table allocated and initialized at runtime, if it does not
|
||||
already exist in the host environment. Indexed by the errno value to find
|
||||
the descriptive string.
|
||||
|
||||
We don't export it for use in other modules because even though it has the
|
||||
same name, it differs from other implementations in that it is dynamically
|
||||
initialized rather than statically initialized. */
|
||||
|
||||
#ifndef HAVE_SYS_ERRLIST
|
||||
|
||||
static int sys_nerr;
|
||||
static const char **sys_errlist;
|
||||
|
||||
#else
|
||||
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
|
||||
NAME
|
||||
|
||||
init_error_tables -- initialize the name and message tables
|
||||
|
||||
SYNOPSIS
|
||||
|
||||
static void init_error_tables ();
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Using the error_table, which is initialized at compile time, generate
|
||||
the error_names and the sys_errlist (if needed) tables, which are
|
||||
indexed at runtime by a specific errno value.
|
||||
|
||||
BUGS
|
||||
|
||||
The initialization of the tables may fail under low memory conditions,
|
||||
in which case we don't do anything particularly useful, but we don't
|
||||
bomb either. Who knows, it might succeed at a later point if we free
|
||||
some memory in the meantime. In any case, the other routines know
|
||||
how to deal with lack of a table after trying to initialize it. This
|
||||
may or may not be considered to be a bug, that we don't specifically
|
||||
warn about this particular failure mode.
|
||||
|
||||
*/
|
||||
|
||||
static void
|
||||
init_error_tables ()
|
||||
{
|
||||
const struct error_info *eip;
|
||||
int nbytes;
|
||||
|
||||
/* If we haven't already scanned the error_table once to find the maximum
|
||||
errno value, then go find it now. */
|
||||
|
||||
if (num_error_names == 0)
|
||||
{
|
||||
for (eip = error_table; eip -> name != NULL; eip++)
|
||||
{
|
||||
if (eip -> value >= num_error_names)
|
||||
{
|
||||
num_error_names = eip -> value + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now attempt to allocate the error_names table, zero it out, and then
|
||||
initialize it from the statically initialized error_table. */
|
||||
|
||||
if (error_names == NULL)
|
||||
{
|
||||
nbytes = num_error_names * sizeof (char *);
|
||||
if ((error_names = (const char **) malloc (nbytes)) != NULL)
|
||||
{
|
||||
memset (error_names, 0, nbytes);
|
||||
for (eip = error_table; eip -> name != NULL; eip++)
|
||||
{
|
||||
error_names[eip -> value] = eip -> name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef HAVE_SYS_ERRLIST
|
||||
|
||||
/* Now attempt to allocate the sys_errlist table, zero it out, and then
|
||||
initialize it from the statically initialized error_table. */
|
||||
|
||||
if (sys_errlist == NULL)
|
||||
{
|
||||
nbytes = num_error_names * sizeof (char *);
|
||||
if ((sys_errlist = (const char **) malloc (nbytes)) != NULL)
|
||||
{
|
||||
memset (sys_errlist, 0, nbytes);
|
||||
sys_nerr = num_error_names;
|
||||
for (eip = error_table; eip -> name != NULL; eip++)
|
||||
{
|
||||
sys_errlist[eip -> value] = eip -> msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
NAME
|
||||
|
||||
errno_max -- return the max errno value
|
||||
|
||||
SYNOPSIS
|
||||
|
||||
int errno_max ();
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Returns the maximum errno value for which a corresponding symbolic
|
||||
name or message is available. Note that in the case where
|
||||
we use the sys_errlist supplied by the system, it is possible for
|
||||
there to be more symbolic names than messages, or vice versa.
|
||||
In fact, the manual page for perror(3C) explicitly warns that one
|
||||
should check the size of the table (sys_nerr) before indexing it,
|
||||
since new error codes may be added to the system before they are
|
||||
added to the table. Thus sys_nerr might be smaller than value
|
||||
implied by the largest errno value defined in <errno.h>.
|
||||
|
||||
We return the maximum value that can be used to obtain a meaningful
|
||||
symbolic name or message.
|
||||
|
||||
*/
|
||||
|
||||
int
|
||||
errno_max ()
|
||||
{
|
||||
int maxsize;
|
||||
|
||||
if (error_names == NULL)
|
||||
{
|
||||
init_error_tables ();
|
||||
}
|
||||
maxsize = MAX (sys_nerr, num_error_names);
|
||||
return (maxsize - 1);
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
|
||||
/*
|
||||
|
||||
NAME
|
||||
|
||||
strerror -- map an error number to an error message string
|
||||
|
||||
SYNOPSIS
|
||||
|
||||
char *strerror (int errnoval)
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Maps an errno number to an error message string, the contents of
|
||||
which are implementation defined. On systems which have the external
|
||||
variables sys_nerr and sys_errlist, these strings will be the same
|
||||
as the ones used by perror().
|
||||
|
||||
If the supplied error number is within the valid range of indices
|
||||
for the sys_errlist, but no message is available for the particular
|
||||
error number, then returns the string "Error NUM", where NUM is the
|
||||
error number.
|
||||
|
||||
If the supplied error number is not a valid index into sys_errlist,
|
||||
returns NULL.
|
||||
|
||||
The returned string is only guaranteed to be valid only until the
|
||||
next call to strerror.
|
||||
|
||||
*/
|
||||
|
||||
char *
|
||||
strerror (errnoval)
|
||||
int errnoval;
|
||||
{
|
||||
char *msg;
|
||||
static char buf[32];
|
||||
|
||||
#ifndef HAVE_SYS_ERRLIST
|
||||
|
||||
if (error_names == NULL)
|
||||
{
|
||||
init_error_tables ();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if ((errnoval < 0) || (errnoval >= sys_nerr))
|
||||
{
|
||||
#ifdef EVMSERR
|
||||
if (errnoval == evmserr.value)
|
||||
msg = evmserr.msg;
|
||||
else
|
||||
#endif
|
||||
/* Out of range, just return NULL */
|
||||
msg = NULL;
|
||||
}
|
||||
else if ((sys_errlist == NULL) || (sys_errlist[errnoval] == NULL))
|
||||
{
|
||||
/* In range, but no sys_errlist or no entry at this index. */
|
||||
sprintf (buf, "Error %d", errnoval);
|
||||
msg = buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* In range, and a valid message. Just return the message. */
|
||||
msg = (char *) sys_errlist[errnoval];
|
||||
}
|
||||
|
||||
return (msg);
|
||||
}
|
||||
|
||||
#endif /* ! HAVE_STRERROR */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
NAME
|
||||
|
||||
strerrno -- map an error number to a symbolic name string
|
||||
|
||||
SYNOPSIS
|
||||
|
||||
const char *strerrno (int errnoval)
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Given an error number returned from a system call (typically
|
||||
returned in errno), returns a pointer to a string containing the
|
||||
symbolic name of that error number, as found in <errno.h>.
|
||||
|
||||
If the supplied error number is within the valid range of indices
|
||||
for symbolic names, but no name is available for the particular
|
||||
error number, then returns the string "Error NUM", where NUM is
|
||||
the error number.
|
||||
|
||||
If the supplied error number is not within the range of valid
|
||||
indices, then returns NULL.
|
||||
|
||||
BUGS
|
||||
|
||||
The contents of the location pointed to are only guaranteed to be
|
||||
valid until the next call to strerrno.
|
||||
|
||||
*/
|
||||
|
||||
const char *
|
||||
strerrno (errnoval)
|
||||
int errnoval;
|
||||
{
|
||||
const char *name;
|
||||
static char buf[32];
|
||||
|
||||
if (error_names == NULL)
|
||||
{
|
||||
init_error_tables ();
|
||||
}
|
||||
|
||||
if ((errnoval < 0) || (errnoval >= num_error_names))
|
||||
{
|
||||
#ifdef EVMSERR
|
||||
if (errnoval == evmserr.value)
|
||||
name = evmserr.name;
|
||||
else
|
||||
#endif
|
||||
/* Out of range, just return NULL */
|
||||
name = NULL;
|
||||
}
|
||||
else if ((error_names == NULL) || (error_names[errnoval] == NULL))
|
||||
{
|
||||
/* In range, but no error_names or no entry at this index. */
|
||||
sprintf (buf, "Error %d", errnoval);
|
||||
name = (const char *) buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* In range, and a valid name. Just return the name. */
|
||||
name = error_names[errnoval];
|
||||
}
|
||||
|
||||
return (name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
NAME
|
||||
|
||||
strtoerrno -- map a symbolic errno name to a numeric value
|
||||
|
||||
SYNOPSIS
|
||||
|
||||
int strtoerrno (char *name)
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Given the symbolic name of a error number, map it to an errno value.
|
||||
If no translation is found, returns 0.
|
||||
|
||||
*/
|
||||
|
||||
int
|
||||
strtoerrno (name)
|
||||
const char *name;
|
||||
{
|
||||
int errnoval = 0;
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
if (error_names == NULL)
|
||||
{
|
||||
init_error_tables ();
|
||||
}
|
||||
for (errnoval = 0; errnoval < num_error_names; errnoval++)
|
||||
{
|
||||
if ((error_names[errnoval] != NULL) &&
|
||||
(strcmp (name, error_names[errnoval]) == 0))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (errnoval == num_error_names)
|
||||
{
|
||||
#ifdef EVMSERR
|
||||
if (strcmp (name, evmserr.name) == 0)
|
||||
errnoval = evmserr.value;
|
||||
else
|
||||
#endif
|
||||
errnoval = 0;
|
||||
}
|
||||
}
|
||||
return (errnoval);
|
||||
}
|
||||
|
||||
|
||||
/* A simple little main that does nothing but print all the errno translations
|
||||
if MAIN is defined and this file is compiled and linked. */
|
||||
|
||||
#ifdef MAIN
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int errn;
|
||||
int errnmax;
|
||||
const char *name;
|
||||
char *msg;
|
||||
char *strerror ();
|
||||
|
||||
errnmax = errno_max ();
|
||||
printf ("%d entries in names table.\n", num_error_names);
|
||||
printf ("%d entries in messages table.\n", sys_nerr);
|
||||
printf ("%d is max useful index.\n", errnmax);
|
||||
|
||||
/* Keep printing values until we get to the end of *both* tables, not
|
||||
*either* table. Note that knowing the maximum useful index does *not*
|
||||
relieve us of the responsibility of testing the return pointer for
|
||||
NULL. */
|
||||
|
||||
for (errn = 0; errn <= errnmax; errn++)
|
||||
{
|
||||
name = strerrno (errn);
|
||||
name = (name == NULL) ? "<NULL>" : name;
|
||||
msg = strerror (errn);
|
||||
msg = (msg == NULL) ? "<NULL>" : msg;
|
||||
printf ("%-4d%-18s%s\n", errn, name, msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,116 @@
|
||||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 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 this library; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ([email protected]). */
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include "iostreamP.h"
|
||||
#include "strstream.h"
|
||||
#include <string.h>
|
||||
|
||||
static void* default_alloc(_IO_size_t size)
|
||||
{
|
||||
return (void*)new char[size];
|
||||
}
|
||||
|
||||
static void default_free(void* ptr)
|
||||
{
|
||||
delete [] (char*)ptr;
|
||||
}
|
||||
|
||||
istrstream::istrstream(const char *cp, int n)
|
||||
{
|
||||
__my_sb.init_readonly (cp, n);
|
||||
}
|
||||
|
||||
strstreambase::strstreambase(char *cp, int n, int mode)
|
||||
: __my_sb (cp, n,
|
||||
(mode == ios::app || mode == ios::ate) ? cp + strlen(cp) : cp)
|
||||
{
|
||||
init (&__my_sb);
|
||||
}
|
||||
|
||||
char *strstreambuf::str()
|
||||
{
|
||||
freeze(1);
|
||||
return base();
|
||||
}
|
||||
|
||||
_IO_ssize_t strstreambuf::pcount () { return _IO_write_ptr - _IO_write_base; }
|
||||
|
||||
int strstreambuf::overflow(int c /* = EOF */)
|
||||
{
|
||||
return _IO_str_overflow (this, c);
|
||||
}
|
||||
|
||||
int strstreambuf::underflow()
|
||||
{
|
||||
return _IO_str_underflow(this);
|
||||
}
|
||||
|
||||
|
||||
void strstreambuf::init_dynamic(_IO_alloc_type alloc, _IO_free_type free,
|
||||
int initial_size)
|
||||
|
||||
{
|
||||
_s._allocate_buffer = alloc ? alloc : default_alloc;
|
||||
_s._free_buffer = free ? free : default_free;
|
||||
if (initial_size > 0)
|
||||
{
|
||||
char * buf = (char*)(*_s._allocate_buffer)(initial_size);
|
||||
setb(buf, buf + initial_size, 1);
|
||||
setp(buf, buf + initial_size);
|
||||
setg(buf, buf, buf);
|
||||
}
|
||||
}
|
||||
|
||||
void strstreambuf::init_static(char *ptr, int size, char *pstart)
|
||||
{
|
||||
_IO_str_init_static (reinterpret_cast<_IO_strfile_*>(this), ptr, size, pstart);
|
||||
}
|
||||
|
||||
void strstreambuf::init_readonly (const char *ptr, int size)
|
||||
{
|
||||
_IO_str_init_readonly (reinterpret_cast<_IO_strfile_*>(this), ptr, size);
|
||||
}
|
||||
|
||||
strstreambuf::~strstreambuf()
|
||||
{
|
||||
if (_IO_buf_base && !(_flags & _IO_USER_BUF))
|
||||
(_s._free_buffer)(_IO_buf_base);
|
||||
_IO_buf_base = NULL;
|
||||
}
|
||||
|
||||
streampos strstreambuf::seekoff(streamoff off, _seek_dir dir,
|
||||
int mode /*=ios::in|ios::out*/)
|
||||
{
|
||||
return _IO_str_seekoff (this, off, dir, mode);
|
||||
}
|
||||
|
||||
int strstreambuf::pbackfail(int c)
|
||||
{
|
||||
return _IO_str_pbackfail (this, c);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include <std/std_valarray.h>
|
||||
|
||||
// Some Explicit Instanciations.
|
||||
template class multiplies<size_t>;
|
||||
template size_t accumulate(size_t*, size_t*, size_t, multiplies<size_t>);
|
||||
|
||||
template void
|
||||
__valarray_fill(size_t* __restrict__, size_t, const size_t&);
|
||||
|
||||
template void
|
||||
__valarray_copy(const size_t* __restrict__, size_t, size_t* __restrict__);
|
||||
|
||||
template valarray<size_t>::valarray(size_t);
|
||||
template valarray<size_t>::~valarray();
|
||||
template valarray<size_t>::valarray(const valarray<size_t>&);
|
||||
template size_t valarray<size_t>::size() const;
|
||||
template size_t& valarray<size_t>::operator[](size_t);
|
||||
template size_t valarray<size_t>::product() const;
|
||||
|
||||
|
||||
void __gslice_to_index(size_t __o, const valarray<size_t>& __l,
|
||||
const valarray<size_t>& __s,
|
||||
valarray<size_t>& __i)
|
||||
{
|
||||
const size_t __n = __l.size();
|
||||
size_t* const __t = static_cast<size_t*>(alloca(__n*sizeof(size_t)));
|
||||
__valarray_fill(__t, __n, size_t(0));
|
||||
const size_t __z = __i.size();
|
||||
__valarray_fill(&__i[0], __z, __o);
|
||||
for (size_t __j=0; __j<__z; ++__j) {
|
||||
for (size_t __k=0; __k<__n; ++__k)
|
||||
__i[__j] += __s[__k]*__t[__k];
|
||||
++__t[__n-1];
|
||||
for (size_t __k=__n-1; __k; --__k) {
|
||||
if (__t[__k] >= __l[__k]) {
|
||||
__t[__k] = 0;
|
||||
++__t[__k-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_Indexer::_Indexer(size_t __o, const valarray<size_t>& __l,
|
||||
const valarray<size_t>& __s)
|
||||
: _M_count(1), _M_start(__o), _M_size(__l), _M_stride(__s),
|
||||
_M_index(__l.size() ? __l.product() : 0)
|
||||
{ __gslice_to_index(__o, __l, __s, _M_index); }
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/* Emulate vfork using just plain fork, for systems without a real vfork.
|
||||
This function is in the public domain. */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
vfork ()
|
||||
{
|
||||
return (fork ());
|
||||
}
|
||||
Reference in New Issue
Block a user