📄 file-defines.zc
字号:
//[c]file-defines - OS specific definitions
//[c]
//[of]:license
//[c] Code Browser - a folding text editor for programmers
//[c] Copyright (C) 2003 Marc Kerbiquet
//[c]
//[c] This program is free software; you can redistribute it and/or modify
//[c] it under the terms of the GNU General Public License as published by
//[c] the Free Software Foundation; either version 2 of the License, or
//[c] (at your option) any later version.
//[c]
//[c] This program is distributed in the hope that it will be useful,
//[c] but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c] MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//[c] GNU General Public License for more details.
//[c]
//[c] You should have received a copy of the GNU General Public License
//[c] along with this program; if not, write to the Free Software
//[c] Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//[cf]
//[of]:imports
//[c]
import "base/types"
import "text/string"
import "text/string-buffer"
import "net/uri"
import "win32/windows"
//[cf]
//[of]:constants
//[c]
public equ path separator = $\
//[cf]
//[c]
//[of]:convert full name (filename)
//[c]
public equ convert full name (filename: string)
def p = filename
repeat
def c = p[]
if is nul (c)
break
end
if c == $/
p[] = path separator
end
++p
end
end
//[cf]
//[of]:is same file (fn1, fn2)
//[c]
public func is same file (fn1: string, fn2: string)
return compare no case (fn1, fn2) == 0
end
//[cf]
//[of]:full name (filename, full name)
//[c]
public func full name (filename: string, full name: string buffer)
// already a fully qualified name ?
if size (filename) > 1 &&
(filename [1] == $: || (filename [0] == $\ && filename [1] == $\))
full name << filename
return
end
def buf : [1024] char
if GetCurrentDirectoryA (1024, buf) <> 0
// the filename starts with '\': just pick up drive
if filename[0] == $\
if size (buf) >= 2
full name << buf[0] << buf [1]
end
else
full name << buf << path separator
end
end
full name << filename
end
//[cf]
//[of]:resolve full name (directory, filename, full name)
//[c]
public func resolve full name (
directory: string,
filename: string,
full name: string buffer)
// already a fully qualified name ?
if size (filename) > 1 &&
(filename [1] == $: || (filename [0] == $\ && filename [1] == $\))
full name << filename
return
end
full name << directory << path separator << filename
end
//[cf]
//[c]
//[of]:create directory (filename)
//[c]Creates a new directory
//[c]
//[c]Returns true if success
//[c]
public func create directory (path: string)
def res = CreateDirectoryA (path, nil)
return res <> 0
end
//[cf]
//[c]
//[of]:append root dir (string buffer, name)
//[c]
//[c] Sub-function:
//[of]: append path (stream, filename)
private func append path (stream: string buffer, filename: string)
def occurence = last occurrence (filename, path separator)
if not nil (occurence)
append (stream, filename, occurence - filename)
end
end
//[cf]
//[c]
public func append root dir (s: string buffer, name: string)
def buf: [MAX_PATH] char
GetModuleFileNameA (nil, buf, MAX_PATH)
append path (s, buf)
end
//[cf]
//[of]:append home dir (string buffer, name)
//[c]
public func append home dir (s: string buffer, name: string)
def buf: [MAX_PATH] char
SHGetSpecialFolderPathA (nil, buf, CSIDL_APPDATA, FALSE)
s << buf << path separator << name
end
//[cf]
//[c]
//[of]:convert filename to uri (filename)
//[c]Converts a filename into an URL
//[c]
public func convert filename to uri (filename: string, return m: uri)
initialize (m)
def p = filename
def s = size (filename)
def path := temp string buffer
if s >= 2 && p[1] == $:
path << $/
end
repeat
def c = p++[]
if is nul (c)
break
end
if c == $\
path << $/
else
path << lower (c)
end
end
set scheme (m, "file")
set path (m, as string (path))
release (path)
end
//[cf]
//[of]:convert uri to filename (uri)
//[c]Converts an uri to a filename
//[c]
public func convert uri to filename (uri: uri, return m: string buffer)
initialize (m)
def p = path (uri)
if p [] == $/
++p
end
repeat
def c = p++[]
if is nul (c)
break
end
if c == $/
m << path separator
else
m << c
end
end
end
//[cf]
//[c]
//[of]:directory
//[of]:definition
public struct directory
private dirname: string
private data: WIN32_FIND_DATAA
private handle: HANDLE
end
//[cf]
//[c]
//[of]:initialize - release
//[of]:directory (dirname)
//[c]
public func directory (dirname: string, return m: directory)
initialize (m, dirname)
end
//[cf]
//[of]:initialize (m, dirname)
public func initialize (m: directory, dirname: string)
dirname (m) = new string (dirname)
end
//[cf]
//[of]:release (m)
public func release (m: directory)
delete (dirname (m))
end
//[cf]
//[cf]
//[of]:enumerating
//[of]:each file (m)
//[c]
public equ each file (m: directory)
def file found = first (m)
while file found
if check file (m)
yield (cFileName (data (m)))
end
file found = next (m)
end
close (m)
end
//[cf]
//[of]:each directory (m)
//[c]
public equ each directory (m: directory)
def file found = first (m)
while file found
if check directory (m)
yield (cFileName (data (m)))
end
file found = next (m)
end
close (m)
end
//[cf]
//[cf]
//[of]:private
//[of]:first (m)
private func first (m: directory)
def t := temp string buffer
t << dirname (m) << path separator << "*.*"
handle (m) = FindFirstFileA (as string (t), data (m))
release (t)
return handle (m) <> INVALID_HANDLE_VALUE
end
//[cf]
//[of]:next (m)
private func next (m: directory)
def res = FindNextFileA (handle (m), data (m))
return res <> 0
end
//[cf]
//[of]:close (m)
private func close (m: directory)
def handle = handle (m)
if handle <> INVALID_HANDLE_VALUE
FindClose (handle)
end
end
//[cf]
//[c]
//[of]:check file (m)
private func check file (m: directory)
def n = cFileName (data (m))
if n[0] == $. && (n[1] == nul char || (n[1] == $. && n[2] == nul char))
return false
end
return (dwFileAttributes (data (m)) & FILE_ATTRIBUTE_DIRECTORY) == 0
end
//[c]
//[cf]
//[of]:check directory (m)
private func check directory (m: directory)
def n = cFileName (data (m))
if n[0] == $. && (n[1] == nul char || (n[1] == $. && n[2] == nul char))
return false
end
return (dwFileAttributes (data (m)) & FILE_ATTRIBUTE_DIRECTORY) <> 0
end
//[c]
//[cf]
//[cf]
//[cf]
//[of]:filemask
//[of]:testing
//[of]:match wildcards (pattern, string)
//[c]Compares a string with a pattern having wildcards (*)
//[c]
public func match wildcards (pattern: string, value: string)
def stacked p = nil : string
def stacked q = nil : string
def p = pattern
def q = value
repeat
if p[] == $*
p += 1
stacked p = p
stacked q = q
end
if q[] == nul char
return p[] == nul char
end
if upper (p[]) == upper (q[])
p += 1
q += 1
else
if is nil (stacked p)
// no previous wild card: no match
break
end
// assimilate char and restart
stacked q += 1
p = stacked p
q = stacked q
end
end
return false
end
//[cf]
//[cf]
//[cf]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -