mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
phobos 0.126
This commit is contained in:
parent
eb9c6b12e3
commit
ccbb884d7d
21 changed files with 739 additions and 604 deletions
|
@ -232,6 +232,47 @@ void *_aaGet(aaA*[] *aa, TypeInfo keyti, int valuesize, ...)
|
|||
}
|
||||
|
||||
|
||||
/*************************************************
|
||||
* Get pointer to value in associative array indexed by key.
|
||||
* Returns null if it is not already there.
|
||||
*/
|
||||
|
||||
void *_aaGetRvalue(aaA*[] aa, TypeInfo keyti, int valuesize, ...)
|
||||
{
|
||||
void *pkey = cast(void *)(&valuesize + 1);
|
||||
uint key_hash;
|
||||
uint i;
|
||||
aaA *e;
|
||||
aaA **pe;
|
||||
int keysize = keyti.tsize();
|
||||
|
||||
if (aa.length)
|
||||
{
|
||||
key_hash = keyti.getHash(pkey);
|
||||
//printf("hash = %d\n", key_hash);
|
||||
i = (key_hash % (aa.length - 1)) + 1;
|
||||
pe = &aa[i];
|
||||
while ((e = *pe) != null)
|
||||
{ int c;
|
||||
|
||||
c = key_hash - e.hash;
|
||||
if (c == 0)
|
||||
{
|
||||
c = keyti.compare(pkey, e + 1);
|
||||
if (c == 0)
|
||||
return cast(void *)(e + 1) + keysize;
|
||||
}
|
||||
|
||||
if (c < 0)
|
||||
pe = &e.left;
|
||||
else
|
||||
pe = &e.right;
|
||||
}
|
||||
}
|
||||
return null; // not found, caller will throw exception
|
||||
}
|
||||
|
||||
|
||||
/*************************************************
|
||||
* Determine if key is in aa.
|
||||
* Returns:
|
||||
|
|
|
@ -77,7 +77,22 @@ int os_mem_unmap(void *base, uint nbytes)
|
|||
|
||||
void *os_query_stackBottom()
|
||||
{
|
||||
return __libc_stack_end;
|
||||
version (none)
|
||||
{ // See discussion: http://autopackage.org/forums/viewtopic.php?t=22
|
||||
static void** libc_stack_end;
|
||||
|
||||
if (libc_stack_end == libc_stack_end.init)
|
||||
{
|
||||
void* handle = dlopen(null, RTLD_NOW);
|
||||
libc_stack_end = cast(void **)dlsym(handle, "__libc_stack_end");
|
||||
dlclose(handle);
|
||||
}
|
||||
return *libc_stack_end;
|
||||
}
|
||||
else
|
||||
{ // This doesn't resolve on all versions of Linux
|
||||
return __libc_stack_end;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ void _d_invariant(Object o)
|
|||
//printf("__d_invariant(%p)\n", o);
|
||||
|
||||
// BUG: needs to be filename/line of caller, not library routine
|
||||
assert(o !== null); // just do null check, not invariant check
|
||||
assert(o !is null); // just do null check, not invariant check
|
||||
|
||||
c = o.classinfo;
|
||||
do
|
||||
|
|
|
@ -354,7 +354,7 @@ else
|
|||
fprintf(fplog,"%7d\t%3lld.%07lld\t%3lld.%07lld\t%3lld.%07lld\t%.*s\n",
|
||||
calls,tl,tr,fl,fr,pl,pr,id);
|
||||
}
|
||||
if (id !== s.Sident)
|
||||
if (id !is s.Sident)
|
||||
free(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ OBJS= asserterror.o deh2.o switch.o complex.o gcstats.o \
|
|||
compiler.o system.o moduleinit.o md5.o base64.o \
|
||||
cast.o path.o string.o memset.o math.o mmfile.o \
|
||||
outbuffer.o ctype.o regexp.o random.o linux.o linuxsocket.o \
|
||||
stream.o switcherr.o array.o gc.o \
|
||||
stream.o cstream.o switcherr.o array.o gc.o \
|
||||
qsort.o thread.o obj.o utf.o uri.o \
|
||||
crc32.o conv.o arraycast.o errno.o alloca.o cmath2.o \
|
||||
process.o syserror.o \
|
||||
|
@ -99,7 +99,7 @@ SRC_STD= std/zlib.d std/zip.d std/stdint.d std/conv.d std/utf.d std/uri.d \
|
|||
std/regexp.d std/random.d std/stream.d std/process.d std/recls.d \
|
||||
std/socket.d std/socketstream.d std/loader.d std/stdarg.d \
|
||||
std/stdio.d std/format.d std/perf.d std/openrj.d std/uni.d \
|
||||
std/boxer.d
|
||||
std/boxer.d std/cstream.d
|
||||
|
||||
SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d \
|
||||
std/c/math.d std/c/stdarg.d std/c/stddef.d
|
||||
|
@ -481,6 +481,9 @@ compiler.o : std/compiler.d
|
|||
conv.o : std/conv.d
|
||||
$(DMD) -c $(DFLAGS) std/conv.d
|
||||
|
||||
cstream.o : std/cstream.d
|
||||
$(DMD) -c $(DFLAGS) std/cstream.d
|
||||
|
||||
ctype.o : std/ctype.d
|
||||
$(DMD) -c $(DFLAGS) std/ctype.d
|
||||
|
||||
|
@ -551,7 +554,7 @@ stdio.o : std/stdio.d
|
|||
$(DMD) -c $(DFLAGS) std/stdio.d
|
||||
|
||||
stream.o : std/stream.d
|
||||
$(DMD) -c $(DFLAGS) std/stream.d
|
||||
$(DMD) -c $(DFLAGS) -d std/stream.d
|
||||
|
||||
string.o : std/string.d
|
||||
$(DMD) -c $(DFLAGS) std/string.d
|
||||
|
|
11
std/base64.d
11
std/base64.d
|
@ -75,7 +75,8 @@ body
|
|||
sp = &str[0];
|
||||
for(stri = 0; stri != strmax; stri++)
|
||||
{
|
||||
x = (*sp++ << 16) | (*sp++ << 8) | (*sp++);
|
||||
x = (sp[0] << 16) | (sp[1] << 8) | (sp[2]);
|
||||
sp+= 3;
|
||||
*bp++ = array[(x & 0b11111100_00000000_00000000) >> 18];
|
||||
*bp++ = array[(x & 0b00000011_11110000_00000000) >> 12];
|
||||
*bp++ = array[(x & 0b00000000_00001111_11000000) >> 6];
|
||||
|
@ -85,7 +86,8 @@ body
|
|||
switch(strleft)
|
||||
{
|
||||
case 2:
|
||||
x = (*sp++ << 16) | (*sp++ << 8);
|
||||
x = (sp[0] << 16) | (sp[1] << 8);
|
||||
sp += 2;
|
||||
*bp++ = array[(x & 0b11111100_00000000_00000000) >> 18];
|
||||
*bp++ = array[(x & 0b00000011_11110000_00000000) >> 12];
|
||||
*bp++ = array[(x & 0b00000000_00001111_11000000) >> 6];
|
||||
|
@ -180,8 +182,9 @@ body
|
|||
bp = &buf[0];
|
||||
for(estri = 0; estri != estrmax; estri++)
|
||||
{
|
||||
x = arrayIndex(*sp++) << 18 | arrayIndex(*sp++) << 12;
|
||||
|
||||
x = arrayIndex(sp[0]) << 18 | arrayIndex(sp[1]) << 12;
|
||||
sp += 2;
|
||||
|
||||
ch = *sp++;
|
||||
if(ch == '=')
|
||||
{
|
||||
|
|
28
std/boxer.d
28
std/boxer.d
|
@ -136,11 +136,11 @@ struct Box
|
|||
|
||||
TypeInfo_Class ca = cast(TypeInfo_Class) type, cb = cast(TypeInfo_Class) test;
|
||||
|
||||
if (ca !== null && cb !== null)
|
||||
if (ca !is null && cb !is null)
|
||||
{
|
||||
ClassInfo ia = (*cast(Object *) data).classinfo, ib = cb.info;
|
||||
|
||||
for ( ; ia !== null; ia = ia.base)
|
||||
for ( ; ia !is null; ia = ia.base)
|
||||
if (ia is ib)
|
||||
return true;
|
||||
return false;
|
||||
|
@ -320,7 +320,7 @@ body
|
|||
Box box(TypeInfo type, void* data)
|
||||
in
|
||||
{
|
||||
assert(type !== null);
|
||||
assert(type !is null);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -407,7 +407,7 @@ private template unboxCastReal(T)
|
|||
{
|
||||
T unboxCastReal(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (value.type is typeid(float))
|
||||
return cast(T) *cast(float*) value.data;
|
||||
|
@ -424,7 +424,7 @@ private template unboxCastInteger(T)
|
|||
{
|
||||
T unboxCastInteger(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (value.type is typeid(int))
|
||||
return cast(T) *cast(int*) value.data;
|
||||
|
@ -453,7 +453,7 @@ private template unboxCastComplex(T)
|
|||
{
|
||||
T unboxCastComplex(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (value.type is typeid(cfloat))
|
||||
return cast(T) *cast(cfloat*) value.data;
|
||||
|
@ -476,7 +476,7 @@ private template unboxCastImaginary(T)
|
|||
{
|
||||
T unboxCastImaginary(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (value.type is typeid(ifloat))
|
||||
return cast(T) *cast(ifloat*) value.data;
|
||||
|
@ -499,7 +499,7 @@ template unbox(T)
|
|||
{
|
||||
T unbox(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (typeid(T) is value.type)
|
||||
return *cast(T*) value.data;
|
||||
|
@ -529,7 +529,7 @@ template unbox(T : Object)
|
|||
{
|
||||
T unbox(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (typeid(T) == value.type || cast(TypeInfo_Class) value.type)
|
||||
{
|
||||
|
@ -553,7 +553,7 @@ template unbox(T : T[])
|
|||
{
|
||||
T[] unbox(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (typeid(T[]) is value.type)
|
||||
return *cast(T[]*) value.data;
|
||||
|
@ -567,7 +567,7 @@ template unbox(T : T*)
|
|||
{
|
||||
T* unbox(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (typeid(T*) is value.type)
|
||||
return *cast(T**) value.data;
|
||||
|
@ -584,7 +584,7 @@ template unbox(T : void*)
|
|||
{
|
||||
T unbox(Box value)
|
||||
{
|
||||
assert (value.type !== null);
|
||||
assert (value.type !is null);
|
||||
|
||||
if (cast(TypeInfo_Pointer) value.type)
|
||||
return *cast(void**) value.data;
|
||||
|
@ -689,7 +689,7 @@ unittest
|
|||
assert(array.length == 3);
|
||||
assert(unboxTest!(int)(array[0]) == 16);
|
||||
assert(unboxTest!(char[])(array[1]) == "foobar");
|
||||
assert(unboxTest!(Object)(array[2]) !== null);
|
||||
assert(unboxTest!(Object)(array[2]) !is null);
|
||||
|
||||
/* Convert the box array back into arguments. */
|
||||
TypeInfo[] array_types;
|
||||
|
@ -724,7 +724,7 @@ unittest
|
|||
assert (box(1) == box(true));
|
||||
|
||||
/* Assert that unboxing to an object works properly. */
|
||||
assert (unboxTest!(B)(box(cast(A)new B)) !== null);
|
||||
assert (unboxTest!(B)(box(cast(A)new B)) !is null);
|
||||
|
||||
/* Assert that illegal object casting fails properly. */
|
||||
assert (fails(delegate void() { unboxTest!(B)(box(new A)); }));
|
||||
|
|
|
@ -323,3 +323,17 @@ extern(C)
|
|||
}
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
/* From <dlfcn.h>
|
||||
* See http://www.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
|
||||
*/
|
||||
|
||||
const int RTLD_NOW = 0x00002; // Correct for Red Hat 8
|
||||
|
||||
void* dlopen(char* file, int mode);
|
||||
int dlclose(void* handle);
|
||||
void* dlsym(void* handle, char* name);
|
||||
char* dlerror();
|
||||
}
|
||||
|
||||
|
|
147
std/cstream.d
Normal file
147
std/cstream.d
Normal file
|
@ -0,0 +1,147 @@
|
|||
// Written by Ben Hinkle and put in the public domain.
|
||||
|
||||
import std.stream;
|
||||
import std.c.stdio;
|
||||
|
||||
// wraps a FILE* in a stream class
|
||||
class CFile : Stream {
|
||||
FILE* cfile;
|
||||
|
||||
// Construct a CFile from the given FILE* with mode and optional seekable state
|
||||
this(FILE* cfile, FileMode mode, bool seekable = false) {
|
||||
super();
|
||||
this.file = cfile;
|
||||
readable = cast(bit)(mode & FileMode.In);
|
||||
writeable = cast(bit)(mode & FileMode.Out);
|
||||
this.seekable = seekable;
|
||||
}
|
||||
|
||||
~this() { close(); }
|
||||
|
||||
FILE* file() { return cfile; }
|
||||
void file(FILE* cfile) {
|
||||
this.cfile = cfile;
|
||||
isopen = true;
|
||||
}
|
||||
|
||||
override void flush() { fflush(cfile); }
|
||||
override void close() {
|
||||
if (isopen)
|
||||
fclose(cfile);
|
||||
isopen = readable = writeable = seekable = false;
|
||||
}
|
||||
override bool eof() {
|
||||
return cast(bool)(readEOF || feof(cfile));
|
||||
}
|
||||
override char getc() {
|
||||
return cast(char)fgetc(cfile);
|
||||
}
|
||||
override char ungetc(char c) {
|
||||
return cast(char)std.c.stdio.ungetc(c,cfile);
|
||||
}
|
||||
override size_t readBlock(void* buffer, size_t size) {
|
||||
size_t n = fread(buffer,1,size,cfile);
|
||||
readEOF = cast(bit)(n == 0);
|
||||
return n;
|
||||
}
|
||||
override size_t writeBlock(void* buffer, size_t size) {
|
||||
return fwrite(buffer,1,size,cfile);
|
||||
}
|
||||
override ulong seek(long offset, SeekPos rel) {
|
||||
readEOF = false;
|
||||
if (fseek(cfile,cast(int)offset,rel) != 0)
|
||||
throw new SeekException("unable to move file pointer");
|
||||
return ftell(cfile);
|
||||
}
|
||||
override void writeLine(char[] s) {
|
||||
writeString(s);
|
||||
writeString("\n");
|
||||
}
|
||||
override void writeLineW(wchar[] s) {
|
||||
writeStringW(s);
|
||||
writeStringW("\n");
|
||||
}
|
||||
// run a few tests
|
||||
unittest {
|
||||
FILE* f = fopen("stream.txt","w");
|
||||
assert(f !is null);
|
||||
CFile file = new CFile(f,FileMode.Out);
|
||||
int i = 666;
|
||||
// should be ok to write
|
||||
assert(file.writeable);
|
||||
file.writeLine("Testing stream.d:");
|
||||
file.writeString("Hello, world!");
|
||||
file.write(i);
|
||||
// string#1 + string#2 + int should give exacly that
|
||||
version (Win32)
|
||||
assert(file.position() == 19 + 13 + 4);
|
||||
version (linux)
|
||||
assert(file.position() == 18 + 13 + 4);
|
||||
file.close();
|
||||
// no operations are allowed when file is closed
|
||||
assert(!file.readable && !file.writeable && !file.seekable);
|
||||
f = fopen("stream.txt","r");
|
||||
file = new CFile(f,FileMode.In,true);
|
||||
// should be ok to read
|
||||
assert(file.readable);
|
||||
char[] line = file.readLine();
|
||||
char[] exp = "Testing stream.d:";
|
||||
assert(line[0] == 'T');
|
||||
assert(line.length == exp.length);
|
||||
assert(!std.string.cmp(line, "Testing stream.d:"));
|
||||
// jump over "Hello, "
|
||||
file.seek(7, SeekPos.Current);
|
||||
version (Win32)
|
||||
assert(file.position() == 19 + 7);
|
||||
version (linux)
|
||||
assert(file.position() == 18 + 7);
|
||||
assert(!std.string.cmp(file.readString(6), "world!"));
|
||||
i = 0; file.read(i);
|
||||
assert(i == 666);
|
||||
// string#1 + string#2 + int should give exacly that
|
||||
version (Win32)
|
||||
assert(file.position() == 19 + 13 + 4);
|
||||
version (linux)
|
||||
assert(file.position() == 18 + 13 + 4);
|
||||
// we must be at the end of file
|
||||
file.close();
|
||||
f = fopen("stream.txt","w+");
|
||||
file = new CFile(f,FileMode.In|FileMode.Out,true);
|
||||
file.writeLine("Testing stream.d:");
|
||||
file.writeLine("Another line");
|
||||
file.writeLine("");
|
||||
file.writeLine("That was blank");
|
||||
file.position = 0;
|
||||
char[][] lines;
|
||||
foreach(char[] line; file) {
|
||||
lines ~= line.dup;
|
||||
}
|
||||
assert( lines.length == 5 );
|
||||
assert( lines[0] == "Testing stream.d:");
|
||||
assert( lines[1] == "Another line");
|
||||
assert( lines[2] == "");
|
||||
assert( lines[3] == "That was blank");
|
||||
file.position = 0;
|
||||
lines = new char[][5];
|
||||
foreach(ulong n, char[] line; file) {
|
||||
lines[n-1] = line.dup;
|
||||
}
|
||||
assert( lines[0] == "Testing stream.d:");
|
||||
assert( lines[1] == "Another line");
|
||||
assert( lines[2] == "");
|
||||
assert( lines[3] == "That was blank");
|
||||
file.close();
|
||||
remove("stream.txt");
|
||||
}
|
||||
}
|
||||
|
||||
// standard IO devices
|
||||
CFile din, dout, derr;
|
||||
|
||||
static this() {
|
||||
// open standard I/O devices
|
||||
din = new CFile(std.c.stdio.stdin,FileMode.In);
|
||||
dout = new CFile(std.c.stdio.stdout,FileMode.Out);
|
||||
derr = new CFile(std.c.stdio.stderr,FileMode.Out);
|
||||
}
|
||||
|
52
std/loader.d
52
std/loader.d
|
@ -210,7 +210,7 @@ version(Windows)
|
|||
private HXModule ExeModule_Load_(in char[] moduleName)
|
||||
in
|
||||
{
|
||||
assert(null !== moduleName);
|
||||
assert(null !is moduleName);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -227,7 +227,7 @@ version(Windows)
|
|||
private HXModule ExeModule_AddRef_(in HXModule hModule)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -237,7 +237,7 @@ version(Windows)
|
|||
private void ExeModule_Release_(inout HXModule hModule)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -251,7 +251,7 @@ version(Windows)
|
|||
private void *ExeModule_GetSymbol_(inout HXModule hModule, in char[] symbolName)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -332,13 +332,13 @@ else version(linux)
|
|||
private HXModule ExeModule_Load_(in char[] moduleName)
|
||||
in
|
||||
{
|
||||
assert(null !== moduleName);
|
||||
assert(null !is moduleName);
|
||||
}
|
||||
body
|
||||
{
|
||||
ExeModuleInfo mi = s_modules[moduleName];
|
||||
|
||||
if(null !== mi)
|
||||
if(null !is mi)
|
||||
{
|
||||
return (++mi.m_cRefs, cast(HXModule)mi);
|
||||
}
|
||||
|
@ -366,21 +366,21 @@ else version(linux)
|
|||
private HXModule ExeModule_AddRef_(in HXModule hModule)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
|
||||
ExeModuleInfo mi = cast(ExeModuleInfo)hModule;
|
||||
|
||||
assert(0 < mi.m_cRefs);
|
||||
assert(null !== mi.m_hmod);
|
||||
assert(null !== mi.m_name);
|
||||
assert(null !== s_modules[mi.m_name]);
|
||||
assert(null !is mi.m_hmod);
|
||||
assert(null !is mi.m_name);
|
||||
assert(null !is s_modules[mi.m_name]);
|
||||
assert(mi is s_modules[mi.m_name]);
|
||||
}
|
||||
body
|
||||
{
|
||||
ExeModuleInfo mi = cast(ExeModuleInfo)hModule;
|
||||
|
||||
if(null !== mi)
|
||||
if(null !is mi)
|
||||
{
|
||||
return (++mi.m_cRefs, hModule);
|
||||
}
|
||||
|
@ -393,14 +393,14 @@ else version(linux)
|
|||
private void ExeModule_Release_(inout HXModule hModule)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
|
||||
ExeModuleInfo mi = cast(ExeModuleInfo)hModule;
|
||||
|
||||
assert(0 < mi.m_cRefs);
|
||||
assert(null !== mi.m_hmod);
|
||||
assert(null !== mi.m_name);
|
||||
assert(null !== s_modules[mi.m_name]);
|
||||
assert(null !is mi.m_hmod);
|
||||
assert(null !is mi.m_name);
|
||||
assert(null !is s_modules[mi.m_name]);
|
||||
assert(mi is s_modules[mi.m_name]);
|
||||
}
|
||||
body
|
||||
|
@ -425,14 +425,14 @@ else version(linux)
|
|||
private void *ExeModule_GetSymbol_(inout HXModule hModule, in char[] symbolName)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
|
||||
ExeModuleInfo mi = cast(ExeModuleInfo)hModule;
|
||||
|
||||
assert(0 < mi.m_cRefs);
|
||||
assert(null !== mi.m_hmod);
|
||||
assert(null !== mi.m_name);
|
||||
assert(null !== s_modules[mi.m_name]);
|
||||
assert(null !is mi.m_hmod);
|
||||
assert(null !is mi.m_name);
|
||||
assert(null !is s_modules[mi.m_name]);
|
||||
assert(mi is s_modules[mi.m_name]);
|
||||
}
|
||||
body
|
||||
|
@ -456,14 +456,14 @@ else version(linux)
|
|||
private char[] ExeModule_GetPath_(HXModule hModule)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
|
||||
ExeModuleInfo mi = cast(ExeModuleInfo)hModule;
|
||||
|
||||
assert(0 < mi.m_cRefs);
|
||||
assert(null !== mi.m_hmod);
|
||||
assert(null !== mi.m_name);
|
||||
assert(null !== s_modules[mi.m_name]);
|
||||
assert(null !is mi.m_hmod);
|
||||
assert(null !is mi.m_name);
|
||||
assert(null !is s_modules[mi.m_name]);
|
||||
assert(mi is s_modules[mi.m_name]);
|
||||
}
|
||||
body
|
||||
|
@ -509,7 +509,7 @@ public:
|
|||
this(in HXModule hModule, boolean bTakeOwnership)
|
||||
in
|
||||
{
|
||||
assert(null !== hModule);
|
||||
assert(null !is hModule);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -538,7 +538,7 @@ public:
|
|||
this(char[] moduleName)
|
||||
in
|
||||
{
|
||||
assert(null !== moduleName);
|
||||
assert(null !is moduleName);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -574,7 +574,7 @@ public:
|
|||
/// calls do not result in an error, and are simply ignored.
|
||||
void close()
|
||||
{
|
||||
if(null !== m_hModule)
|
||||
if(null !is m_hModule)
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
|
|
|
@ -334,9 +334,10 @@ SC17: fprem1 ;
|
|||
jp SC17 ;
|
||||
fstp ST(1) ; // remove pi from stack
|
||||
jmp SC18 ;
|
||||
}
|
||||
|
||||
trigerr:
|
||||
fstp ST(0) ; // dump theta
|
||||
}
|
||||
return real.nan;
|
||||
|
||||
Lret:
|
||||
|
|
26
std/openrj.d
26
std/openrj.d
|
@ -354,8 +354,8 @@ private:
|
|||
this(char[] name, char[] value/* , Record record */)
|
||||
in
|
||||
{
|
||||
assert(null !== name);
|
||||
assert(null !== value);
|
||||
assert(null !is name);
|
||||
assert(null !is value);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -390,7 +390,7 @@ public:
|
|||
{
|
||||
Field f = cast(Field)(rhs);
|
||||
|
||||
if(null === f)
|
||||
if(null is f)
|
||||
{
|
||||
throw new InvalidTypeException("Attempt to compare a Field with an instance of another type");
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ public:
|
|||
{
|
||||
int res;
|
||||
|
||||
if(this === rhs)
|
||||
if(this is rhs)
|
||||
{
|
||||
res = 0;
|
||||
}
|
||||
|
@ -499,13 +499,13 @@ public:
|
|||
Field getField(char[] fieldName)
|
||||
in
|
||||
{
|
||||
assert(null !== fieldName);
|
||||
assert(null !is fieldName);
|
||||
}
|
||||
body
|
||||
{
|
||||
Field field = findField(fieldName);
|
||||
|
||||
if(null === field)
|
||||
if(null is field)
|
||||
{
|
||||
throw new InvalidKeyException("field not found");
|
||||
}
|
||||
|
@ -516,18 +516,18 @@ public:
|
|||
Field findField(char[] fieldName)
|
||||
in
|
||||
{
|
||||
assert(null !== fieldName);
|
||||
assert(null !is fieldName);
|
||||
}
|
||||
body
|
||||
{
|
||||
Field *pfield = (fieldName in m_values);
|
||||
|
||||
return (null === pfield) ? null : *pfield;
|
||||
return (null is pfield) ? null : *pfield;
|
||||
}
|
||||
|
||||
int hasField(char[] fieldName)
|
||||
{
|
||||
return null !== findField(fieldName);
|
||||
return null !is findField(fieldName);
|
||||
}
|
||||
|
||||
Database database()
|
||||
|
@ -799,7 +799,7 @@ public:
|
|||
|
||||
foreach(Record record; m_records)
|
||||
{
|
||||
if(null !== record.findField(fieldName))
|
||||
if(null !is record.findField(fieldName))
|
||||
{
|
||||
records ~= record;
|
||||
}
|
||||
|
@ -817,7 +817,7 @@ public:
|
|||
{
|
||||
Field field = record.findField(fieldName);
|
||||
|
||||
if(null !== field)
|
||||
if(null !is field)
|
||||
{
|
||||
// Since there can be more than one field with the same name in
|
||||
// the same record, we need to search all fields in this record
|
||||
|
@ -829,7 +829,7 @@ public:
|
|||
int res = cmp(field.name, fieldName);
|
||||
|
||||
if( 0 == res &&
|
||||
( null === fieldValue ||
|
||||
( null is fieldValue ||
|
||||
field.value == fieldValue))
|
||||
{
|
||||
records ~= record;
|
||||
|
@ -847,7 +847,7 @@ public:
|
|||
foreach(Field field; record)
|
||||
{
|
||||
if( field.name == fieldName &&
|
||||
( null === fieldValue ||
|
||||
( null is fieldValue ||
|
||||
field.value == fieldValue))
|
||||
{
|
||||
records ~= record;
|
||||
|
|
|
@ -44,7 +44,7 @@ auto class PerformanceCounterScope(T)
|
|||
this(T counter)
|
||||
in
|
||||
{
|
||||
assert(null !== counter);
|
||||
assert(null !is counter);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
|
76
std/recls.d
76
std/recls.d
|
@ -344,7 +344,7 @@ public char[] Search_GetErrorString(in recls_rc_t rc)
|
|||
public char[] Search_GetEntryPath(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -363,7 +363,7 @@ version(Windows)
|
|||
public char Search_GetEntryDrive(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -376,7 +376,7 @@ body
|
|||
public char[] Search_GetEntryDirectory(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -393,7 +393,7 @@ body
|
|||
public char[] Search_GetEntryDirectoryPath(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -410,7 +410,7 @@ body
|
|||
public char[] Search_GetEntryFile(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -427,7 +427,7 @@ body
|
|||
public char[] Search_GetEntryShortFile(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -444,7 +444,7 @@ body
|
|||
public char[] Search_GetEntryFileName(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -461,7 +461,7 @@ body
|
|||
public char[] Search_GetEntryFileExt(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -478,7 +478,7 @@ body
|
|||
public char[][] Search_GetEntryDirectoryParts(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -503,7 +503,7 @@ body
|
|||
public boolean Search_IsEntryReadOnly(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -513,7 +513,7 @@ body
|
|||
public boolean Search_IsEntryDirectory(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -523,7 +523,7 @@ body
|
|||
public boolean Search_IsEntryLink(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -533,7 +533,7 @@ body
|
|||
public recls_filesize_t Search_GetEntrySize(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -545,7 +545,7 @@ body
|
|||
public recls_time_t Search_GetEntryCreationTime(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -555,7 +555,7 @@ body
|
|||
public recls_time_t Search_GetEntryModificationTime(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -565,7 +565,7 @@ body
|
|||
public recls_time_t Search_GetEntryLastAccessTime(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -575,7 +575,7 @@ body
|
|||
public recls_time_t Search_GetEntryLastStatusChangeTime(in recls_info_t entry)
|
||||
in
|
||||
{
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -630,7 +630,7 @@ public:
|
|||
Entry CurrentEntry()
|
||||
in
|
||||
{
|
||||
assert(null !== m_hSrch);
|
||||
assert(null !is m_hSrch);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -797,7 +797,7 @@ public class Entry
|
|||
// we just add a reference, and then release it
|
||||
recls_info_t entry = Search_CopyEntry(m_entry);
|
||||
|
||||
assert(null !== entry);
|
||||
assert(null !is entry);
|
||||
|
||||
Recls_CloseDetails(entry);
|
||||
}
|
||||
|
@ -834,7 +834,7 @@ private:
|
|||
}
|
||||
~this()
|
||||
{
|
||||
if(null !== m_entry)
|
||||
if(null !is m_entry)
|
||||
{
|
||||
Search_CloseEntry(m_entry);
|
||||
}
|
||||
|
@ -847,7 +847,7 @@ public:
|
|||
char[] GetPath()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -859,7 +859,7 @@ public:
|
|||
char[] Path()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -873,7 +873,7 @@ version(Windows)
|
|||
char Drive()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -886,7 +886,7 @@ version(Windows)
|
|||
char[] Directory()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -898,7 +898,7 @@ version(Windows)
|
|||
char[] DirectoryPath()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -910,7 +910,7 @@ version(Windows)
|
|||
char[][] DirectoryParts()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -922,7 +922,7 @@ version(Windows)
|
|||
char[] File()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -934,7 +934,7 @@ version(Windows)
|
|||
char[] ShortFile()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -946,7 +946,7 @@ version(Windows)
|
|||
char[] FileName()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -958,7 +958,7 @@ version(Windows)
|
|||
char[] FileExt()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -969,7 +969,7 @@ version(Windows)
|
|||
recls_time_t CreationTime()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -979,7 +979,7 @@ version(Windows)
|
|||
recls_time_t ModificationTime()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -989,7 +989,7 @@ version(Windows)
|
|||
recls_time_t LastAccessTime()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -999,7 +999,7 @@ version(Windows)
|
|||
recls_time_t LastStatusChangeTime()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -1010,7 +1010,7 @@ version(Windows)
|
|||
recls_filesize_t Size()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -1021,7 +1021,7 @@ version(Windows)
|
|||
boolean IsReadOnly()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -1031,7 +1031,7 @@ version(Windows)
|
|||
boolean IsDirectory()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
@ -1041,7 +1041,7 @@ version(Windows)
|
|||
boolean IsLink()
|
||||
in
|
||||
{
|
||||
assert(null !== m_entry);
|
||||
assert(null !is m_entry);
|
||||
}
|
||||
body
|
||||
{
|
||||
|
|
|
@ -1339,12 +1339,12 @@ class Socket
|
|||
//make sure none of the SocketSet's are the same object
|
||||
if(checkRead)
|
||||
{
|
||||
assert(checkRead !== checkWrite);
|
||||
assert(checkRead !== checkError);
|
||||
assert(checkRead !is checkWrite);
|
||||
assert(checkRead !is checkError);
|
||||
}
|
||||
if(checkWrite)
|
||||
{
|
||||
assert(checkWrite !== checkError);
|
||||
assert(checkWrite !is checkError);
|
||||
}
|
||||
}
|
||||
body
|
||||
|
|
|
@ -24,15 +24,11 @@ module std.socketstream;
|
|||
private import std.stream;
|
||||
private import std.socket;
|
||||
|
||||
|
||||
class SocketStream: Stream
|
||||
{
|
||||
private:
|
||||
bit prevCr = false;
|
||||
bit atEof = false;
|
||||
Socket sock;
|
||||
|
||||
|
||||
public:
|
||||
this(Socket sock, FileMode mode)
|
||||
{
|
||||
|
@ -44,187 +40,61 @@ class SocketStream: Stream
|
|||
this.sock = sock;
|
||||
}
|
||||
|
||||
|
||||
this(Socket sock)
|
||||
{
|
||||
writeable = readable = true;
|
||||
this.sock = sock;
|
||||
}
|
||||
|
||||
|
||||
Socket socket()
|
||||
{
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
||||
override uint readBlock(void* _buffer, uint size)
|
||||
in
|
||||
{
|
||||
assert(readable);
|
||||
ubyte* buffer = cast(ubyte*)_buffer;
|
||||
int len;
|
||||
uint need = size;
|
||||
assertReadable();
|
||||
|
||||
if(size == 0)
|
||||
return size;
|
||||
|
||||
len = sock.receive(buffer[0 .. size]);
|
||||
readEOF = cast(bit)(len == 0);
|
||||
if(len < 0)
|
||||
len = 0;
|
||||
return len;
|
||||
}
|
||||
body
|
||||
{
|
||||
ubyte* buffer = cast(ubyte*)_buffer;
|
||||
int len;
|
||||
uint need = size;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if(!need)
|
||||
return size;
|
||||
|
||||
len = sock.receive(buffer[0 .. need]);
|
||||
if(len <= 0)
|
||||
{
|
||||
if(!len)
|
||||
atEof = true;
|
||||
break;
|
||||
}
|
||||
|
||||
buffer += len;
|
||||
need -= len;
|
||||
}
|
||||
return size - need;
|
||||
}
|
||||
|
||||
|
||||
override char getc()
|
||||
{
|
||||
char ch;
|
||||
|
||||
if(prevCr)
|
||||
{
|
||||
prevCr = false;
|
||||
ch = super.getc();
|
||||
if(ch != '\n')
|
||||
return ch;
|
||||
}
|
||||
|
||||
return super.getc();
|
||||
}
|
||||
|
||||
|
||||
override wchar getcw()
|
||||
{
|
||||
wchar ch;
|
||||
|
||||
if(prevCr)
|
||||
{
|
||||
prevCr = false;
|
||||
ch = super.getcw();
|
||||
if(ch != '\n')
|
||||
return ch;
|
||||
}
|
||||
|
||||
return super.getcw();
|
||||
}
|
||||
|
||||
|
||||
override char[] readLine()
|
||||
{
|
||||
char[] result;
|
||||
try
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
char ch = getc();
|
||||
switch(ch)
|
||||
{
|
||||
case '\r':
|
||||
prevCr = true;
|
||||
case '\n':
|
||||
return result;
|
||||
|
||||
default:
|
||||
result ~= ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ReadError re)
|
||||
{
|
||||
if(!eof())
|
||||
throw re;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
override wchar[] readLineW()
|
||||
{
|
||||
wchar[] result;
|
||||
try
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
char ch = getcw();
|
||||
switch(ch)
|
||||
{
|
||||
case '\r':
|
||||
prevCr = true;
|
||||
case '\n':
|
||||
return result;
|
||||
|
||||
default:
|
||||
result ~= ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ReadError re)
|
||||
{
|
||||
if(!eof())
|
||||
throw re;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
override uint writeBlock(void* _buffer, uint size)
|
||||
in
|
||||
{
|
||||
assert(writeable);
|
||||
ubyte* buffer = cast(ubyte*)_buffer;
|
||||
int len;
|
||||
assertWriteable();
|
||||
|
||||
if(size == 0)
|
||||
return size;
|
||||
|
||||
len = sock.send(buffer[0 .. size]);
|
||||
readEOF = cast(bit)(len == 0);
|
||||
if(len < 0)
|
||||
len = 0;
|
||||
return len;
|
||||
}
|
||||
body
|
||||
{
|
||||
ubyte* buffer = cast(ubyte*)_buffer;
|
||||
int len;
|
||||
uint need = size;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if(!need)
|
||||
return size;
|
||||
|
||||
len = sock.send(buffer[0 .. need]);
|
||||
if(len <= 0)
|
||||
break;
|
||||
|
||||
buffer += len;
|
||||
need -= len;
|
||||
}
|
||||
return size - need;
|
||||
}
|
||||
|
||||
|
||||
override ulong seek(long offset, SeekPos whence)
|
||||
{
|
||||
throw new SeekError("Cannot seek a socket.");
|
||||
throw new SeekException("Cannot seek a socket.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
override char[] toString()
|
||||
{
|
||||
return sock.toString();
|
||||
}
|
||||
|
||||
|
||||
override bit eof()
|
||||
{
|
||||
return atEof;
|
||||
}
|
||||
|
||||
|
||||
override void close()
|
||||
{
|
||||
sock.close();
|
||||
|
|
672
std/stream.d
672
std/stream.d
|
@ -63,12 +63,8 @@ enum SeekPos {
|
|||
End
|
||||
}
|
||||
|
||||
import std.format;
|
||||
alias std.format.va_list va_list;
|
||||
private import std.c.stdio;
|
||||
alias std.c.stdio.va_list c_va_list;
|
||||
|
||||
private {
|
||||
import std.format;
|
||||
import std.system; // for Endian enumeration
|
||||
import std.intrinsic; // for bswap
|
||||
import std.utf;
|
||||
|
@ -150,10 +146,12 @@ interface InputStream {
|
|||
|
||||
// reads and returns next character from the stream,
|
||||
// handles characters pushed back by ungetc()
|
||||
// return char.init on EOF
|
||||
char getc();
|
||||
|
||||
// reads and returns next Unicode character from the
|
||||
// stream, handles characters pushed back by ungetc()
|
||||
// return wchar.init on EOF
|
||||
wchar getcw();
|
||||
|
||||
// pushes back character c into the stream; only has
|
||||
|
@ -164,7 +162,7 @@ interface InputStream {
|
|||
// has effect on further calls to getc() and getcw()
|
||||
wchar ungetcw(wchar c);
|
||||
|
||||
int vscanf(char[] fmt, c_va_list args);
|
||||
int vscanf(char[] fmt, va_list args);
|
||||
|
||||
int scanf(char[] format, ...);
|
||||
|
||||
|
@ -226,7 +224,7 @@ interface OutputStream {
|
|||
|
||||
// writes data to stream using vprintf() syntax,
|
||||
// returns number of bytes written
|
||||
size_t vprintf(char[] format, c_va_list args);
|
||||
size_t vprintf(char[] format, va_list args);
|
||||
|
||||
// writes data to stream using printf() syntax,
|
||||
// returns number of bytes written
|
||||
|
@ -257,6 +255,9 @@ class Stream : InputStream, OutputStream {
|
|||
// flag that last readBlock resulted in eof
|
||||
protected bit readEOF = false;
|
||||
|
||||
// flag that last getc got \r
|
||||
protected bit prevCr = false;
|
||||
|
||||
this() {}
|
||||
|
||||
// reads block of data of specified size,
|
||||
|
@ -331,35 +332,31 @@ class Stream : InputStream, OutputStream {
|
|||
// allocates a new string
|
||||
char[] readLine(char[] result) {
|
||||
size_t strlen = 0;
|
||||
try {
|
||||
char ch = getc();
|
||||
while (readable) {
|
||||
switch (ch) {
|
||||
case '\r': {
|
||||
char ch = getc();
|
||||
while (readable) {
|
||||
switch (ch) {
|
||||
case '\r':
|
||||
if (seekable) {
|
||||
ch = getc();
|
||||
if (ch != '\n')
|
||||
ungetc(ch);
|
||||
} else {
|
||||
prevCr = true;
|
||||
}
|
||||
case '\n':
|
||||
case char.init:
|
||||
result.length = strlen;
|
||||
return result;
|
||||
|
||||
case '\n':
|
||||
result.length = strlen;
|
||||
return result;
|
||||
|
||||
default:
|
||||
if (strlen < result.length) {
|
||||
result[strlen] = ch;
|
||||
} else {
|
||||
result ~= ch;
|
||||
}
|
||||
strlen++;
|
||||
default:
|
||||
if (strlen < result.length) {
|
||||
result[strlen] = ch;
|
||||
} else {
|
||||
result ~= ch;
|
||||
}
|
||||
ch = getc();
|
||||
strlen++;
|
||||
}
|
||||
} catch (ReadException e) {
|
||||
// either this is end of stream, which is okay,
|
||||
// or something bad occured while reading
|
||||
if (!eof())
|
||||
throw e;
|
||||
ch = getc();
|
||||
}
|
||||
result.length = strlen;
|
||||
return result;
|
||||
|
@ -377,35 +374,31 @@ class Stream : InputStream, OutputStream {
|
|||
// fills supplied buffer if line fits and otherwise allocates a new string.
|
||||
wchar[] readLineW(wchar[] result) {
|
||||
size_t strlen = 0;
|
||||
try {
|
||||
wchar c = getcw();
|
||||
while (readable) {
|
||||
switch (c) {
|
||||
case '\r': {
|
||||
wchar c = getcw();
|
||||
while (readable) {
|
||||
switch (c) {
|
||||
case '\r':
|
||||
if (seekable) {
|
||||
c = getcw();
|
||||
if (c != '\n')
|
||||
ungetcw(c);
|
||||
} else {
|
||||
prevCr = true;
|
||||
}
|
||||
case '\n':
|
||||
case wchar.init:
|
||||
result.length = strlen;
|
||||
return result;
|
||||
|
||||
case '\n':
|
||||
result.length = strlen;
|
||||
return result;
|
||||
|
||||
default:
|
||||
if (strlen < result.length) {
|
||||
result[strlen] = c;
|
||||
} else {
|
||||
result ~= c;
|
||||
}
|
||||
strlen++;
|
||||
default:
|
||||
if (strlen < result.length) {
|
||||
result[strlen] = c;
|
||||
} else {
|
||||
result ~= c;
|
||||
}
|
||||
c = getcw();
|
||||
strlen++;
|
||||
}
|
||||
} catch (ReadException e) {
|
||||
// either this is end of stream, which is okay,
|
||||
// or something bad occured while reading
|
||||
if (!eof())
|
||||
throw e;
|
||||
c = getcw();
|
||||
}
|
||||
result.length = strlen;
|
||||
return result;
|
||||
|
@ -485,26 +478,43 @@ class Stream : InputStream, OutputStream {
|
|||
|
||||
// reads and returns next character from the stream,
|
||||
// handles characters pushed back by ungetc()
|
||||
// returns char.init on eof.
|
||||
char getc() {
|
||||
char c;
|
||||
if (prevCr) {
|
||||
prevCr = false;
|
||||
c = getc();
|
||||
if (c != '\n')
|
||||
return c;
|
||||
}
|
||||
if (unget.length > 1) {
|
||||
c = unget[unget.length - 1];
|
||||
unget.length = unget.length - 1;
|
||||
} else {
|
||||
read(c);
|
||||
readBlock(&c,1);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
// reads and returns next Unicode character from the
|
||||
// stream, handles characters pushed back by ungetc()
|
||||
// returns wchar.init on eof.
|
||||
wchar getcw() {
|
||||
wchar c;
|
||||
if (prevCr) {
|
||||
prevCr = false;
|
||||
c = getcw();
|
||||
if (c != '\n')
|
||||
return c;
|
||||
}
|
||||
if (unget.length > 1) {
|
||||
c = unget[unget.length - 1];
|
||||
unget.length = unget.length - 1;
|
||||
} else {
|
||||
read(c);
|
||||
void* buf = &c;
|
||||
size_t n = readBlock(buf,2);
|
||||
if (n == 1 && readBlock(buf+1,1) == 0)
|
||||
throw new ReadException("not enough data in stream");
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
@ -512,6 +522,7 @@ class Stream : InputStream, OutputStream {
|
|||
// pushes back character c into the stream; only has
|
||||
// effect on further calls to getc() and getcw()
|
||||
char ungetc(char c) {
|
||||
if (c == c.init) return c;
|
||||
// first byte is a dummy so that we never set length to 0
|
||||
if (unget.length == 0)
|
||||
unget.length = 1;
|
||||
|
@ -522,6 +533,7 @@ class Stream : InputStream, OutputStream {
|
|||
// pushes back Unicode character c into the stream; only
|
||||
// has effect on further calls to getc() and getcw()
|
||||
wchar ungetcw(wchar c) {
|
||||
if (c == c.init) return c;
|
||||
// first byte is a dummy so that we never set length to 0
|
||||
if (unget.length == 0)
|
||||
unget.length = 1;
|
||||
|
@ -529,300 +541,293 @@ class Stream : InputStream, OutputStream {
|
|||
return c;
|
||||
}
|
||||
|
||||
int vscanf(char[] fmt, c_va_list args) {
|
||||
int vscanf(char[] fmt, va_list args) {
|
||||
void** arg = cast(void**) args;
|
||||
int count = 0, i = 0;
|
||||
try {
|
||||
char c = getc();
|
||||
while (i < fmt.length) {
|
||||
if (fmt[i] == '%') { // a field
|
||||
char c = getc();
|
||||
while (i < fmt.length && !eof()) {
|
||||
if (fmt[i] == '%') { // a field
|
||||
i++;
|
||||
bit suppress = false;
|
||||
if (fmt[i] == '*') { // suppress assignment
|
||||
suppress = true;
|
||||
i++;
|
||||
bit suppress = false;
|
||||
if (fmt[i] == '*') { // suppress assignment
|
||||
suppress = true;
|
||||
}
|
||||
// read field width
|
||||
int width = 0;
|
||||
while (isdigit(fmt[i])) {
|
||||
width = width * 10 + (fmt[i] - '0');
|
||||
i++;
|
||||
}
|
||||
if (width == 0)
|
||||
width = -1;
|
||||
// D string?
|
||||
bit dstr = false;
|
||||
if (fmt[i] == '.') {
|
||||
i++;
|
||||
if (fmt[i] == '*') {
|
||||
dstr = true;
|
||||
i++;
|
||||
}
|
||||
// read field width
|
||||
int width = 0;
|
||||
while (isdigit(fmt[i])) {
|
||||
width = width * 10 + (fmt[i] - '0');
|
||||
i++;
|
||||
}
|
||||
if (width == 0)
|
||||
width = -1;
|
||||
// D string?
|
||||
bit dstr = false;
|
||||
if (fmt[i] == '.') {
|
||||
i++;
|
||||
if (fmt[i] == '*') {
|
||||
dstr = true;
|
||||
i++;
|
||||
}
|
||||
// read the modifier
|
||||
char modifier = fmt[i];
|
||||
if (modifier == 'h' || modifier == 'l' || modifier == 'L')
|
||||
i++;
|
||||
else
|
||||
modifier = 0;
|
||||
// check the typechar and act accordingly
|
||||
switch (fmt[i]) {
|
||||
case 'd': // decimal/hexadecimal/octal integer
|
||||
case 'D':
|
||||
case 'u':
|
||||
case 'U':
|
||||
case 'o':
|
||||
case 'O':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 'i':
|
||||
case 'I':
|
||||
{
|
||||
while (iswhite(c)) {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// read the modifier
|
||||
char modifier = fmt[i];
|
||||
if (modifier == 'h' || modifier == 'l' || modifier == 'L')
|
||||
i++;
|
||||
else
|
||||
modifier = 0;
|
||||
// check the typechar and act accordingly
|
||||
switch (fmt[i]) {
|
||||
case 'd': // decimal/hexadecimal/octal integer
|
||||
case 'D':
|
||||
case 'u':
|
||||
case 'U':
|
||||
case 'o':
|
||||
case 'O':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 'i':
|
||||
case 'I':
|
||||
{
|
||||
while (iswhite(c)) {
|
||||
bit neg = false;
|
||||
if (c == '-') {
|
||||
neg = true;
|
||||
c = getc();
|
||||
count++;
|
||||
} else if (c == '+') {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
char ifmt = fmt[i] | 0x20;
|
||||
if (ifmt == 'i') { // undetermined base
|
||||
if (c == '0') { // octal or hex
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
bit neg = false;
|
||||
if (c == '-') {
|
||||
neg = true;
|
||||
c = getc();
|
||||
count++;
|
||||
} else if (c == '+') {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
char ifmt = fmt[i] | 0x20;
|
||||
if (ifmt == 'i') { // undetermined base
|
||||
if (c == '0') { // octal or hex
|
||||
if (c == 'x' || c == 'X') { // hex
|
||||
ifmt = 'x';
|
||||
c = getc();
|
||||
count++;
|
||||
if (c == 'x' || c == 'X') { // hex
|
||||
ifmt = 'x';
|
||||
c = getc();
|
||||
count++;
|
||||
} else { // octal
|
||||
ifmt = 'o';
|
||||
}
|
||||
} else { // octal
|
||||
ifmt = 'o';
|
||||
}
|
||||
else // decimal
|
||||
ifmt = 'd';
|
||||
}
|
||||
long n = 0;
|
||||
switch (ifmt) {
|
||||
case 'd': // decimal
|
||||
case 'u': {
|
||||
while (isdigit(c) && width) {
|
||||
n = n * 10 + (c - '0');
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
} break;
|
||||
|
||||
case 'o': { // octal
|
||||
while (isoctdigit(c) && width) {
|
||||
n = n * 010 + (c - '0');
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
} break;
|
||||
|
||||
case 'x': { // hexadecimal
|
||||
while (ishexdigit(c) && width) {
|
||||
n *= 0x10;
|
||||
if (isdigit(c))
|
||||
n += c - '0';
|
||||
else
|
||||
n += 0xA + (c | 0x20) - 'a';
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
if (neg)
|
||||
n = -n;
|
||||
// check the modifier and cast the pointer
|
||||
// to appropriate type
|
||||
switch (modifier) {
|
||||
case 'h': { // short
|
||||
*cast(short*)*arg = n;
|
||||
} break;
|
||||
|
||||
case 'L': { // long
|
||||
*cast(long*)*arg = n;
|
||||
} break;
|
||||
|
||||
default: // int
|
||||
*cast(int*)*arg = n;
|
||||
}
|
||||
i++;
|
||||
} break;
|
||||
|
||||
case 'f': // float
|
||||
case 'F':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
while (iswhite(c)) {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
bit neg = false;
|
||||
if (c == '-') {
|
||||
neg = true;
|
||||
c = getc();
|
||||
count++;
|
||||
} else if (c == '+') {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
real n = 0;
|
||||
else // decimal
|
||||
ifmt = 'd';
|
||||
}
|
||||
long n = 0;
|
||||
switch (ifmt) {
|
||||
case 'd': // decimal
|
||||
case 'u': {
|
||||
while (isdigit(c) && width) {
|
||||
n = n * 10 + (c - '0');
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
if (width && c == '.') {
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
double frac = 1;
|
||||
while (isdigit(c) && width) {
|
||||
n = n * 10 + (c - '0');
|
||||
frac *= 10;
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
n /= frac;
|
||||
}
|
||||
if (width && (c == 'e' || c == 'E')) {
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
if (width) {
|
||||
bit expneg = false;
|
||||
if (c == '-') {
|
||||
expneg = true;
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
} else if (c == '+') {
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
real exp = 0;
|
||||
while (isdigit(c) && width) {
|
||||
exp = exp * 10 + (c - '0');
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
if (expneg) {
|
||||
while (exp--)
|
||||
n /= 10;
|
||||
} else {
|
||||
while (exp--)
|
||||
n *= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (neg)
|
||||
n = -n;
|
||||
// check the modifier and cast the pointer
|
||||
// to appropriate type
|
||||
switch (modifier) {
|
||||
case 'l': { // double
|
||||
*cast(double*)*arg = n;
|
||||
} break;
|
||||
|
||||
case 'L': { // real
|
||||
*cast(real*)*arg = n;
|
||||
} break;
|
||||
|
||||
default: // float
|
||||
*cast(float*)*arg = n;
|
||||
}
|
||||
i++;
|
||||
} break;
|
||||
|
||||
case 's': { // ANSI string
|
||||
case 'o': { // octal
|
||||
while (isoctdigit(c) && width) {
|
||||
n = n * 010 + (c - '0');
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
} break;
|
||||
|
||||
case 'x': { // hexadecimal
|
||||
while (ishexdigit(c) && width) {
|
||||
n *= 0x10;
|
||||
if (isdigit(c))
|
||||
n += c - '0';
|
||||
else
|
||||
n += 0xA + (c | 0x20) - 'a';
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
if (neg)
|
||||
n = -n;
|
||||
// check the modifier and cast the pointer
|
||||
// to appropriate type
|
||||
switch (modifier) {
|
||||
case 'h': { // short
|
||||
*cast(short*)*arg = n;
|
||||
} break;
|
||||
|
||||
case 'L': { // long
|
||||
*cast(long*)*arg = n;
|
||||
} break;
|
||||
|
||||
default: // int
|
||||
*cast(int*)*arg = n;
|
||||
}
|
||||
i++;
|
||||
} break;
|
||||
|
||||
case 'f': // float
|
||||
case 'F':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
while (iswhite(c)) {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
char[] s;
|
||||
while (!iswhite(c)) {
|
||||
s ~= c;
|
||||
bit neg = false;
|
||||
if (c == '-') {
|
||||
neg = true;
|
||||
c = getc();
|
||||
count++;
|
||||
} else if (c == '+') {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
if (dstr) // D string (char[])
|
||||
*cast(char[]*)*arg = s;
|
||||
else { // C string (char*)
|
||||
s ~= 0;
|
||||
(cast(char*)*arg)[0 .. s.length] = s[];
|
||||
real n = 0;
|
||||
while (isdigit(c) && width) {
|
||||
n = n * 10 + (c - '0');
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
if (width && c == '.') {
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
double frac = 1;
|
||||
while (isdigit(c) && width) {
|
||||
n = n * 10 + (c - '0');
|
||||
frac *= 10;
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
n /= frac;
|
||||
}
|
||||
if (width && (c == 'e' || c == 'E')) {
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
if (width) {
|
||||
bit expneg = false;
|
||||
if (c == '-') {
|
||||
expneg = true;
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
} else if (c == '+') {
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
real exp = 0;
|
||||
while (isdigit(c) && width) {
|
||||
exp = exp * 10 + (c - '0');
|
||||
width--;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
if (expneg) {
|
||||
while (exp--)
|
||||
n /= 10;
|
||||
} else {
|
||||
while (exp--)
|
||||
n *= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (neg)
|
||||
n = -n;
|
||||
// check the modifier and cast the pointer
|
||||
// to appropriate type
|
||||
switch (modifier) {
|
||||
case 'l': { // double
|
||||
*cast(double*)*arg = n;
|
||||
} break;
|
||||
|
||||
case 'L': { // real
|
||||
*cast(real*)*arg = n;
|
||||
} break;
|
||||
|
||||
default: // float
|
||||
*cast(float*)*arg = n;
|
||||
}
|
||||
i++;
|
||||
} break;
|
||||
|
||||
case 'c': { // character(s)
|
||||
char* s = cast(char*)*arg;
|
||||
if (width < 0)
|
||||
width = 1;
|
||||
else
|
||||
while (iswhite(c)) {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
while (width--) {
|
||||
*(s++) = c;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
} break;
|
||||
|
||||
case 'n': { // number of chars read so far
|
||||
*cast(int*)*arg = count;
|
||||
i++;
|
||||
} break;
|
||||
|
||||
default: // read character as is
|
||||
goto nws;
|
||||
}
|
||||
arg++;
|
||||
} else if (iswhite(fmt[i])) { // skip whitespace
|
||||
while (iswhite(c))
|
||||
case 's': { // ANSI string
|
||||
while (iswhite(c)) {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
char[] s;
|
||||
while (!iswhite(c) && c != char.init) {
|
||||
s ~= c;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
if (dstr) // D string (char[])
|
||||
*cast(char[]*)*arg = s;
|
||||
else { // C string (char*)
|
||||
s ~= 0;
|
||||
(cast(char*)*arg)[0 .. s.length] = s[];
|
||||
}
|
||||
i++;
|
||||
} else { // read character as is
|
||||
nws:
|
||||
if (fmt[i] != c)
|
||||
break;
|
||||
c = getc();
|
||||
} break;
|
||||
|
||||
case 'c': { // character(s)
|
||||
char* s = cast(char*)*arg;
|
||||
if (width < 0)
|
||||
width = 1;
|
||||
else
|
||||
while (iswhite(c)) {
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
while (width-- && !eof()) {
|
||||
*(s++) = c;
|
||||
c = getc();
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
} break;
|
||||
|
||||
case 'n': { // number of chars read so far
|
||||
*cast(int*)*arg = count;
|
||||
i++;
|
||||
} break;
|
||||
|
||||
default: // read character as is
|
||||
goto nws;
|
||||
}
|
||||
arg++;
|
||||
} else if (iswhite(fmt[i])) { // skip whitespace
|
||||
while (iswhite(c))
|
||||
c = getc();
|
||||
i++;
|
||||
} else { // read character as is
|
||||
nws:
|
||||
if (fmt[i] != c)
|
||||
break;
|
||||
c = getc();
|
||||
i++;
|
||||
}
|
||||
ungetc(c);
|
||||
} catch (ReadException e) {
|
||||
// either this is end of stream, which is okay,
|
||||
// or something bad occured while reading
|
||||
if (!eof())
|
||||
throw e;
|
||||
}
|
||||
ungetc(c);
|
||||
return count;
|
||||
}
|
||||
|
||||
int scanf(char[] format, ...) {
|
||||
c_va_list ap;
|
||||
ap = cast(c_va_list) &format;
|
||||
va_list ap;
|
||||
ap = cast(va_list) &format;
|
||||
ap += format.sizeof;
|
||||
return vscanf(format, ap);
|
||||
}
|
||||
|
@ -837,7 +842,14 @@ class Stream : InputStream, OutputStream {
|
|||
// writes block of data of specified size,
|
||||
// throws WriteException on error
|
||||
void writeExact(void* buffer, size_t size) {
|
||||
if (writeBlock(buffer, size) != size)
|
||||
for(;;) {
|
||||
if (!size) return;
|
||||
size_t writesize = writeBlock(buffer, size);
|
||||
if (writesize == 0) break;
|
||||
buffer += writesize;
|
||||
size -= writesize;
|
||||
}
|
||||
if (size != 0)
|
||||
throw new WriteException("unable to write to stream");
|
||||
}
|
||||
|
||||
|
@ -916,7 +928,7 @@ class Stream : InputStream, OutputStream {
|
|||
|
||||
// writes data to stream using vprintf() syntax,
|
||||
// returns number of bytes written
|
||||
size_t vprintf(char[] format, c_va_list args) {
|
||||
size_t vprintf(char[] format, va_list args) {
|
||||
// shamelessly stolen from OutBuffer,
|
||||
// by Walter's permission
|
||||
char[1024] buffer;
|
||||
|
@ -950,8 +962,8 @@ class Stream : InputStream, OutputStream {
|
|||
// writes data to stream using printf() syntax,
|
||||
// returns number of bytes written
|
||||
size_t printf(char[] format, ...) {
|
||||
c_va_list ap;
|
||||
ap = cast(c_va_list) &format;
|
||||
va_list ap;
|
||||
ap = cast(va_list) &format;
|
||||
ap += format.sizeof;
|
||||
return vprintf(format, ap);
|
||||
}
|
||||
|
@ -1161,7 +1173,7 @@ class BufferedStream : Stream {
|
|||
}
|
||||
|
||||
void updateAttribs() {
|
||||
if (s !== null) {
|
||||
if (s !is null) {
|
||||
readable = s.readable;
|
||||
writeable = s.writeable;
|
||||
seekable = s.seekable;
|
||||
|
@ -1349,6 +1361,7 @@ class BufferedStream : Stream {
|
|||
}
|
||||
flush();
|
||||
size_t res = s.readBlock(buffer,buffer.length);
|
||||
readEOF = res == 0;
|
||||
if(!res) break L0; // EOF
|
||||
bufferSourcePos = bufferLen = res;
|
||||
streamPos += res;
|
||||
|
@ -1580,15 +1593,6 @@ class File: Stream {
|
|||
open(filename, mode | FileMode.OutNew);
|
||||
}
|
||||
|
||||
override void flush() {
|
||||
super.flush();
|
||||
version (Win32) {
|
||||
if (isopen && this !== .stdout) {
|
||||
FlushFileBuffers(hFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// closes file, if it is open; otherwise, does nothing
|
||||
override void close() {
|
||||
if (isopen) {
|
||||
|
@ -1972,6 +1976,27 @@ class EndianStream : Stream {
|
|||
void read(out wchar x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); }
|
||||
void read(out dchar x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); }
|
||||
|
||||
wchar getcw() {
|
||||
wchar c;
|
||||
if (prevCr) {
|
||||
prevCr = false;
|
||||
c = getcw();
|
||||
if (c != '\n')
|
||||
return c;
|
||||
}
|
||||
if (unget.length > 1) {
|
||||
c = unget[unget.length - 1];
|
||||
unget.length = unget.length - 1;
|
||||
} else {
|
||||
void* buf = &c;
|
||||
size_t n = readBlock(buf,2);
|
||||
if (n == 1 && readBlock(buf+1,1) == 0)
|
||||
throw new ReadException("not enough data in stream");
|
||||
fixBO(&c,c.sizeof);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
wchar[] readStringW(size_t length) {
|
||||
wchar[] result = new wchar[length];
|
||||
readExact(result, result.length * wchar.sizeof);
|
||||
|
@ -2378,7 +2403,7 @@ class SliceStream : Stream {
|
|||
// set the base stream and the low offset but leave the high unbounded.
|
||||
this (Stream base, ulong low)
|
||||
in {
|
||||
assert (base !== null);
|
||||
assert (base !is null);
|
||||
assert (low <= base.size ());
|
||||
}
|
||||
body {
|
||||
|
@ -2396,7 +2421,7 @@ class SliceStream : Stream {
|
|||
// set the base stream, the low offset, and the high offset.
|
||||
this (Stream base, ulong low, ulong high)
|
||||
in {
|
||||
assert (base !== null);
|
||||
assert (base !is null);
|
||||
assert (low <= high);
|
||||
assert (high <= base.size ());
|
||||
}
|
||||
|
@ -2583,12 +2608,11 @@ private bit ishexdigit(char c) {
|
|||
}
|
||||
|
||||
// standard IO devices
|
||||
File stdin, stdout, stderr;
|
||||
deprecated File stdin, stdout, stderr;
|
||||
|
||||
version (Win32) {
|
||||
// API imports
|
||||
private extern(Windows) {
|
||||
private import std.c.windows.windows;
|
||||
HANDLE GetStdHandle(DWORD);
|
||||
}
|
||||
|
||||
|
|
12
std/string.d
12
std/string.d
|
@ -199,12 +199,6 @@ deprecated char* toCharz(char[] string)
|
|||
char* toStringz(char[] string)
|
||||
in
|
||||
{
|
||||
if (string)
|
||||
{
|
||||
// No embedded 0's
|
||||
for (uint i = 0; i < string.length; i++)
|
||||
assert(string[i] != 0);
|
||||
}
|
||||
}
|
||||
out (result)
|
||||
{
|
||||
|
@ -902,7 +896,7 @@ unittest
|
|||
|
||||
s2 = toupper(s1);
|
||||
assert(cmp(s2, "FOL") == 0);
|
||||
assert(s2 !== s1);
|
||||
assert(s2 !is s1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -958,7 +952,7 @@ unittest
|
|||
|
||||
s2 = capitalize(s1);
|
||||
assert(cmp(s2, "Fol") == 0);
|
||||
assert(s2 !== s1);
|
||||
assert(s2 !is s1);
|
||||
|
||||
s2 = capitalize(s1[0 .. 2]);
|
||||
assert(cmp(s2, "Fo") == 0);
|
||||
|
@ -967,7 +961,7 @@ unittest
|
|||
s1 = "fOl";
|
||||
s2 = capitalize(s1);
|
||||
assert(cmp(s2, "Fol") == 0);
|
||||
assert(s2 !== s1);
|
||||
assert(s2 !is s1);
|
||||
}
|
||||
|
||||
|
||||
|
|
27
std/thread.d
27
std/thread.d
|
@ -228,7 +228,7 @@ class Thread
|
|||
{ Thread t;
|
||||
|
||||
t = allThreads[i];
|
||||
if (t && t !== tthis && t.state == TS.RUNNING)
|
||||
if (t && t !is tthis && t.state == TS.RUNNING)
|
||||
t.pause();
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ class Thread
|
|||
{ Thread t;
|
||||
|
||||
t = allThreads[i];
|
||||
if (t && t !== tthis && t.state == TS.RUNNING)
|
||||
if (t && t !is tthis && t.state == TS.RUNNING)
|
||||
t.resume();
|
||||
}
|
||||
}
|
||||
|
@ -664,7 +664,7 @@ class Thread
|
|||
{ Thread t;
|
||||
|
||||
t = allThreads[i];
|
||||
if (t && t !== tthis && t.state == TS.RUNNING)
|
||||
if (t && t !is tthis && t.state == TS.RUNNING)
|
||||
{ int result;
|
||||
|
||||
result = pthread_kill(t.id, SIGUSR1);
|
||||
|
@ -693,7 +693,7 @@ class Thread
|
|||
{ Thread t;
|
||||
|
||||
t = allThreads[i];
|
||||
if (t && t !== tthis && t.state == TS.RUNNING)
|
||||
if (t && t !is tthis && t.state == TS.RUNNING)
|
||||
t.resume();
|
||||
}
|
||||
}
|
||||
|
@ -776,7 +776,24 @@ class Thread
|
|||
|
||||
t.state = TS.RUNNING;
|
||||
t.id = pthread_self();
|
||||
t.stackBottom = cast(void*)__libc_stack_end;
|
||||
|
||||
version (none)
|
||||
{
|
||||
// See discussion: http://autopackage.org/forums/viewtopic.php?t=22
|
||||
static void** libc_stack_end;
|
||||
|
||||
if (libc_stack_end == libc_stack_end.init)
|
||||
{
|
||||
void* handle = dlopen(null, RTLD_NOW);
|
||||
libc_stack_end = cast(void **)dlsym(handle, "__libc_stack_end");
|
||||
dlclose(handle);
|
||||
}
|
||||
t.stackBottom = *libc_stack_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.stackBottom = cast(void*)__libc_stack_end;
|
||||
}
|
||||
|
||||
assert(!allThreads[0]);
|
||||
allThreads[0] = t;
|
||||
|
|
|
@ -37,6 +37,7 @@ import std.regexp;
|
|||
import std.random;
|
||||
import std.date;
|
||||
import std.dateparse;
|
||||
import std.cstream;
|
||||
import std.stream;
|
||||
import std.utf;
|
||||
import std.uri;
|
||||
|
@ -67,7 +68,8 @@ printf("test2\n");
|
|||
a.reverse; // adi
|
||||
a.sort; // qsort
|
||||
std.date.getUTCtime(); // date
|
||||
StreamError se = new StreamError(""); // stream
|
||||
Exception e = new ReadException(""); // stream
|
||||
din.eof(); // cstream
|
||||
isValidDchar(cast(dchar)0); // utf
|
||||
std.uri.ascii2hex(0); // uri
|
||||
std.zlib.adler32(0,null); // D.zlib
|
||||
|
|
10
win32.mak
10
win32.mak
|
@ -65,7 +65,7 @@ OBJS= asserterror.obj deh.obj switch.obj complex.obj gcstats.obj \
|
|||
Czlib.obj Dzlib.obj zip.obj process.obj registry.obj recls.obj \
|
||||
socket.obj socketstream.obj loader.obj stdarg.obj format.obj stdio.obj \
|
||||
perf.obj openrj.obj uni.obj winsock.obj oldsyserror.obj \
|
||||
errno.obj boxer.obj \
|
||||
errno.obj boxer.obj cstream.obj \
|
||||
ti_Aa.obj ti_Ag.obj ti_C.obj ti_int.obj ti_char.obj \
|
||||
ti_wchar.obj ti_uint.obj ti_short.obj ti_ushort.obj \
|
||||
ti_byte.obj ti_ubyte.obj ti_long.obj ti_ulong.obj ti_ptr.obj \
|
||||
|
@ -90,7 +90,8 @@ SRC_STD= std\zlib.d std\zip.d std\stdint.d std\conv.d std\utf.d std\uri.d \
|
|||
std\intrinsic.d std\array.d std\switcherr.d std\syserror.d \
|
||||
std\regexp.d std\random.d std\stream.d std\process.d std\recls.d \
|
||||
std\socket.d std\socketstream.d std\loader.d std\stdarg.d std\format.d \
|
||||
std\stdio.d std\perf.d std\openrj.d std\uni.d std\boxer.d
|
||||
std\stdio.d std\perf.d std\openrj.d std\uni.d std\boxer.d \
|
||||
std\cstream.d
|
||||
|
||||
SRC_STD_C= std\c\process.d std\c\stdlib.d std\c\time.d std\c\stdio.d \
|
||||
std\c\math.d std\c\stdarg.d std\c\stddef.d
|
||||
|
@ -445,6 +446,9 @@ compiler.obj : std\compiler.d
|
|||
conv.obj : std\conv.d
|
||||
$(DMD) -c $(DFLAGS) std\conv.d
|
||||
|
||||
cstream.obj : std\cstream.d
|
||||
$(DMD) -c $(DFLAGS) std\cstream.d
|
||||
|
||||
ctype.obj : std\ctype.d
|
||||
$(DMD) -c $(DFLAGS) std\ctype.d
|
||||
|
||||
|
@ -521,7 +525,7 @@ stdio.obj : std\stdio.d
|
|||
$(DMD) -c $(DFLAGS) std\stdio.d
|
||||
|
||||
stream.obj : std\stream.d
|
||||
$(DMD) -c $(DFLAGS) std\stream.d
|
||||
$(DMD) -c $(DFLAGS) -d std\stream.d
|
||||
|
||||
string.obj : std\string.d
|
||||
$(DMD) -c $(DFLAGS) std\string.d
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue