?? wilson.txt
字號:
Positive Integration
by Matthew Wilson
Listing 1:
/* /////////////////////////////////////////////////////////////
* Extract from std/recls.d
* www: http://www.digitalmars.com/d
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
// Module
module std.recls;
// Imports
import std.string;
// Typedefs
private alias int recls_sint32_t;
public alias uint recls_uint32_t;
public typedef int recls_bool_t;
public alias recls_bool_t boolean;
version(Windows)
{
public struct recls_time_t
{
uint dwLowDateTime;
uint dwHighDateTime;
};
alias ulong recls_filesize_t;
}
else version(Linux)
{
typedef time_t recls_time_t;
typedef off_t recls_filesize_t;
}
public typedef void *hrecls_t;
public typedef void *recls_info_t;
public typedef void *recls_process_fn_param_t;
public typedef recls_sint32_t recls_rc_t;
public recls_bool_t RECLS_FAILED(recls_rc_t rc)
{
return (recls_bool_t)(rc < 0);
}
public recls_bool_t RECLS_SUCCEEDED(recls_rc_t rc)
{
return (recls_bool_t)!RECLS_FAILED(rc);
}
// Values
public const recls_rc_t RECLS_RC_OK = (recls_rc_t)(0);
public const recls_rc_t RECLS_RC_NO_MORE_DATA = (recls_rc_t)(-1004);
public enum RECLS_FLAG
{
RECLS_F_FILES = 0x00000001
, RECLS_F_DIRECTORIES = 0x00000002
, RECLS_F_LINKS = 0x00000004
, RECLS_F_DEVICES = 0x00000008
, RECLS_F_RECURSIVE = 0x00010000
, RECLS_F_NO_FOLLOW_LINKS = 0x00020000
, RECLS_F_DIRECTORY_PARTS = 0x00040000
, RECLS_F_DETAILS_LATER = 0x00080000
};
// Private recls API declarations
extern (Windows)
{
private recls_rc_t Recls_Search(char *searchRoot
, char *pattern
, recls_uint32_t flags
, hrecls_t *phSrch);
private void Recls_SearchClose(in hrecls_t hSrch);
private recls_rc_t Recls_GetNext(in hrecls_t hSrch);
private recls_rc_t Recls_GetDetails(in hrecls_t hSrch,
out recls_info_t pinfo);
private recls_rc_t Recls_GetNextDetails(in hrecls_t hSrch,
out recls_info_t pinfo);
private void Recls_CloseDetails(in recls_info_t fileInfo);
private recls_rc_t Recls_CopyDetails(in recls_info_t fileInfo,
in recls_info_t *pinfo);
private recls_rc_t Recls_OutstandingDetails(in hrecls_t hSrch,
out recls_uint32_t count);
private recls_rc_t Recls_GetLastError(in hrecls_t hSrch);
private int Recls_GetErrorString(in recls_rc_t rc, in char *buffer,
in uint cchBuffer);
private int Recls_GetLastErrorString(in hrecls_t hSrch, in char *buffer,
in uint cchBuffer);
private uint Recls_GetPathProperty(in recls_info_t fileInfo,in char *buffer,
in uint cchBuffer);
version(Windows)
{
private void Recls_GetDriveProperty(in recls_info_t fileInfo,
out char chDrive);
}
private uint Recls_GetDirectoryProperty(in recls_info_t fileInfo,
in char *buffer, in uint cchBuffer);
. . . // And all the other functions
}
Listing 2:
/* /////////////////////////////////////////////////////////////
* Extract from std/recls.d
* www: http://www.digitalmars.com/d
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
// Public functions
public recls_rc_t Search_Create(in char[] searchRoot, in char[] pattern,
in int flags, out hrecls_t hSrch)
{
return Recls_Search(toStringz(searchRoot),toStringz(pattern),flags,&hSrch);
}
. . .
public void Search_Close(inout hrecls_t hSrch)
{
Recls_SearchClose(hSrch);
hSrch = null;
}
. . .
public recls_info_t Search_CopyEntry(in recls_info_t entry)
{
recls_info_t copy;
if(RECLS_FAILED(Recls_CopyDetails(entry, ©)))
{
copy = null;
}
return copy;
}
. . .
public char[] Search_GetErrorString(in recls_rc_t rc)
{
uint cch = Recls_GetErrorString(rc, null, 0);
char[] err = new char[cch];
cch = Recls_GetErrorString(rc, err, err.length);
assert(cch <= err.length);
return err;
}
public char[] Search_GetEntryPath(in recls_info_t entry)
in
{
assert(null !== entry);
}
body
{
uint cch = Recls_GetPathProperty(entry, null, 0);
char[] path = new char[cch];
cch = Recls_GetPathProperty(entry, path, path.length);
assert(cch <= path.length);
return path;
}
. . .
public char[][] Search_GetEntryDirectoryParts(in recls_info_t entry)
in
{
assert(null !== entry);
}
body
{
uint cParts = Recls_GetDirectoryPartProperty(entry, -1, null, 0);
char[][] parts = new char[][cParts];
for(int i = 0; i < cParts; ++i)
{
uint cch = Recls_GetDirectoryPartProperty(entry, i, null, 0);
char[] str = new char[cch];
cch = Recls_GetDirectoryPartProperty(entry, i, str, str.length);
assert(cch <= str.length);
parts[i] = str;
}
return parts;
}
Listing 3:
/* /////////////////////////////////////////////////////////////
* Extract from std/recls.d
* www: http://www.digitalmars.com/d
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
// Classes
public class Entry
{
private:
this(recls_info_t entry)
{
m_entry = entry;
}
~this()
{
Search_CloseEntry(m_entry);
}
public:
char[] Path()
in
{
assert(null !== m_entry);
}
body
{
return Search_GetEntryPath(m_entry);
}
. . . // All the other properties
boolean IsLink()
in
{
assert(null !== m_entry);
}
body
{
return Search_IsEntryLink(m_entry);
}
private:
recls_info_t m_entry;
}
public class Search
{
public:
this(in char[] searchRoot, in char[] pattern, in uint flags)
{
m_searchRoot = searchRoot;
m_pattern = pattern;
m_flags = flags;
}
public:
int opApply(int delegate(inout Entry entry) dg)
{
int result = 0;
hrecls_t hSrch;
recls_rc_t rc = Search_Create(m_searchRoot,m_pattern,m_flags,hSrch);
recls_info_t entry;
do
{
if(RECLS_FAILED(rc))
{
result = 1;
}
else
{
rc = Search_GetEntry(hSrch, entry);
if(RECLS_FAILED(rc))
{
result = 1;
}
else
{
try
{
Entry e = new Entry(entry);
result = dg(e);
}
finally
{
Search_CloseEntry(entry);
}
}
rc = Search_GetNextEntry(hSrch, entry);
}
} while(result == 0);
return result;
}
/// Members
private:
char[] m_searchRoot;
char[] m_pattern;
uint m_flags;
}
// Unittest
unittest
{
Search search = new Search(".", "*.*", RECLS_FLAG.RECLS_F_RECURSIVE);
foreach(Entry entry; search)
{
char[] path = entry.Path();
char[] directory = entry.Directory();
. . . // Call all other properties
entry.IsLink();
}
}
Listing 4:
/* /////////////////////////////////////////////////////////////
* Extract from org/recls/Search.java
* www: http://www.recls.org/
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
package org.recls;
import java.io.File;
import java.util.Enumeration;
public class Search
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -