mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 00:54:05 +03:00
phobos 0.129
This commit is contained in:
parent
8ee5d51c15
commit
071f592aa2
7 changed files with 131 additions and 50 deletions
|
@ -8,6 +8,7 @@ module std.c.linux.linux;
|
|||
|
||||
import std.c.linux.linuxextern;
|
||||
|
||||
alias int pid_t;
|
||||
alias int off_t;
|
||||
alias uint mode_t;
|
||||
|
||||
|
@ -118,6 +119,12 @@ extern (C)
|
|||
int rmdir(char*);
|
||||
char* getcwd(char*, int);
|
||||
int chmod(char*, mode_t);
|
||||
int fork();
|
||||
int dup(int);
|
||||
int dup2(int, int);
|
||||
int pipe(int[2]);
|
||||
pid_t wait(int*);
|
||||
int waitpid(pid_t, int*, int);
|
||||
}
|
||||
|
||||
struct timeval
|
||||
|
|
|
@ -523,21 +523,6 @@ const HKEY HKEY_PERFORMANCE_DATA = cast(HKEY)(0x80000004);
|
|||
const HKEY HKEY_CURRENT_CONFIG = cast(HKEY)(0x80000005);
|
||||
const HKEY HKEY_DYN_DATA = cast(HKEY)(0x80000006);
|
||||
|
||||
enum
|
||||
{
|
||||
KEY_QUERY_VALUE = (0x0001),
|
||||
KEY_SET_VALUE = (0x0002),
|
||||
KEY_CREATE_SUB_KEY = (0x0004),
|
||||
KEY_ENUMERATE_SUB_KEYS = (0x0008),
|
||||
KEY_NOTIFY = (0x0010),
|
||||
KEY_CREATE_LINK = (0x0020),
|
||||
|
||||
KEY_READ = cast(int)((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & (~SYNCHRONIZE)),
|
||||
KEY_WRITE = cast(int)((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE)),
|
||||
KEY_EXECUTE = cast(int)(KEY_READ & ~SYNCHRONIZE),
|
||||
KEY_ALL_ACCESS = cast(int)((STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY | KEY_CREATE_LINK) & (~SYNCHRONIZE)),
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
REG_OPTION_RESERVED = (0x00000000), // Parameter is reserved
|
||||
|
@ -560,23 +545,6 @@ enum
|
|||
REG_LEGAL_OPTION = (REG_OPTION_RESERVED | REG_OPTION_NON_VOLATILE | REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK | REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK),
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
REG_NONE = ( 0 ), // No value type
|
||||
REG_SZ = ( 1 ), // Unicode nul terminated string
|
||||
REG_EXPAND_SZ = ( 2 ), // Unicode nul terminated string
|
||||
// (with environment variable references)
|
||||
REG_BINARY = ( 3 ), // Free form binary
|
||||
REG_DWORD = ( 4 ), // 32-bit number
|
||||
REG_DWORD_LITTLE_ENDIAN = ( 4 ), // 32-bit number (same as REG_DWORD)
|
||||
REG_DWORD_BIG_ENDIAN = ( 5 ), // 32-bit number
|
||||
REG_LINK = ( 6 ), // Symbolic Link (unicode)
|
||||
REG_MULTI_SZ = ( 7 ), // Multiple Unicode strings
|
||||
REG_RESOURCE_LIST = ( 8 ), // Resource list in the resource map
|
||||
REG_FULL_RESOURCE_DESCRIPTOR = ( 9 ), // Resource list in the hardware description
|
||||
REG_RESOURCE_REQUIREMENTS_LIST = ( 10 ),
|
||||
}
|
||||
|
||||
export LONG RegDeleteKeyA(HKEY hKey, LPCSTR lpSubKey);
|
||||
export LONG RegDeleteValueA(HKEY hKey, LPCSTR lpValueName);
|
||||
|
||||
|
|
|
@ -819,6 +819,11 @@ int exists(char[] name)
|
|||
+/
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
assert(exists("."));
|
||||
}
|
||||
|
||||
/****************************************************
|
||||
* Is name a file?
|
||||
*/
|
||||
|
|
101
std/format.d
101
std/format.d
|
@ -90,6 +90,64 @@ enum Mangle : char
|
|||
Tdelegate = 'D',
|
||||
}
|
||||
|
||||
// return the TypeInfo for a primitive type and null otherwise.
|
||||
// This is required since for arrays of ints we only have the mangled
|
||||
// char to work from. If arrays always subclassed TypeInfo_Array this
|
||||
// routine could go away.
|
||||
private TypeInfo primitiveTypeInfo(Mangle m)
|
||||
{
|
||||
TypeInfo ti;
|
||||
switch (m)
|
||||
{
|
||||
case Mangle.Tvoid:
|
||||
ti = typeid(void);break;
|
||||
case Mangle.Tbit:
|
||||
ti = typeid(bit);break;
|
||||
case Mangle.Tbyte:
|
||||
ti = typeid(byte);break;
|
||||
case Mangle.Tubyte:
|
||||
ti = typeid(ubyte);break;
|
||||
case Mangle.Tshort:
|
||||
ti = typeid(short);break;
|
||||
case Mangle.Tushort:
|
||||
ti = typeid(ushort);break;
|
||||
case Mangle.Tint:
|
||||
ti = typeid(int);break;
|
||||
case Mangle.Tuint:
|
||||
ti = typeid(uint);break;
|
||||
case Mangle.Tlong:
|
||||
ti = typeid(long);break;
|
||||
case Mangle.Tulong:
|
||||
ti = typeid(ulong);break;
|
||||
case Mangle.Tfloat:
|
||||
ti = typeid(float);break;
|
||||
case Mangle.Tdouble:
|
||||
ti = typeid(double);break;
|
||||
case Mangle.Treal:
|
||||
ti = typeid(real);break;
|
||||
case Mangle.Tifloat:
|
||||
ti = typeid(ifloat);break;
|
||||
case Mangle.Tidouble:
|
||||
ti = typeid(idouble);break;
|
||||
case Mangle.Tireal:
|
||||
ti = typeid(ireal);break;
|
||||
case Mangle.Tcfloat:
|
||||
ti = typeid(cfloat);break;
|
||||
case Mangle.Tcdouble:
|
||||
ti = typeid(cdouble);break;
|
||||
case Mangle.Tcreal:
|
||||
ti = typeid(creal);break;
|
||||
case Mangle.Tchar:
|
||||
ti = typeid(char);break;
|
||||
case Mangle.Twchar:
|
||||
ti = typeid(wchar);break;
|
||||
case Mangle.Tdchar:
|
||||
ti = typeid(dchar);
|
||||
default:
|
||||
ti = null;
|
||||
}
|
||||
return ti;
|
||||
}
|
||||
|
||||
/************************************
|
||||
* Convert arguments to tchar's according to format strings and feed to putc().
|
||||
|
@ -251,6 +309,16 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr)
|
|||
return;
|
||||
}
|
||||
|
||||
void putArray(void* p, size_t len, TypeInfo ti) {
|
||||
putc('[');
|
||||
size_t tsize = ti.tsize();
|
||||
while (len--) {
|
||||
doFormat(putc, (&ti)[0 .. 1], p);
|
||||
p += tsize;
|
||||
if (len > 0) putc(',');
|
||||
}
|
||||
putc(']');
|
||||
}
|
||||
|
||||
//printf("formatArg(fc = '%c', m = '%c')\n", fc, m);
|
||||
switch (m)
|
||||
|
@ -385,8 +453,14 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr)
|
|||
vcreal = va_arg!(creal)(argptr);
|
||||
goto Lcomplex;
|
||||
|
||||
|
||||
case Mangle.Tarray:
|
||||
if (ti.classinfo.name.length == 14 &&
|
||||
ti.classinfo.name[9..14] == "Array")
|
||||
{ // array of non-primitive types
|
||||
void[] va = va_arg!(void[])(argptr);
|
||||
putArray(va.ptr, va.length, (cast(TypeInfo_Array)ti).next);
|
||||
return;
|
||||
}
|
||||
m2 = cast(Mangle)ti.classinfo.name[10];
|
||||
switch (m2)
|
||||
{
|
||||
|
@ -408,8 +482,12 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr)
|
|||
putstr(s);
|
||||
break;
|
||||
|
||||
default:
|
||||
goto Lerror;
|
||||
default:
|
||||
TypeInfo ti2 = primitiveTypeInfo(m2);
|
||||
if (!ti2)
|
||||
goto Lerror;
|
||||
void[] va = va_arg!(void[])(argptr);
|
||||
putArray(va.ptr, va.length, ti2);
|
||||
}
|
||||
return;
|
||||
|
||||
|
@ -813,5 +891,22 @@ unittest
|
|||
assert(r == "hello");
|
||||
r = std.string.format("%8s", s[0..5]);
|
||||
assert(r == " hello");
|
||||
|
||||
int[] arr = new int[4];
|
||||
arr[0] = 100;
|
||||
arr[1] = -999;
|
||||
arr[3] = 0;
|
||||
r = std.string.format(arr);
|
||||
assert(r == "[100,-999,0,0]");
|
||||
r = std.string.format("%s",arr);
|
||||
assert(r == "[100,-999,0,0]");
|
||||
|
||||
char[][] arr2 = new char[][4];
|
||||
arr2[0] = "hello";
|
||||
arr2[1] = "world";
|
||||
arr2[3] = "foo";
|
||||
r = std.string.format(arr2);
|
||||
assert(r == "[hello,world,,foo]");
|
||||
|
||||
}
|
||||
|
||||
|
|
11
std/stdio.d
11
std/stdio.d
|
@ -40,7 +40,7 @@ else
|
|||
void __fp_unlock(FILE* fp) { }
|
||||
}
|
||||
|
||||
private void writex(FILE* fp, TypeInfo[] arguments, void* argptr, int newline)
|
||||
void writefx(FILE* fp, TypeInfo[] arguments, void* argptr, int newline=false)
|
||||
{ int orientation;
|
||||
|
||||
orientation = fwide(fp, 0);
|
||||
|
@ -120,21 +120,20 @@ private void writex(FILE* fp, TypeInfo[] arguments, void* argptr, int newline)
|
|||
|
||||
void writef(...)
|
||||
{
|
||||
writex(stdout, _arguments, _argptr, 0);
|
||||
writefx(stdout, _arguments, _argptr, 0);
|
||||
}
|
||||
|
||||
void writefln(...)
|
||||
{
|
||||
writex(stdout, _arguments, _argptr, 1);
|
||||
writefx(stdout, _arguments, _argptr, 1);
|
||||
}
|
||||
|
||||
void fwritef(FILE* fp, ...)
|
||||
{
|
||||
writex(fp, _arguments, _argptr, 0);
|
||||
writefx(fp, _arguments, _argptr, 0);
|
||||
}
|
||||
|
||||
void fwritefln(FILE* fp, ...)
|
||||
{
|
||||
writex(fp, _arguments, _argptr, 1);
|
||||
writefx(fp, _arguments, _argptr, 1);
|
||||
}
|
||||
|
||||
|
|
21
std/stream.d
21
std/stream.d
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2001-2005
|
||||
* Pavel "EvilOne" Minayev
|
||||
|
@ -163,7 +162,7 @@ interface InputStream {
|
|||
// has effect on further calls to getc() and getcw()
|
||||
wchar ungetcw(wchar c);
|
||||
|
||||
int vreadf(TypeInfo[] arguments, va_list args);
|
||||
int vreadf(TypeInfo[] arguments, void* args);
|
||||
|
||||
int readf(...);
|
||||
|
||||
|
@ -237,6 +236,9 @@ interface OutputStream {
|
|||
// writes data with trailing newline and returns self
|
||||
OutputStream writefln(...);
|
||||
|
||||
// writes data with optional trailing newline and returns self
|
||||
OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline = false);
|
||||
|
||||
void flush();
|
||||
void close();
|
||||
bool isOpen();
|
||||
|
@ -542,7 +544,7 @@ class Stream : InputStream, OutputStream {
|
|||
return c;
|
||||
}
|
||||
|
||||
int vreadf(TypeInfo[] arguments, va_list args) {
|
||||
int vreadf(TypeInfo[] arguments, void* args) {
|
||||
char[] fmt;
|
||||
int j = 0;
|
||||
int count = 0, i = 0;
|
||||
|
@ -1023,14 +1025,19 @@ class Stream : InputStream, OutputStream {
|
|||
|
||||
// writes data to stream using writef() syntax,
|
||||
OutputStream writef(...) {
|
||||
doFormat(&doFormatCallback,_arguments,_argptr);
|
||||
return this;
|
||||
return writefx(_arguments,_argptr,0);
|
||||
}
|
||||
|
||||
// writes data with trailing newline
|
||||
OutputStream writefln(...) {
|
||||
doFormat(&doFormatCallback,_arguments,_argptr);
|
||||
writeLine("");
|
||||
return writefx(_arguments,_argptr,1);
|
||||
}
|
||||
|
||||
// writes data with optional trailing newline
|
||||
OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline=false) {
|
||||
doFormat(&doFormatCallback,arguments,argptr);
|
||||
if (newline)
|
||||
writeLine("");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2004 by Digital Mars, www.digitalmars.com
|
||||
* Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
|
||||
* Written by Walter Bright
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
|
@ -39,7 +39,7 @@ class TypeInfo_C : TypeInfo
|
|||
Object o1 = *cast(Object*)p1;
|
||||
Object o2 = *cast(Object*)p2;
|
||||
|
||||
return o1 == o2 || (o1 && o1.opCmp(o2) == 0);
|
||||
return o1 == o2;
|
||||
}
|
||||
|
||||
int compare(void *p1, void *p2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue