mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Merge branch 'master' into vm2
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -180,3 +180,4 @@ examples/cross_calculator/android/tags
|
||||
/tests/caas/main
|
||||
/tests/caasdriver
|
||||
/tools/nimgrep
|
||||
/tests/system/params
|
||||
|
||||
@@ -335,12 +335,19 @@ type
|
||||
tyConst, tyMutable, tyVarargs,
|
||||
tyIter, # unused
|
||||
tyProxy # used as errornous type (for idetools)
|
||||
tyTypeClass,
|
||||
tyTypeClass
|
||||
tyAnd
|
||||
tyOr
|
||||
tyNot
|
||||
tyAnything
|
||||
tyParametricTypeClass # structured similarly to tyGenericInst
|
||||
# lastSon is the body of the type class
|
||||
|
||||
const
|
||||
tyPureObject* = tyTuple
|
||||
GcTypeKinds* = {tyRef, tySequence, tyString}
|
||||
tyError* = tyProxy # as an errornous node should match everything
|
||||
tyTypeClasses* = {tyTypeClass, tyParametricTypeClass, tyAnd, tyOr, tyNot, tyAnything}
|
||||
|
||||
type
|
||||
TTypeKinds* = set[TTypeKind]
|
||||
@@ -378,6 +385,7 @@ type
|
||||
# used as return types for return type inference)
|
||||
tfAll, # type class requires all constraints to be met (default)
|
||||
tfAny, # type class requires any constraint to be met
|
||||
tfNot, # type class with a negative check
|
||||
tfCapturesEnv, # whether proc really captures some environment
|
||||
tfByCopy, # pass object/tuple by copy (C backend)
|
||||
tfByRef, # pass object/tuple by reference (C backend)
|
||||
@@ -1417,3 +1425,4 @@ proc isAtom*(n: PNode): bool {.inline.} =
|
||||
proc isEmptyType*(t: PType): bool {.inline.} =
|
||||
## 'void' and 'stmt' types are often equivalent to 'nil' these days:
|
||||
result = t == nil or t.kind in {tyEmpty, tyStmt}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ proc GetUniqueType*(key: PType): PType =
|
||||
if result == nil:
|
||||
gCanonicalTypes[k] = key
|
||||
result = key
|
||||
of tyTypeDesc, tyTypeClass:
|
||||
of tyTypeDesc, tyTypeClasses:
|
||||
InternalError("value expected, but got a type")
|
||||
of tyGenericParam:
|
||||
InternalError("GetUniqueType")
|
||||
|
||||
@@ -944,9 +944,9 @@ proc genMainProc(m: BModule) =
|
||||
const
|
||||
CommonMainBody =
|
||||
"\tsystemDatInit();$n" &
|
||||
"\tsystemInit();$n" &
|
||||
"$1" &
|
||||
"$2" &
|
||||
"\tsystemInit();$n" &
|
||||
"$3" &
|
||||
"$4"
|
||||
PosixNimMain =
|
||||
|
||||
@@ -550,9 +550,7 @@ proc evalSym(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
|
||||
of skProc, skConverter, skMacro, skType:
|
||||
result = n
|
||||
#result = s.getBody
|
||||
of skForVar:
|
||||
result = evalGlobalVar(c, s, flags)
|
||||
of skVar, skLet, skTemp, skResult:
|
||||
of skVar, skLet, skForVar, skTemp, skResult:
|
||||
if sfGlobal notin s.flags:
|
||||
result = evalVariable(c.tos, s, flags)
|
||||
else:
|
||||
|
||||
@@ -130,7 +130,7 @@ proc mapType(typ: PType): TJSTypeKind =
|
||||
result = etyObject
|
||||
of tyNil: result = etyNull
|
||||
of tyGenericInst, tyGenericParam, tyGenericBody, tyGenericInvokation, tyNone,
|
||||
tyForward, tyEmpty, tyExpr, tyStmt, tyTypeDesc, tyTypeClass:
|
||||
tyForward, tyEmpty, tyExpr, tyStmt, tyTypeDesc, tyTypeClasses:
|
||||
result = etyNone
|
||||
of tyProc: result = etyProc
|
||||
of tyCString: result = etyString
|
||||
|
||||
@@ -432,7 +432,9 @@ proc MainCommand* =
|
||||
else:
|
||||
rawMessage(errInvalidCommandX, command)
|
||||
|
||||
if msgs.gErrorCounter == 0 and gCmd notin {cmdInterpret, cmdRun, cmdDump}:
|
||||
if (msgs.gErrorCounter == 0 and
|
||||
gCmd notin {cmdInterpret, cmdRun, cmdDump} and
|
||||
gVerbosity > 0):
|
||||
rawMessage(hintSuccessX, [$gLinesCompiled,
|
||||
formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
|
||||
formatSize(getTotalMem())])
|
||||
|
||||
@@ -76,5 +76,7 @@ when compileOption("gc", "v2") or compileOption("gc", "refc"):
|
||||
# the new correct mark&sweet collector is too slow :-/
|
||||
GC_disableMarkAndSweep()
|
||||
condsyms.InitDefines()
|
||||
HandleCmdLine()
|
||||
quit(int8(msgs.gErrorCounter > 0))
|
||||
|
||||
when not defined(selftest):
|
||||
HandleCmdLine()
|
||||
quit(int8(msgs.gErrorCounter > 0))
|
||||
|
||||
@@ -11,6 +11,7 @@ path:"$projectPath/.."
|
||||
path:"$lib/packages/docutils"
|
||||
|
||||
define:booting
|
||||
import:testability
|
||||
|
||||
@if windows:
|
||||
cincludes: "$lib/wrappers/libffi/common"
|
||||
|
||||
@@ -322,7 +322,7 @@ proc isOpImpl(c: PContext, n: PNode): PNode =
|
||||
var match: bool
|
||||
let t2 = n[2].typ
|
||||
case t2.kind
|
||||
of tyTypeClass:
|
||||
of tyTypeClasses:
|
||||
var m: TCandidate
|
||||
InitCandidate(m, t2)
|
||||
match = matchUserTypeClass(c, m, emptyNode, t2, t1) != nil
|
||||
|
||||
@@ -20,7 +20,8 @@ proc instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable,
|
||||
if a.kind != nkSym:
|
||||
InternalError(a.info, "instantiateGenericParamList; no symbol")
|
||||
var q = a.sym
|
||||
if q.typ.kind notin {tyTypeDesc, tyGenericParam, tyTypeClass, tyExpr}: continue
|
||||
if q.typ.kind notin {tyTypeDesc, tyGenericParam, tyExpr}+tyTypeClasses:
|
||||
continue
|
||||
var s = newSym(skType, q.name, getCurrOwner(), q.info)
|
||||
s.flags = s.flags + {sfUsed, sfFromGeneric}
|
||||
var t = PType(IdTableGet(pt, q.typ))
|
||||
@@ -193,7 +194,7 @@ proc fixupProcType(c: PContext, genericType: PType,
|
||||
if result == nil: return
|
||||
|
||||
case genericType.kind
|
||||
of tyGenericParam, tyTypeClass:
|
||||
of tyGenericParam, tyTypeClasses:
|
||||
result = inst.concreteTypes[genericType.sym.position]
|
||||
of tyTypeDesc:
|
||||
result = inst.concreteTypes[genericType.sym.position]
|
||||
|
||||
@@ -676,8 +676,13 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
if lifted != nil:
|
||||
paramType.sons[i] = lifted
|
||||
result = paramType
|
||||
|
||||
if result != nil:
|
||||
|
||||
if paramType.lastSon.kind == tyTypeClass:
|
||||
result = paramType
|
||||
result.kind = tyParametricTypeClass
|
||||
result = addImplicitGeneric(copyType(result,
|
||||
getCurrOwner(), false))
|
||||
elif result != nil:
|
||||
result.kind = tyGenericInvokation
|
||||
result.sons.setLen(result.sons.len - 1)
|
||||
of tyTypeClass:
|
||||
|
||||
@@ -203,7 +203,7 @@ proc describeArgs*(c: PContext, n: PNode, startIdx = 1): string =
|
||||
add(result, argTypeToString(arg))
|
||||
if i != sonsLen(n) - 1: add(result, ", ")
|
||||
|
||||
proc typeRel*(c: var TCandidate, f, a: PType): TTypeRelation
|
||||
proc typeRel*(c: var TCandidate, f, a: PType, doBind = true): TTypeRelation
|
||||
proc concreteType(c: TCandidate, t: PType): PType =
|
||||
case t.kind
|
||||
of tyArrayConstr:
|
||||
@@ -213,7 +213,7 @@ proc concreteType(c: TCandidate, t: PType): PType =
|
||||
addSonSkipIntLit(result, t.sons[1]) # XXX: semantic checking for the type?
|
||||
of tyNil:
|
||||
result = nil # what should it be?
|
||||
of tyGenericParam:
|
||||
of tyGenericParam, tyAnything:
|
||||
result = t
|
||||
while true:
|
||||
result = PType(idTableGet(c.bindings, t))
|
||||
@@ -385,8 +385,23 @@ proc typeRangeRel(f, a: PType): TTypeRelation {.noinline.} =
|
||||
else:
|
||||
result = isNone
|
||||
|
||||
proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
# is a subtype of f?
|
||||
proc typeRel(c: var TCandidate, f, a: PType, doBind = true): TTypeRelation =
|
||||
# typeRel can be used to establish various relationships between types:
|
||||
#
|
||||
# 1) When used with concrete types, it will check for type equivalence
|
||||
# or a subtype relationship.
|
||||
#
|
||||
# 2) When used with a concrete type against a type class (such as generic
|
||||
# signature of a proc), it will check whether the concrete type is a member
|
||||
# of the designated type class.
|
||||
#
|
||||
# 3) When used with two type classes, it will check whether the types
|
||||
# matching the first type class are a strict subset of the types matching
|
||||
# the other. This allows us to compare the signatures of generic procs in
|
||||
# order to give preferrence to the most specific one:
|
||||
#
|
||||
# seq[seq[any]] is a strict subset of seq[any] and hence more specific.
|
||||
|
||||
result = isNone
|
||||
assert(f != nil)
|
||||
assert(a != nil)
|
||||
@@ -397,6 +412,50 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
return typeRel(c, f, lastSon(a))
|
||||
if a.kind == tyVar and f.kind != tyVar:
|
||||
return typeRel(c, f, a.sons[0])
|
||||
|
||||
template bindingRet(res) =
|
||||
when res == isGeneric: put(c.bindings, f, a)
|
||||
return res
|
||||
|
||||
case a.kind
|
||||
of tyOr:
|
||||
# seq[int|string] vs seq[number]
|
||||
# both int and string must match against number
|
||||
for branch in a.sons:
|
||||
if typeRel(c, f, branch, false) == isNone:
|
||||
return isNone
|
||||
|
||||
return isGeneric
|
||||
|
||||
of tyAnd:
|
||||
# seq[Sortable and Iterable] vs seq[Sortable]
|
||||
# only one match is enough
|
||||
for branch in a.sons:
|
||||
if typeRel(c, f, branch, false) != isNone:
|
||||
return isGeneric
|
||||
|
||||
return isNone
|
||||
|
||||
of tyNot:
|
||||
case f.kind
|
||||
of tyNot:
|
||||
# seq[!int] vs seq[!number]
|
||||
# seq[float] matches the first, but not the second
|
||||
# we must turn the problem around:
|
||||
# is number a subset of int?
|
||||
return typeRel(c, a.lastSon, f.lastSon)
|
||||
|
||||
else:
|
||||
# negative type classes are essentially infinite,
|
||||
# so only the `any` type class is their superset
|
||||
return if f.kind == tyAnything: isGeneric
|
||||
else: isNone
|
||||
|
||||
of tyAnything:
|
||||
return if f.kind == tyAnything: isGeneric
|
||||
else: isNone
|
||||
else: nil
|
||||
|
||||
case f.kind
|
||||
of tyEnum:
|
||||
if a.kind == f.kind and sameEnumTypes(f, a): result = isEqual
|
||||
@@ -485,9 +544,12 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
of tyOrdinal:
|
||||
if isOrdinalType(a):
|
||||
var x = if a.kind == tyOrdinal: a.sons[0] else: a
|
||||
|
||||
result = typeRel(c, f.sons[0], x)
|
||||
if result < isGeneric: result = isNone
|
||||
|
||||
if f.sonsLen == 0:
|
||||
result = isGeneric
|
||||
else:
|
||||
result = typeRel(c, f.sons[0], x)
|
||||
if result < isGeneric: result = isNone
|
||||
elif a.kind == tyGenericParam:
|
||||
result = isGeneric
|
||||
of tyForward: InternalError("forward type in typeRel()")
|
||||
@@ -574,13 +636,17 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
(a.sons[1].kind == tyChar):
|
||||
result = isConvertible
|
||||
else: nil
|
||||
of tyEmpty:
|
||||
|
||||
of tyEmpty:
|
||||
if a.kind == tyEmpty: result = isEqual
|
||||
of tyGenericInst:
|
||||
|
||||
of tyGenericInst:
|
||||
result = typeRel(c, lastSon(f), a)
|
||||
of tyGenericBody:
|
||||
|
||||
of tyGenericBody:
|
||||
let ff = lastSon(f)
|
||||
if ff != nil: result = typeRel(c, ff, a)
|
||||
|
||||
of tyGenericInvokation:
|
||||
var x = a.skipGenericAlias
|
||||
if x.kind == tyGenericInvokation or f.sons[0].kind != tyGenericBody:
|
||||
@@ -604,6 +670,38 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
if x == nil or x.kind in {tyGenericInvokation, tyGenericParam}:
|
||||
InternalError("wrong instantiated type!")
|
||||
put(c.bindings, f.sons[i], x)
|
||||
|
||||
of tyAnd:
|
||||
for branch in f.sons:
|
||||
if typeRel(c, branch, a) == isNone:
|
||||
return isNone
|
||||
|
||||
bindingRet isGeneric
|
||||
|
||||
of tyOr:
|
||||
for branch in f.sons:
|
||||
if typeRel(c, branch, a) != isNone:
|
||||
bindingRet isGeneric
|
||||
|
||||
return isNone
|
||||
|
||||
of tyNot:
|
||||
for branch in f.sons:
|
||||
if typeRel(c, branch, a) != isNone:
|
||||
return isNone
|
||||
|
||||
bindingRet isGeneric
|
||||
|
||||
of tyAnything:
|
||||
var prev = PType(idTableGet(c.bindings, f))
|
||||
if prev == nil:
|
||||
var concrete = concreteType(c, a)
|
||||
if concrete != nil and doBind:
|
||||
put(c.bindings, f, concrete)
|
||||
return isGeneric
|
||||
else:
|
||||
return typeRel(c, prev, a)
|
||||
|
||||
of tyGenericParam, tyTypeClass:
|
||||
var x = PType(idTableGet(c.bindings, f))
|
||||
if x == nil:
|
||||
@@ -634,7 +732,7 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
if concrete == nil:
|
||||
result = isNone
|
||||
else:
|
||||
put(c.bindings, f, concrete)
|
||||
if doBind: put(c.bindings, f, concrete)
|
||||
elif a.kind == tyEmpty:
|
||||
result = isGeneric
|
||||
elif x.kind == tyGenericParam:
|
||||
@@ -809,8 +907,8 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, argType: PType,
|
||||
InternalAssert a.len > 0
|
||||
r = typeRel(m, f.lastSon, a.lastSon)
|
||||
else:
|
||||
let match = matchTypeClass(m, fMaybeExpr, a)
|
||||
if match != isGeneric: r = isNone
|
||||
let match = matchTypeClass(m.bindings, fMaybeExpr, a)
|
||||
if not match: r = isNone
|
||||
else:
|
||||
# XXX: Ideally, this should happen much earlier somewhere near
|
||||
# semOpAux, but to do that, we need to be able to query the
|
||||
@@ -827,7 +925,7 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, argType: PType,
|
||||
|
||||
if r == isGeneric:
|
||||
put(m.bindings, f, arg.typ)
|
||||
of tyTypeClass:
|
||||
of tyTypeClass, tyParametricTypeClass:
|
||||
if fMaybeExpr.n != nil:
|
||||
let match = matchUserTypeClass(c, m, arg, fMaybeExpr, a)
|
||||
if match != nil:
|
||||
@@ -1130,7 +1228,7 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||
var f = 1
|
||||
while f < sonsLen(m.callee.n):
|
||||
var formal = m.callee.n.sons[f].sym
|
||||
if not ContainsOrIncl(marker, formal.position):
|
||||
if not ContainsOrIncl(marker, formal.position):
|
||||
if formal.ast == nil:
|
||||
if formal.typ.kind == tyVarargs:
|
||||
var container = newNodeIT(nkBracket, n.info, arrayConstr(c, n.info))
|
||||
@@ -1145,7 +1243,7 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||
setSon(m.call, formal.position + 1, copyTree(formal.ast))
|
||||
inc(f)
|
||||
|
||||
proc argtypeMatches*(c: PContext, f, a: PType): bool =
|
||||
proc argtypeMatches*(c: PContext, f, a: PType): bool =
|
||||
var m: TCandidate
|
||||
initCandidate(m, f)
|
||||
let res = paramTypesMatch(c, m, f, a, ast.emptyNode, nil)
|
||||
@@ -1155,3 +1253,121 @@ proc argtypeMatches*(c: PContext, f, a: PType): bool =
|
||||
result = res != nil
|
||||
|
||||
include suggest
|
||||
|
||||
tests:
|
||||
var dummyOwner = newSym(skModule, getIdent("test_module"), nil, UnknownLineInfo())
|
||||
|
||||
proc `|` (t1, t2: PType): PType =
|
||||
result = newType(tyOr, dummyOwner)
|
||||
result.rawAddSon(t1)
|
||||
result.rawAddSon(t2)
|
||||
|
||||
proc `&` (t1, t2: PType): PType =
|
||||
result = newType(tyAnd, dummyOwner)
|
||||
result.rawAddSon(t1)
|
||||
result.rawAddSon(t2)
|
||||
|
||||
proc `!` (t: PType): PType =
|
||||
result = newType(tyNot, dummyOwner)
|
||||
result.rawAddSon(t)
|
||||
|
||||
proc seq(t: PType): PType =
|
||||
result = newType(tySequence, dummyOwner)
|
||||
result.rawAddSon(t)
|
||||
|
||||
proc array(x: int, t: PType): PType =
|
||||
result = newType(tyArray, dummyOwner)
|
||||
|
||||
var n = newNodeI(nkRange, UnknownLineInfo())
|
||||
addSon(n, newIntNode(nkIntLit, 0))
|
||||
addSon(n, newIntNode(nkIntLit, x))
|
||||
let range = newType(tyRange, dummyOwner)
|
||||
|
||||
result.rawAddSon(range)
|
||||
result.rawAddSon(t)
|
||||
|
||||
suite "type classes":
|
||||
let
|
||||
int = newType(tyInt, dummyOwner)
|
||||
float = newType(tyFloat, dummyOwner)
|
||||
string = newType(tyString, dummyOwner)
|
||||
ordinal = newType(tyOrdinal, dummyOwner)
|
||||
any = newType(tyAnything, dummyOwner)
|
||||
number = int | float
|
||||
|
||||
var TFoo = newType(tyObject, dummyOwner)
|
||||
TFoo.sym = newSym(skType, getIdent"TFoo", dummyOwner, UnknownLineInfo())
|
||||
|
||||
var T1 = newType(tyGenericParam, dummyOwner)
|
||||
T1.sym = newSym(skType, getIdent"T1", dummyOwner, UnknownLineInfo())
|
||||
T1.sym.position = 0
|
||||
|
||||
var T2 = newType(tyGenericParam, dummyOwner)
|
||||
T2.sym = newSym(skType, getIdent"T2", dummyOwner, UnknownLineInfo())
|
||||
T2.sym.position = 1
|
||||
|
||||
setup:
|
||||
var c: TCandidate
|
||||
InitCandidate(c, nil)
|
||||
|
||||
template yes(x, y) =
|
||||
test astToStr(x) & " is " & astToStr(y):
|
||||
check typeRel(c, y, x) == isGeneric
|
||||
|
||||
template no(x, y) =
|
||||
test astToStr(x) & " is not " & astToStr(y):
|
||||
check typeRel(c, y, x) == isNone
|
||||
|
||||
yes seq(any), array(10, int) | seq(any)
|
||||
# Sure, seq[any] is directly included
|
||||
|
||||
yes seq(int), seq(any)
|
||||
yes seq(int), seq(number)
|
||||
# Sure, the int sequence is certainly
|
||||
# part of the number sequences (and all sequences)
|
||||
|
||||
no seq(any), seq(float)
|
||||
# Nope, seq[any] includes types that are not seq[float] (e.g. seq[int])
|
||||
|
||||
yes seq(int|string), seq(any)
|
||||
# Sure
|
||||
|
||||
yes seq(int&string), seq(any)
|
||||
# Again
|
||||
|
||||
yes seq(int&string), seq(int)
|
||||
# A bit more complicated
|
||||
# seq[int&string] is not a real type, but it's analogous to
|
||||
# seq[Sortable and Iterable], which is certainly a subset of seq[Sortable]
|
||||
|
||||
no seq(int|string), seq(int|float)
|
||||
# Nope, seq[string] is not included in not included in
|
||||
# the seq[int|float] set
|
||||
|
||||
no seq(!(int|string)), seq(string)
|
||||
# A sequence that is neither seq[int] or seq[string]
|
||||
# is obviously not seq[string]
|
||||
|
||||
no seq(!int), seq(number)
|
||||
# Now your head should start to hurt a bit
|
||||
# A sequence that is not seq[int] is not necessarily a number sequence
|
||||
# it could well be seq[string] for example
|
||||
|
||||
yes seq(!(int|string)), seq(!string)
|
||||
# all sequnece types besides seq[int] and seq[string]
|
||||
# are subset of all sequence types that are not seq[string]
|
||||
|
||||
no seq(!(int|string)), seq(!(string|TFoo))
|
||||
# Nope, seq[TFoo] is included in the first set, but not in the second
|
||||
|
||||
no seq(!string), seq(!number)
|
||||
# Nope, seq[int] in included in the first set, but not in the second
|
||||
|
||||
yes seq(!number), seq(any)
|
||||
yes seq(!int), seq(any)
|
||||
no seq(any), seq(!any)
|
||||
no seq(!int), seq(!any)
|
||||
|
||||
yes int, ordinal
|
||||
no string, ordinal
|
||||
|
||||
|
||||
5
compiler/testability.nim
Normal file
5
compiler/testability.nim
Normal file
@@ -0,0 +1,5 @@
|
||||
template tests*(body: stmt) {.immediate.} =
|
||||
when defined(selftest):
|
||||
when not defined(unittest): import unittest
|
||||
body
|
||||
|
||||
@@ -382,33 +382,34 @@ proc mutateTypeAux(marker: var TIntSet, t: PType, iter: TTypeMutator,
|
||||
if t.n != nil: result.n = mutateNode(marker, t.n, iter, closure)
|
||||
assert(result != nil)
|
||||
|
||||
proc mutateType(t: PType, iter: TTypeMutator, closure: PObject): PType =
|
||||
proc mutateType(t: PType, iter: TTypeMutator, closure: PObject): PType =
|
||||
var marker = InitIntSet()
|
||||
result = mutateTypeAux(marker, t, iter, closure)
|
||||
|
||||
proc ValueToString(a: PNode): string =
|
||||
proc ValueToString(a: PNode): string =
|
||||
case a.kind
|
||||
of nkCharLit..nkUInt64Lit: result = $(a.intVal)
|
||||
of nkFloatLit..nkFloat128Lit: result = $(a.floatVal)
|
||||
of nkStrLit..nkTripleStrLit: result = a.strVal
|
||||
else: result = "<invalid value>"
|
||||
|
||||
proc rangeToStr(n: PNode): string =
|
||||
proc rangeToStr(n: PNode): string =
|
||||
assert(n.kind == nkRange)
|
||||
result = ValueToString(n.sons[0]) & ".." & ValueToString(n.sons[1])
|
||||
|
||||
const
|
||||
typeToStr: array[TTypeKind, string] = ["None", "bool", "Char", "empty",
|
||||
"Array Constructor [$1]", "nil", "expr", "stmt", "typeDesc",
|
||||
"GenericInvokation", "GenericBody", "GenericInst", "GenericParam",
|
||||
"distinct $1", "enum", "ordinal[$1]", "array[$1, $2]", "object", "tuple",
|
||||
"set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc",
|
||||
typeToStr: array[TTypeKind, string] = ["None", "bool", "Char", "empty",
|
||||
"Array Constructor [$1]", "nil", "expr", "stmt", "typeDesc",
|
||||
"GenericInvokation", "GenericBody", "GenericInst", "GenericParam",
|
||||
"distinct $1", "enum", "ordinal[$1]", "array[$1, $2]", "object", "tuple",
|
||||
"set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc",
|
||||
"pointer", "OpenArray[$1]", "string", "CString", "Forward",
|
||||
"int", "int8", "int16", "int32", "int64",
|
||||
"float", "float32", "float64", "float128",
|
||||
"uint", "uint8", "uint16", "uint32", "uint64",
|
||||
"bignum", "const ",
|
||||
"!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass"]
|
||||
"!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass",
|
||||
"ParametricTypeClass", "and", "or", "not", "any"]
|
||||
|
||||
proc consToStr(t: PType): string =
|
||||
if t.len > 0: result = t.typeToString
|
||||
@@ -421,7 +422,7 @@ proc constraintsToStr(t: PType): string =
|
||||
if i > 0: result.add(sep)
|
||||
result.add(t.sons[i].consToStr)
|
||||
|
||||
proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
var t = typ
|
||||
result = ""
|
||||
if t == nil: return
|
||||
@@ -861,7 +862,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||
of tyGenericParam, tyGenericInvokation, tyGenericBody, tySequence,
|
||||
tyOpenArray, tySet, tyRef, tyPtr, tyVar, tyArrayConstr,
|
||||
tyArray, tyProc, tyConst, tyMutable, tyVarargs, tyIter,
|
||||
tyOrdinal, tyTypeClass:
|
||||
tyOrdinal, tyTypeClasses:
|
||||
CycleCheck()
|
||||
result = sameChildrenAux(a, b, c) and sameFlags(a, b)
|
||||
if result and (a.kind == tyProc):
|
||||
@@ -1042,7 +1043,7 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind,
|
||||
# XXX er ... no? these should not be allowed!
|
||||
of tyEmpty:
|
||||
result = taField in flags
|
||||
of tyTypeClass:
|
||||
of tyTypeClasses:
|
||||
result = true
|
||||
of tyGenericBody, tyGenericParam, tyForward, tyNone, tyGenericInvokation:
|
||||
result = false
|
||||
|
||||
10
doc/tut2.txt
10
doc/tut2.txt
@@ -16,9 +16,9 @@ Introduction
|
||||
|
||||
|
||||
This document is a tutorial for the advanced constructs of the *Nimrod*
|
||||
programming language. **Note that this document is somewhat obsolete as
|
||||
the `manual <manual.html>`_ contains many more examples of the advanced
|
||||
language features.**
|
||||
programming language. **Note that this document is somewhat obsolete as the**
|
||||
`manual <manual.html>`_ **contains many more examples of the advanced language
|
||||
features.**
|
||||
|
||||
|
||||
Pragmas
|
||||
@@ -852,7 +852,7 @@ to be included along the program containing the license information::
|
||||
The ``readCfgAtRuntime`` proc will open the given filename and return a
|
||||
``TTable`` from the `tables module <tables.html>`_. The parsing of the file is
|
||||
done (without much care for handling invalid data or corner cases) using the
|
||||
``split`` proc from the `strutils module <strutils.html>`_. There are many
|
||||
``splitLines`` proc from the `strutils module <strutils.html>`_. There are many
|
||||
things which can fail; mind the purpose is explaining how to make this run at
|
||||
compile time, not how to properly implement a DRM scheme.
|
||||
|
||||
@@ -948,7 +948,7 @@ Generating AST by hand
|
||||
|
||||
To generate an AST we would need to intimately know the structures used by the
|
||||
Nimrod compiler exposed in the `macros module <macros.html>`_, which at first
|
||||
look seems a daunting task. But we can use a helper shortcut the ``dumpTree``
|
||||
look seems a daunting task. But we can use as helper shortcut the ``dumpTree``
|
||||
macro, which is used as a statement macro instead of an expression macro.
|
||||
Since we know that we want to generate a bunch of ``const`` symbols we can
|
||||
create the following source file and compile it to see what the compiler
|
||||
|
||||
9
examples/wingui.nim
Normal file
9
examples/wingui.nim
Normal file
@@ -0,0 +1,9 @@
|
||||
# test a Windows GUI application
|
||||
|
||||
import
|
||||
windows, shellapi, nb30, mmsystem, shfolder
|
||||
|
||||
#proc MessageBox(hWnd: int, lpText, lpCaption: CString, uType: uint): int
|
||||
# {stdcall, import: "MessageBox", header: "<windows.h>"}
|
||||
|
||||
discard MessageBox(0, "Hello World!", "Nimrod GUI Application", 0)
|
||||
@@ -180,6 +180,21 @@ proc Open*(connection, user, password, database: string): TDbConn {.
|
||||
tags: [FDb].} =
|
||||
## opens a database connection. Raises `EDb` if the connection could not
|
||||
## be established.
|
||||
##
|
||||
## Clients can also use Postgres keyword/value connection strings to
|
||||
## connect.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
##
|
||||
## con = Open("", "", "", "host=localhost port=5432 dbname=mydb")
|
||||
##
|
||||
## See http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
|
||||
## for more information.
|
||||
##
|
||||
## Note that the connection parameter is not used but exists to maintain
|
||||
## the nimrod db api.
|
||||
result = PQsetdbLogin(nil, nil, nil, nil, database, user, password)
|
||||
if PQStatus(result) != CONNECTION_OK: dbError(result) # result = nil
|
||||
|
||||
|
||||
300
lib/pure/os.nim
300
lib/pure/os.nim
@@ -21,7 +21,7 @@ import
|
||||
|
||||
when defined(windows):
|
||||
import winlean
|
||||
elif defined(posix):
|
||||
elif defined(posix):
|
||||
import posix
|
||||
else:
|
||||
{.error: "OS module not ported to your operating system!".}
|
||||
@@ -33,7 +33,7 @@ type
|
||||
## from an environment variable
|
||||
FWriteEnv* = object of FWriteIO ## effect that denotes a write
|
||||
## to an environment variable
|
||||
|
||||
|
||||
FReadDir* = object of FReadIO ## effect that denotes a write operation to
|
||||
## the directory structure
|
||||
FWriteDir* = object of FWriteIO ## effect that denotes a write operation to
|
||||
@@ -179,7 +179,7 @@ proc OSErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||
## Returns "" if no error occured.
|
||||
##
|
||||
## **Deprecated since version 0.9.4**: use the other ``OSErrorMsg`` proc.
|
||||
|
||||
|
||||
result = ""
|
||||
when defined(Windows):
|
||||
var err = GetLastError()
|
||||
@@ -276,7 +276,7 @@ proc OSLastError*(): TOSErrorCode =
|
||||
## On Windows some OS calls can reset the error code to ``0`` causing this
|
||||
## procedure to return ``0``. It is therefore advised to call this procedure
|
||||
## immediately after an OS call fails. On POSIX systems this is not a problem.
|
||||
|
||||
|
||||
when defined(windows):
|
||||
result = TOSErrorCode(GetLastError())
|
||||
else:
|
||||
@@ -342,7 +342,14 @@ when defined(windows):
|
||||
template getCommandLine(): expr = getCommandLineW()
|
||||
|
||||
proc skipFindData(f: TWIN32_FIND_DATA): bool {.inline.} =
|
||||
result = f.cFilename[0].int == ord('.')
|
||||
let
|
||||
nul = 0
|
||||
dot = ord('.')
|
||||
result = (f.cFilename[0].int == dot)
|
||||
if result:
|
||||
result = (f.cFilename[1].int in {dot, nul})
|
||||
if result:
|
||||
result = (f.cFilename[2].int == nul)
|
||||
|
||||
template getFilename(f: expr): expr =
|
||||
$cast[WideCString](addr(f.cFilename[0]))
|
||||
@@ -352,11 +359,18 @@ when defined(windows):
|
||||
template getCommandLine(): expr = getCommandLineA()
|
||||
|
||||
proc skipFindData(f: TWIN32_FIND_DATA): bool {.inline.} =
|
||||
result = f.cFilename[0] == '.'
|
||||
let
|
||||
nul = '\0'
|
||||
dot = '.'
|
||||
result = (f.cFilename[0] == dot)
|
||||
if result:
|
||||
result = (f.cFilename[1] in {dot, nul})
|
||||
if result:
|
||||
result = (f.cFilename[2] == nul)
|
||||
|
||||
template getFilename(f: expr): expr = $f.cFilename
|
||||
|
||||
proc existsFile*(filename: string): bool {.rtl, extern: "nos$1",
|
||||
|
||||
proc existsFile*(filename: string): bool {.rtl, extern: "nos$1",
|
||||
tags: [FReadDir].} =
|
||||
## Returns true if the file exists, false otherwise.
|
||||
when defined(windows):
|
||||
@@ -410,7 +424,7 @@ proc getLastAccessTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
||||
result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime))
|
||||
findclose(h)
|
||||
|
||||
proc getCreationTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
||||
proc getCreationTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
||||
## Returns the `file`'s creation time.
|
||||
when defined(posix):
|
||||
var res: TStat
|
||||
@@ -524,7 +538,7 @@ proc SplitPath*(path: string): tuple[head, tail: string] {.
|
||||
## Splits a directory into (head, tail), so that
|
||||
## ``JoinPath(head, tail) == path``.
|
||||
##
|
||||
## Examples:
|
||||
## Examples:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## SplitPath("usr/local/bin") -> ("usr/local", "bin")
|
||||
@@ -567,7 +581,7 @@ proc parentDir*(path: string): string {.
|
||||
|
||||
proc isRootDir*(path: string): bool {.
|
||||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
## Checks whether a given `path` is a root directory
|
||||
## Checks whether a given `path` is a root directory
|
||||
result = parentDirPos(path) < 0
|
||||
|
||||
iterator parentDirs*(path: string, fromRoot=false, inclusive=true): string =
|
||||
@@ -589,7 +603,7 @@ iterator parentDirs*(path: string, fromRoot=false, inclusive=true): string =
|
||||
else:
|
||||
for i in countup(0, path.len - 2): # ignore the last /
|
||||
# deal with non-normalized paths such as /foo//bar//baz
|
||||
if path[i] in {dirsep, altsep} and
|
||||
if path[i] in {dirsep, altsep} and
|
||||
(i == 0 or path[i-1] notin {dirsep, altsep}):
|
||||
yield path.substr(0, i)
|
||||
|
||||
@@ -642,7 +656,7 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
||||
var dotPos = path.len
|
||||
for i in countdown(len(path)-1, 0):
|
||||
if path[i] == ExtSep:
|
||||
if dotPos == path.len and i > 0 and
|
||||
if dotPos == path.len and i > 0 and
|
||||
path[i-1] notin {dirsep, altsep}: dotPos = i
|
||||
elif path[i] in {dirsep, altsep}:
|
||||
sepPos = i
|
||||
@@ -653,7 +667,7 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
||||
|
||||
proc extractFilename*(path: string): string {.
|
||||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
## Extracts the filename of a given `path`. This is the same as
|
||||
## Extracts the filename of a given `path`. This is the same as
|
||||
## ``name & ext`` from ``splitFile(path)``.
|
||||
if path.len == 0 or path[path.len-1] in {dirSep, altSep}:
|
||||
result = ""
|
||||
@@ -669,7 +683,7 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||
var unused: widecstring
|
||||
var res = newWideCString("", bufsize div 2)
|
||||
var L = GetFullPathNameW(newWideCString(filename), bufsize, res, unused)
|
||||
if L <= 0'i32 or L >= bufsize:
|
||||
if L <= 0'i32 or L >= bufsize:
|
||||
OSError(OSLastError())
|
||||
result = res$L
|
||||
else:
|
||||
@@ -684,7 +698,7 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||
var r = realpath(filename, result)
|
||||
if r.isNil: OSError(OSLastError())
|
||||
setlen(result, c_strlen(result))
|
||||
|
||||
|
||||
proc ChangeFileExt*(filename, ext: string): string {.
|
||||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
## Changes the file extension to `ext`.
|
||||
@@ -740,12 +754,12 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1".} =
|
||||
elif defined(posix):
|
||||
result = path[0] == '/'
|
||||
|
||||
proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||
proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||
tags: [FReadDir].} =
|
||||
## Returns True if both pathname arguments refer to the same physical
|
||||
## Returns True if both pathname arguments refer to the same physical
|
||||
## file or directory. Raises an exception if any of the files does not
|
||||
## exist or information about it can not be obtained.
|
||||
##
|
||||
##
|
||||
## This proc will return true if given two alternative hard-linked or
|
||||
## sym-linked paths to the same file or directory.
|
||||
when defined(Windows):
|
||||
@@ -761,7 +775,7 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||
|
||||
var f1 = OpenHandle(p1)
|
||||
var f2 = OpenHandle(p2)
|
||||
|
||||
|
||||
else:
|
||||
template OpenHandle(path: expr): expr =
|
||||
CreateFileA(path, 0'i32, FILE_SHARE_DELETE or FILE_SHARE_READ or
|
||||
@@ -829,7 +843,87 @@ proc sameFileContent*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||
close(a)
|
||||
close(b)
|
||||
|
||||
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
type
|
||||
TFilePermission* = enum ## file access permission; modelled after UNIX
|
||||
fpUserExec, ## execute access for the file owner
|
||||
fpUserWrite, ## write access for the file owner
|
||||
fpUserRead, ## read access for the file owner
|
||||
fpGroupExec, ## execute access for the group
|
||||
fpGroupWrite, ## write access for the group
|
||||
fpGroupRead, ## read access for the group
|
||||
fpOthersExec, ## execute access for others
|
||||
fpOthersWrite, ## write access for others
|
||||
fpOthersRead ## read access for others
|
||||
|
||||
proc getFilePermissions*(filename: string): set[TFilePermission] {.
|
||||
rtl, extern: "nos$1", tags: [FReadDir].} =
|
||||
## retrieves file permissions for `filename`. `OSError` is raised in case of
|
||||
## an error. On Windows, only the ``readonly`` flag is checked, every other
|
||||
## permission is available in any case.
|
||||
when defined(posix):
|
||||
var a: TStat
|
||||
if stat(filename, a) < 0'i32: OSError(OSLastError())
|
||||
result = {}
|
||||
if (a.st_mode and S_IRUSR) != 0'i32: result.incl(fpUserRead)
|
||||
if (a.st_mode and S_IWUSR) != 0'i32: result.incl(fpUserWrite)
|
||||
if (a.st_mode and S_IXUSR) != 0'i32: result.incl(fpUserExec)
|
||||
|
||||
if (a.st_mode and S_IRGRP) != 0'i32: result.incl(fpGroupRead)
|
||||
if (a.st_mode and S_IWGRP) != 0'i32: result.incl(fpGroupWrite)
|
||||
if (a.st_mode and S_IXGRP) != 0'i32: result.incl(fpGroupExec)
|
||||
|
||||
if (a.st_mode and S_IROTH) != 0'i32: result.incl(fpOthersRead)
|
||||
if (a.st_mode and S_IWOTH) != 0'i32: result.incl(fpOthersWrite)
|
||||
if (a.st_mode and S_IXOTH) != 0'i32: result.incl(fpOthersExec)
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, GetFileAttributesW, filename)
|
||||
else:
|
||||
var res = GetFileAttributesA(filename)
|
||||
if res == -1'i32: OSError(OSLastError())
|
||||
if (res and FILE_ATTRIBUTE_READONLY) != 0'i32:
|
||||
result = {fpUserExec, fpUserRead, fpGroupExec, fpGroupRead,
|
||||
fpOthersExec, fpOthersRead}
|
||||
else:
|
||||
result = {fpUserExec..fpOthersRead}
|
||||
|
||||
proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
|
||||
rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
## sets the file permissions for `filename`. `OSError` is raised in case of
|
||||
## an error. On Windows, only the ``readonly`` flag is changed, depending on
|
||||
## ``fpUserWrite``.
|
||||
when defined(posix):
|
||||
var p = 0'i32
|
||||
if fpUserRead in permissions: p = p or S_IRUSR
|
||||
if fpUserWrite in permissions: p = p or S_IWUSR
|
||||
if fpUserExec in permissions: p = p or S_IXUSR
|
||||
|
||||
if fpGroupRead in permissions: p = p or S_IRGRP
|
||||
if fpGroupWrite in permissions: p = p or S_IWGRP
|
||||
if fpGroupExec in permissions: p = p or S_IXGRP
|
||||
|
||||
if fpOthersRead in permissions: p = p or S_IROTH
|
||||
if fpOthersWrite in permissions: p = p or S_IWOTH
|
||||
if fpOthersExec in permissions: p = p or S_IXOTH
|
||||
|
||||
if chmod(filename, p) != 0: OSError(OSLastError())
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, GetFileAttributesW, filename)
|
||||
else:
|
||||
var res = GetFileAttributesA(filename)
|
||||
if res == -1'i32: OSError(OSLastError())
|
||||
if fpUserWrite in permissions:
|
||||
res = res and not FILE_ATTRIBUTE_READONLY
|
||||
else:
|
||||
res = res or FILE_ATTRIBUTE_READONLY
|
||||
when useWinUnicode:
|
||||
wrapBinary(res2, SetFileAttributesW, filename, res)
|
||||
else:
|
||||
var res2 = SetFileAttributesA(filename, res)
|
||||
if res2 == - 1'i32: OSError(OSLastError())
|
||||
|
||||
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
tags: [FReadIO, FWriteIO].} =
|
||||
## Copies a file from `source` to `dest`.
|
||||
##
|
||||
@@ -870,7 +964,7 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
close(s)
|
||||
close(d)
|
||||
|
||||
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
tags: [FReadIO, FWriteIO].} =
|
||||
## Moves a file from `source` to `dest`. If this fails, `EOS` is raised.
|
||||
if crename(source, dest) != 0'i32:
|
||||
@@ -882,10 +976,13 @@ when not defined(ENOENT):
|
||||
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
## Removes the `file`. If this fails, `EOS` is raised. This does not fail
|
||||
## if the file never existed in the first place.
|
||||
## On Windows, ignores the read-only attribute.
|
||||
when defined(Windows):
|
||||
setFilePermissions(file, {fpUserWrite})
|
||||
if cremove(file) != 0'i32 and errno != ENOENT:
|
||||
raise newException(EOS, $strerror(errno))
|
||||
|
||||
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
||||
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
||||
tags: [FExecIO].} =
|
||||
## Executes a `shell command`:idx:.
|
||||
##
|
||||
@@ -897,7 +994,7 @@ proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
||||
## module.
|
||||
result = csystem(command)
|
||||
|
||||
# Environment handling cannot be put into RTL, because the ``envPairs``
|
||||
# Environment handling cannot be put into RTL, because the ``envPairs``
|
||||
# iterator depends on ``environment``.
|
||||
|
||||
var
|
||||
@@ -943,11 +1040,11 @@ when defined(windows):
|
||||
|
||||
else:
|
||||
const
|
||||
useNSGetEnviron = defined(macosx) and
|
||||
useNSGetEnviron = defined(macosx) and
|
||||
(defined(createNimRtl) or defined(useNimRtl))
|
||||
when useNSGetEnviron:
|
||||
# From the manual:
|
||||
# Shared libraries and bundles don't have direct access to environ,
|
||||
# Shared libraries and bundles don't have direct access to environ,
|
||||
# which is only available to the loader ld(1) when a complete program
|
||||
# is being linked.
|
||||
# The environment routines can still be used, but if direct access to
|
||||
@@ -1025,13 +1122,13 @@ proc putEnv*(key, val: string) {.tags: [FWriteEnv].} =
|
||||
if SetEnvironmentVariableA(key, val) == 0'i32: OSError(OSLastError())
|
||||
|
||||
iterator envPairs*(): tuple[key, value: TaintedString] {.tags: [FReadEnv].} =
|
||||
## Iterate over all `environments variables`:idx:. In the first component
|
||||
## Iterate over all `environments variables`:idx:. In the first component
|
||||
## of the tuple is the name of the current variable stored, in the second
|
||||
## its value.
|
||||
getEnvVarsC()
|
||||
for i in 0..high(environment):
|
||||
var p = find(environment[i], '=')
|
||||
yield (TaintedString(substr(environment[i], 0, p-1)),
|
||||
yield (TaintedString(substr(environment[i], 0, p-1)),
|
||||
TaintedString(substr(environment[i], p+1)))
|
||||
|
||||
iterator walkFiles*(pattern: string): string {.tags: [FReadDir].} =
|
||||
@@ -1125,7 +1222,7 @@ iterator walkDir*(dir: string): tuple[kind: TPathComponent, path: string] {.
|
||||
|
||||
iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string {.
|
||||
tags: [FReadDir].} =
|
||||
## walks over the directory `dir` and yields for each file in `dir`. The
|
||||
## walks over the directory `dir` and yields for each file in `dir`. The
|
||||
## full path for each file is returned.
|
||||
## Walking is recursive. `filter` controls the behaviour of the iterator:
|
||||
##
|
||||
@@ -1137,7 +1234,7 @@ iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string {.
|
||||
## ``pcDir`` follow real directories
|
||||
## ``pcLinkToDir`` follow symbolic links to directories
|
||||
## --------------------- ---------------------------------------------
|
||||
##
|
||||
##
|
||||
var stack = @[dir]
|
||||
while stack.len > 0:
|
||||
for k,p in walkDir(stack.pop()):
|
||||
@@ -1146,14 +1243,14 @@ iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string {.
|
||||
of pcFile, pcLinkToFile: yield p
|
||||
of pcDir, pcLinkToDir: stack.add(p)
|
||||
|
||||
proc rawRemoveDir(dir: string) =
|
||||
proc rawRemoveDir(dir: string) =
|
||||
when defined(windows):
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, RemoveDirectoryW, dir)
|
||||
else:
|
||||
var res = RemoveDirectoryA(dir)
|
||||
let lastError = OSLastError()
|
||||
if res == 0'i32 and lastError.int32 != 3'i32 and
|
||||
if res == 0'i32 and lastError.int32 != 3'i32 and
|
||||
lastError.int32 != 18'i32 and lastError.int32 != 2'i32:
|
||||
OSError(lastError)
|
||||
else:
|
||||
@@ -1166,7 +1263,7 @@ proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [
|
||||
##
|
||||
## If this fails, `EOS` is raised. This does not fail if the directory never
|
||||
## existed in the first place.
|
||||
for kind, path in walkDir(dir):
|
||||
for kind, path in walkDir(dir):
|
||||
case kind
|
||||
of pcFile, pcLinkToFile, pcLinkToDir: removeFile(path)
|
||||
of pcDir: removeDir(path)
|
||||
@@ -1192,7 +1289,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
##
|
||||
## The directory may contain several subdirectories that do not exist yet.
|
||||
## The full path is created. If this fails, `EOS` is raised. It does **not**
|
||||
## fail if the path already exists because for most usages this does not
|
||||
## fail if the path already exists because for most usages this does not
|
||||
## indicate an error.
|
||||
var omitNext = false
|
||||
when defined(doslike):
|
||||
@@ -1205,7 +1302,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
rawCreateDir(substr(dir, 0, i-1))
|
||||
rawCreateDir(dir)
|
||||
|
||||
proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
tags: [FWriteIO, FReadIO].} =
|
||||
## Copies a directory from `source` to `dest`. If this fails, `EOS` is raised.
|
||||
createDir(dest)
|
||||
@@ -1220,7 +1317,7 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
|
||||
proc parseCmdLine*(c: string): seq[string] {.
|
||||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
## Splits a command line into several components;
|
||||
## Splits a command line into several components;
|
||||
## This proc is only occassionally useful, better use the `parseopt` module.
|
||||
##
|
||||
## On Windows, it uses the following parsing rules
|
||||
@@ -1247,7 +1344,7 @@ proc parseCmdLine*(c: string): seq[string] {.
|
||||
## causing a literal double quotation mark (") to be placed in argv.
|
||||
##
|
||||
## On Posix systems, it uses the following parsing rules:
|
||||
## Components are separated by whitespace unless the whitespace
|
||||
## Components are separated by whitespace unless the whitespace
|
||||
## occurs within ``"`` or ``'`` quotes.
|
||||
result = @[]
|
||||
var i = 0
|
||||
@@ -1260,31 +1357,31 @@ proc parseCmdLine*(c: string): seq[string] {.
|
||||
if c[i] == '\0': break
|
||||
var inQuote = false
|
||||
while true:
|
||||
case c[i]
|
||||
case c[i]
|
||||
of '\0': break
|
||||
of '\\':
|
||||
var j = i
|
||||
while c[j] == '\\': inc(j)
|
||||
if c[j] == '"':
|
||||
if c[j] == '"':
|
||||
for k in 1..(j-i) div 2: a.add('\\')
|
||||
if (j-i) mod 2 == 0:
|
||||
if (j-i) mod 2 == 0:
|
||||
i = j
|
||||
else:
|
||||
else:
|
||||
a.add('"')
|
||||
i = j+1
|
||||
else:
|
||||
else:
|
||||
a.add(c[i])
|
||||
inc(i)
|
||||
of '"':
|
||||
inc(i)
|
||||
if not inQuote: inQuote = true
|
||||
elif c[i] == '"':
|
||||
elif c[i] == '"':
|
||||
a.add(c[i])
|
||||
inc(i)
|
||||
else:
|
||||
inQuote = false
|
||||
break
|
||||
of ' ', '\t':
|
||||
of ' ', '\t':
|
||||
if not inQuote: break
|
||||
a.add(c[i])
|
||||
inc(i)
|
||||
@@ -1306,86 +1403,6 @@ proc parseCmdLine*(c: string): seq[string] {.
|
||||
add(a, c[i])
|
||||
inc(i)
|
||||
add(result, a)
|
||||
|
||||
type
|
||||
TFilePermission* = enum ## file access permission; modelled after UNIX
|
||||
fpUserExec, ## execute access for the file owner
|
||||
fpUserWrite, ## write access for the file owner
|
||||
fpUserRead, ## read access for the file owner
|
||||
fpGroupExec, ## execute access for the group
|
||||
fpGroupWrite, ## write access for the group
|
||||
fpGroupRead, ## read access for the group
|
||||
fpOthersExec, ## execute access for others
|
||||
fpOthersWrite, ## write access for others
|
||||
fpOthersRead ## read access for others
|
||||
|
||||
proc getFilePermissions*(filename: string): set[TFilePermission] {.
|
||||
rtl, extern: "nos$1", tags: [FReadDir].} =
|
||||
## retrieves file permissions for `filename`. `OSError` is raised in case of
|
||||
## an error. On Windows, only the ``readonly`` flag is checked, every other
|
||||
## permission is available in any case.
|
||||
when defined(posix):
|
||||
var a: TStat
|
||||
if stat(filename, a) < 0'i32: OSError(OSLastError())
|
||||
result = {}
|
||||
if (a.st_mode and S_IRUSR) != 0'i32: result.incl(fpUserRead)
|
||||
if (a.st_mode and S_IWUSR) != 0'i32: result.incl(fpUserWrite)
|
||||
if (a.st_mode and S_IXUSR) != 0'i32: result.incl(fpUserExec)
|
||||
|
||||
if (a.st_mode and S_IRGRP) != 0'i32: result.incl(fpGroupRead)
|
||||
if (a.st_mode and S_IWGRP) != 0'i32: result.incl(fpGroupWrite)
|
||||
if (a.st_mode and S_IXGRP) != 0'i32: result.incl(fpGroupExec)
|
||||
|
||||
if (a.st_mode and S_IROTH) != 0'i32: result.incl(fpOthersRead)
|
||||
if (a.st_mode and S_IWOTH) != 0'i32: result.incl(fpOthersWrite)
|
||||
if (a.st_mode and S_IXOTH) != 0'i32: result.incl(fpOthersExec)
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, GetFileAttributesW, filename)
|
||||
else:
|
||||
var res = GetFileAttributesA(filename)
|
||||
if res == -1'i32: OSError(OSLastError())
|
||||
if (res and FILE_ATTRIBUTE_READONLY) != 0'i32:
|
||||
result = {fpUserExec, fpUserRead, fpGroupExec, fpGroupRead,
|
||||
fpOthersExec, fpOthersRead}
|
||||
else:
|
||||
result = {fpUserExec..fpOthersRead}
|
||||
|
||||
proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
|
||||
rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
## sets the file permissions for `filename`. `OSError` is raised in case of
|
||||
## an error. On Windows, only the ``readonly`` flag is changed, depending on
|
||||
## ``fpUserWrite``.
|
||||
when defined(posix):
|
||||
var p = 0'i32
|
||||
if fpUserRead in permissions: p = p or S_IRUSR
|
||||
if fpUserWrite in permissions: p = p or S_IWUSR
|
||||
if fpUserExec in permissions: p = p or S_IXUSR
|
||||
|
||||
if fpGroupRead in permissions: p = p or S_IRGRP
|
||||
if fpGroupWrite in permissions: p = p or S_IWGRP
|
||||
if fpGroupExec in permissions: p = p or S_IXGRP
|
||||
|
||||
if fpOthersRead in permissions: p = p or S_IROTH
|
||||
if fpOthersWrite in permissions: p = p or S_IWOTH
|
||||
if fpOthersExec in permissions: p = p or S_IXOTH
|
||||
|
||||
if chmod(filename, p) != 0: OSError(OSLastError())
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, GetFileAttributesW, filename)
|
||||
else:
|
||||
var res = GetFileAttributesA(filename)
|
||||
if res == -1'i32: OSError(OSLastError())
|
||||
if fpUserWrite in permissions:
|
||||
res = res and not FILE_ATTRIBUTE_READONLY
|
||||
else:
|
||||
res = res or FILE_ATTRIBUTE_READONLY
|
||||
when useWinUnicode:
|
||||
wrapBinary(res2, SetFileAttributesW, filename, res)
|
||||
else:
|
||||
var res2 = SetFileAttributesA(filename, res)
|
||||
if res2 == - 1'i32: OSError(OSLastError())
|
||||
|
||||
proc copyFileWithPermissions*(source, dest: string,
|
||||
ignorePermissionErrors = true) =
|
||||
@@ -1407,19 +1424,19 @@ proc copyFileWithPermissions*(source, dest: string,
|
||||
if not ignorePermissionErrors:
|
||||
raise
|
||||
|
||||
proc inclFilePermissions*(filename: string,
|
||||
proc inclFilePermissions*(filename: string,
|
||||
permissions: set[TFilePermission]) {.
|
||||
rtl, extern: "nos$1", tags: [FReadDir, FWriteDir].} =
|
||||
## a convenience procedure for:
|
||||
## a convenience procedure for:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## setFilePermissions(filename, getFilePermissions(filename)+permissions)
|
||||
setFilePermissions(filename, getFilePermissions(filename)+permissions)
|
||||
|
||||
proc exclFilePermissions*(filename: string,
|
||||
proc exclFilePermissions*(filename: string,
|
||||
permissions: set[TFilePermission]) {.
|
||||
rtl, extern: "nos$1", tags: [FReadDir, FWriteDir].} =
|
||||
## a convenience procedure for:
|
||||
## a convenience procedure for:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## setFilePermissions(filename, getFilePermissions(filename)-permissions)
|
||||
@@ -1459,7 +1476,7 @@ when defined(windows):
|
||||
if isNil(ownArgv): ownArgv = parseCmdLine($getCommandLine())
|
||||
result = ownArgv.len-1
|
||||
|
||||
proc paramStr*(i: int): TaintedString {.rtl, extern: "nos$1",
|
||||
proc paramStr*(i: int): TaintedString {.rtl, extern: "nos$1",
|
||||
tags: [FReadIO].} =
|
||||
## Returns the `i`-th `command line argument`:idx: given to the
|
||||
## application.
|
||||
@@ -1481,6 +1498,12 @@ elif not defined(createNimRtl):
|
||||
|
||||
proc paramCount*(): int {.tags: [FReadIO].} = return cmdCount-1
|
||||
|
||||
when defined(paramCount):
|
||||
proc commandLineParams*(): seq[TaintedString] =
|
||||
result = @[]
|
||||
for i in 1..paramCount():
|
||||
result.add(paramStr(i))
|
||||
|
||||
when defined(linux) or defined(solaris) or defined(bsd) or defined(aix):
|
||||
proc getApplAux(procPath: string): string =
|
||||
result = newString(256)
|
||||
@@ -1494,7 +1517,7 @@ when defined(macosx):
|
||||
type
|
||||
cuint32* {.importc: "unsigned int", nodecl.} = int
|
||||
## This is the same as the type ``uint32_t`` in *C*.
|
||||
|
||||
|
||||
# a really hacky solution: since we like to include 2 headers we have to
|
||||
# define two procs which in reality are the same
|
||||
proc getExecPath1(c: cstring, size: var cuint32) {.
|
||||
@@ -1553,13 +1576,13 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [FReadIO].} =
|
||||
|
||||
proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||
## Returns the filename of the application's executable.
|
||||
## **Deprecated since version 0.8.12**: use ``getAppFilename``
|
||||
## **Deprecated since version 0.8.12**: use ``getAppFilename``
|
||||
## instead.
|
||||
result = getAppFilename()
|
||||
|
||||
proc getApplicationDir*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||
## Returns the directory of the application's executable.
|
||||
## **Deprecated since version 0.8.12**: use ``getAppDir``
|
||||
## **Deprecated since version 0.8.12**: use ``getAppDir``
|
||||
## instead.
|
||||
result = splitFile(getAppFilename()).dir
|
||||
|
||||
@@ -1580,7 +1603,7 @@ proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [FTime].} =
|
||||
|
||||
proc getFileSize*(file: string): biggestInt {.rtl, extern: "nos$1",
|
||||
tags: [FReadIO].} =
|
||||
## returns the file size of `file`. Can raise ``EOS``.
|
||||
## returns the file size of `file`. Can raise ``EOS``.
|
||||
when defined(windows):
|
||||
var a: TWin32FindData
|
||||
var resA = findfirstFile(file, a)
|
||||
@@ -1589,20 +1612,20 @@ proc getFileSize*(file: string): biggestInt {.rtl, extern: "nos$1",
|
||||
findclose(resA)
|
||||
else:
|
||||
var f: TFile
|
||||
if open(f, file):
|
||||
if open(f, file):
|
||||
result = getFileSize(f)
|
||||
close(f)
|
||||
else: OSError(OSLastError())
|
||||
|
||||
proc findExe*(exe: string): string {.tags: [FReadDir, FReadEnv].} =
|
||||
proc findExe*(exe: string): string {.tags: [FReadDir, FReadEnv].} =
|
||||
## Searches for `exe` in the current working directory and then
|
||||
## in directories listed in the ``PATH`` environment variable.
|
||||
## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe`
|
||||
## in directories listed in the ``PATH`` environment variable.
|
||||
## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe`
|
||||
## is added an ``.exe`` file extension if it has no extension.
|
||||
result = addFileExt(exe, os.exeExt)
|
||||
if ExistsFile(result): return
|
||||
var path = string(os.getEnv("PATH"))
|
||||
for candidate in split(path, pathSep):
|
||||
for candidate in split(path, pathSep):
|
||||
var x = candidate / result
|
||||
if ExistsFile(x): return x
|
||||
result = ""
|
||||
@@ -1629,4 +1652,3 @@ proc expandTilde*(path: string): string =
|
||||
result = path
|
||||
|
||||
{.pop.}
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@
|
||||
## This module provides the standard Nimrod command line parser.
|
||||
## It supports one convenience iterator over all command line options and some
|
||||
## lower-level features.
|
||||
|
||||
##
|
||||
## DEPRECATED. Use parseopt2 instead as this version has issues with spaces
|
||||
## in arguments.
|
||||
{.deprecated.}
|
||||
{.push debugger: off.}
|
||||
|
||||
include "system/inclrtl"
|
||||
|
||||
148
lib/pure/parseopt2.nim
Normal file
148
lib/pure/parseopt2.nim
Normal file
@@ -0,0 +1,148 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## This module provides the standard Nimrod command line parser.
|
||||
## It supports one convenience iterator over all command line options and some
|
||||
## lower-level features.
|
||||
##
|
||||
## Supported syntax:
|
||||
##
|
||||
## 1. short options - ``-abcd``, where a, b, c, d are names
|
||||
## 2. long option - ``--foo:bar``, ``--foo=bar`` or ``--foo``
|
||||
## 3. argument - everything else
|
||||
|
||||
{.push debugger: off.}
|
||||
|
||||
include "system/inclrtl"
|
||||
|
||||
import
|
||||
os, strutils
|
||||
|
||||
type
|
||||
TCmdLineKind* = enum ## the detected command line token
|
||||
cmdEnd, ## end of command line reached
|
||||
cmdArgument, ## argument detected
|
||||
cmdLongOption, ## a long option ``--option`` detected
|
||||
cmdShortOption ## a short option ``-c`` detected
|
||||
TOptParser* =
|
||||
object of TObject ## this object implements the command line parser
|
||||
cmd: seq[string]
|
||||
pos: int
|
||||
remainingShortOptions: string
|
||||
kind*: TCmdLineKind ## the dected command line token
|
||||
key*, val*: TaintedString ## key and value pair; ``key`` is the option
|
||||
## or the argument, ``value`` is not "" if
|
||||
## the option was given a value
|
||||
|
||||
proc initOptParser*(cmdline: seq[string]): TOptParser {.rtl.} =
|
||||
## Initalizes option parses with cmdline. cmdline should not contain
|
||||
## argument 0 - program name.
|
||||
## If cmdline == nil default to current command line arguments.
|
||||
result.remainingShortOptions = ""
|
||||
when not defined(createNimRtl):
|
||||
if cmdline == nil:
|
||||
result.cmd = commandLineParams()
|
||||
return
|
||||
else:
|
||||
assert cmdline != nil, "Cannot determine command line arguments."
|
||||
|
||||
result.cmd = @cmdline
|
||||
|
||||
proc initOptParser*(cmdline: string): TOptParser {.rtl, deprecated.} =
|
||||
## Initalizes option parses with cmdline. Splits cmdline in on spaces
|
||||
## and calls initOptParser(openarray[string])
|
||||
## Do not use.
|
||||
if cmdline == "": # backward compatibilty
|
||||
return initOptParser(seq[string](nil))
|
||||
else:
|
||||
return initOptParser(cmdline.split)
|
||||
|
||||
when not defined(createNimRtl):
|
||||
proc initOptParser*(): TOptParser =
|
||||
## Initializes option parser from current command line arguments.
|
||||
return initOptParser(commandLineParams())
|
||||
|
||||
proc next*(p: var TOptParser) {.rtl, extern: "npo$1".}
|
||||
|
||||
proc nextOption(p: var TOptParser, token: string, allowEmpty: bool) =
|
||||
for splitchar in [':', '=']:
|
||||
if splitchar in token:
|
||||
let pos = token.find(splitchar)
|
||||
p.key = token[0..pos-1]
|
||||
p.val = token[pos+1..token.len-1]
|
||||
return
|
||||
|
||||
p.key = token
|
||||
if allowEmpty:
|
||||
p.val = ""
|
||||
else:
|
||||
p.remainingShortOptions = token[0..token.len-1]
|
||||
p.next()
|
||||
|
||||
proc next(p: var TOptParser) =
|
||||
if p.remainingShortOptions.len != 0:
|
||||
p.kind = cmdShortOption
|
||||
p.key = TaintedString(p.remainingShortOptions[0..0])
|
||||
p.val = ""
|
||||
p.remainingShortOptions = p.remainingShortOptions[1..p.remainingShortOptions.len-1]
|
||||
return
|
||||
|
||||
if p.pos >= p.cmd.len:
|
||||
p.kind = cmdEnd
|
||||
return
|
||||
|
||||
let token = p.cmd[p.pos]
|
||||
p.pos += 1
|
||||
|
||||
if token.startswith("--"):
|
||||
p.kind = cmdLongOption
|
||||
nextOption(p, token[2..token.len-1], allowEmpty=true)
|
||||
elif token.startswith("-"):
|
||||
p.kind = cmdShortOption
|
||||
nextOption(p, token[1..token.len-1], allowEmpty=true)
|
||||
else:
|
||||
p.kind = cmdArgument
|
||||
p.key = token
|
||||
p.val = ""
|
||||
|
||||
proc cmdLineRest*(p: TOptParser): TaintedString {.rtl, extern: "npo$1", deprecated.} =
|
||||
## Returns part of command line string that has not been parsed yet.
|
||||
## Do not use - does not correctly handle whitespace.
|
||||
return p.cmd[p.pos..p.cmd.len-1].join(" ")
|
||||
|
||||
type
|
||||
TGetoptResult* = tuple[kind: TCmdLineKind, key, val: TaintedString]
|
||||
|
||||
when defined(paramCount):
|
||||
iterator getopt*(): TGetoptResult =
|
||||
## This is an convenience iterator for iterating over the command line.
|
||||
## This uses the TOptParser object. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## var
|
||||
## filename = ""
|
||||
## for kind, key, val in getopt():
|
||||
## case kind
|
||||
## of cmdArgument:
|
||||
## filename = key
|
||||
## of cmdLongOption, cmdShortOption:
|
||||
## case key
|
||||
## of "help", "h": writeHelp()
|
||||
## of "version", "v": writeVersion()
|
||||
## of cmdEnd: assert(false) # cannot happen
|
||||
## if filename == "":
|
||||
## # no filename has been given, so we show the help:
|
||||
## writeHelp()
|
||||
var p = initOptParser()
|
||||
while true:
|
||||
next(p)
|
||||
if p.kind == cmdEnd: break
|
||||
yield (p.kind, p.key, p.val)
|
||||
|
||||
{.pop.}
|
||||
@@ -98,8 +98,12 @@ template fail* =
|
||||
|
||||
when not defined(ECMAScript):
|
||||
if AbortOnError: quit(1)
|
||||
|
||||
TestStatusIMPL = FAILED
|
||||
|
||||
when defined(TestStatusIMPL):
|
||||
TestStatusIMPL = FAILED
|
||||
else:
|
||||
program_result += 1
|
||||
|
||||
checkpoints = @[]
|
||||
|
||||
macro check*(conditions: stmt): stmt {.immediate.} =
|
||||
@@ -111,7 +115,8 @@ macro check*(conditions: stmt): stmt {.immediate.} =
|
||||
counter = 0
|
||||
|
||||
template asgn(a, value: expr): stmt =
|
||||
let a = value
|
||||
var a = value # XXX: we need "var: var" here in order to
|
||||
# preserve the semantics of var params
|
||||
|
||||
template print(name, value: expr): stmt =
|
||||
when compiles(string($value)):
|
||||
@@ -146,7 +151,8 @@ macro check*(conditions: stmt): stmt {.immediate.} =
|
||||
of nnkStmtList:
|
||||
result = newNimNode(nnkStmtList)
|
||||
for i in countup(0, checked.len - 1):
|
||||
result.add(newCall(!"check", checked[i]))
|
||||
if checked[i].kind != nnkCommentStmt:
|
||||
result.add(newCall(!"check", checked[i]))
|
||||
|
||||
else:
|
||||
template rewrite(Exp, lineInfoLit: expr, expLit: string): stmt =
|
||||
|
||||
2655
lib/windows/mmsystem.nim
Normal file
2655
lib/windows/mmsystem.nim
Normal file
File diff suppressed because it is too large
Load Diff
232
lib/windows/nb30.nim
Normal file
232
lib/windows/nb30.nim
Normal file
@@ -0,0 +1,232 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2006 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
# NetBIOS 3.0 interface unit
|
||||
|
||||
# This module contains the definitions for portable NetBIOS 3.0 support.
|
||||
|
||||
{.deadCodeElim: on.}
|
||||
|
||||
import # Data structure templates
|
||||
Windows
|
||||
|
||||
const
|
||||
NCBNAMSZ* = 16 # absolute length of a net name
|
||||
MAX_LANA* = 254 # lana's in range 0 to MAX_LANA inclusive
|
||||
|
||||
type # Network Control Block
|
||||
PNCB* = ptr TNCB
|
||||
TNCBPostProc* = proc (P: PNCB) {.stdcall.}
|
||||
TNCB* {.final.} = object # Structure returned to the NCB command NCBASTAT is ADAPTER_STATUS followed
|
||||
# by an array of NAME_BUFFER structures.
|
||||
ncb_command*: Char # command code
|
||||
ncb_retcode*: Char # return code
|
||||
ncb_lsn*: Char # local session number
|
||||
ncb_num*: Char # number of our network name
|
||||
ncb_buffer*: cstring # address of message buffer
|
||||
ncb_length*: int16 # size of message buffer
|
||||
ncb_callname*: array[0..NCBNAMSZ - 1, char] # blank-padded name of remote
|
||||
ncb_name*: array[0..NCBNAMSZ - 1, char] # our blank-padded netname
|
||||
ncb_rto*: Char # rcv timeout/retry count
|
||||
ncb_sto*: Char # send timeout/sys timeout
|
||||
ncb_post*: TNCBPostProc # POST routine address
|
||||
ncb_lana_num*: Char # lana (adapter) number
|
||||
ncb_cmd_cplt*: Char # 0xff => commmand pending
|
||||
ncb_reserve*: array[0..9, Char] # reserved, used by BIOS
|
||||
ncb_event*: THandle # HANDLE to Win32 event which
|
||||
# will be set to the signalled
|
||||
# state when an ASYNCH command
|
||||
# completes
|
||||
|
||||
PAdapterStatus* = ptr TAdapterStatus
|
||||
TAdapterStatus* {.final.} = object
|
||||
adapter_address*: array[0..5, Char]
|
||||
rev_major*: Char
|
||||
reserved0*: Char
|
||||
adapter_type*: Char
|
||||
rev_minor*: Char
|
||||
duration*: int16
|
||||
frmr_recv*: int16
|
||||
frmr_xmit*: int16
|
||||
iframe_recv_err*: int16
|
||||
xmit_aborts*: int16
|
||||
xmit_success*: DWORD
|
||||
recv_success*: DWORD
|
||||
iframe_xmit_err*: int16
|
||||
recv_buff_unavail*: int16
|
||||
t1_timeouts*: int16
|
||||
ti_timeouts*: int16
|
||||
reserved1*: DWORD
|
||||
free_ncbs*: int16
|
||||
max_cfg_ncbs*: int16
|
||||
max_ncbs*: int16
|
||||
xmit_buf_unavail*: int16
|
||||
max_dgram_size*: int16
|
||||
pending_sess*: int16
|
||||
max_cfg_sess*: int16
|
||||
max_sess*: int16
|
||||
max_sess_pkt_size*: int16
|
||||
name_count*: int16
|
||||
|
||||
PNameBuffer* = ptr TNameBuffer
|
||||
TNameBuffer* {.final.} = object
|
||||
name*: array[0..NCBNAMSZ - 1, Char]
|
||||
name_num*: Char
|
||||
name_flags*: Char
|
||||
|
||||
|
||||
const # values for name_flags bits.
|
||||
NAME_FLAGS_MASK* = 0x00000087
|
||||
GROUP_NAME* = 0x00000080
|
||||
UNIQUE_NAME* = 0x00000000
|
||||
REGISTERING* = 0x00000000
|
||||
REGISTERED* = 0x00000004
|
||||
DEREGISTERED* = 0x00000005
|
||||
DUPLICATE* = 0x00000006
|
||||
DUPLICATE_DEREG* = 0x00000007
|
||||
|
||||
type # Structure returned to the NCB command NCBSSTAT is SESSION_HEADER followed
|
||||
# by an array of SESSION_BUFFER structures. If the NCB_NAME starts with an
|
||||
# asterisk then an array of these structures is returned containing the
|
||||
# status for all names.
|
||||
PSessionHeader* = ptr TSessionHeader
|
||||
TSessionHeader* {.final.} = object
|
||||
sess_name*: Char
|
||||
num_sess*: Char
|
||||
rcv_dg_outstanding*: Char
|
||||
rcv_any_outstanding*: Char
|
||||
|
||||
PSessionBuffer* = ptr TSessionBuffer
|
||||
TSessionBuffer* {.final.} = object
|
||||
lsn*: Char
|
||||
state*: Char
|
||||
local_name*: array[0..NCBNAMSZ - 1, Char]
|
||||
remote_name*: array[0..NCBNAMSZ - 1, Char]
|
||||
rcvs_outstanding*: Char
|
||||
sends_outstanding*: Char
|
||||
|
||||
|
||||
const # Values for state
|
||||
LISTEN_OUTSTANDING* = 0x00000001
|
||||
CALL_PENDING* = 0x00000002
|
||||
SESSION_ESTABLISHED* = 0x00000003
|
||||
HANGUP_PENDING* = 0x00000004
|
||||
HANGUP_COMPLETE* = 0x00000005
|
||||
SESSION_ABORTED* = 0x00000006
|
||||
|
||||
type # Structure returned to the NCB command NCBENUM.
|
||||
# On a system containing lana's 0, 2 and 3, a structure with
|
||||
# length =3, lana[0]=0, lana[1]=2 and lana[2]=3 will be returned.
|
||||
PLanaEnum* = ptr TLanaEnum
|
||||
TLanaEnum* {.final.} = object # Structure returned to the NCB command NCBFINDNAME is FIND_NAME_HEADER followed
|
||||
# by an array of FIND_NAME_BUFFER structures.
|
||||
len*: Char # Number of valid entries in lana[]
|
||||
lana*: array[0..MAX_LANA, Char]
|
||||
|
||||
PFindNameHeader* = ptr TFindNameHeader
|
||||
TFindNameHeader* {.final.} = object
|
||||
node_count*: int16
|
||||
reserved*: Char
|
||||
unique_group*: Char
|
||||
|
||||
PFindNameBuffer* = ptr TFindNameBuffer
|
||||
TFindNameBuffer* {.final.} = object # Structure provided with NCBACTION. The purpose of NCBACTION is to provide
|
||||
# transport specific extensions to netbios.
|
||||
len*: Char
|
||||
access_control*: Char
|
||||
frame_control*: Char
|
||||
destination_addr*: array[0..5, Char]
|
||||
source_addr*: array[0..5, Char]
|
||||
routing_info*: array[0..17, Char]
|
||||
|
||||
PActionHeader* = ptr TActionHeader
|
||||
TActionHeader* {.final.} = object
|
||||
transport_id*: int32
|
||||
action_code*: int16
|
||||
reserved*: int16
|
||||
|
||||
|
||||
const # Values for transport_id
|
||||
ALL_TRANSPORTS* = "M\0\0\0"
|
||||
MS_NBF* = "MNBF" # Special values and constants
|
||||
|
||||
const # NCB Command codes
|
||||
NCBCALL* = 0x00000010 # NCB CALL
|
||||
NCBLISTEN* = 0x00000011 # NCB LISTEN
|
||||
NCBHANGUP* = 0x00000012 # NCB HANG UP
|
||||
NCBSEND* = 0x00000014 # NCB SEND
|
||||
NCBRECV* = 0x00000015 # NCB RECEIVE
|
||||
NCBRECVANY* = 0x00000016 # NCB RECEIVE ANY
|
||||
NCBCHAINSEND* = 0x00000017 # NCB CHAIN SEND
|
||||
NCBDGSEND* = 0x00000020 # NCB SEND DATAGRAM
|
||||
NCBDGRECV* = 0x00000021 # NCB RECEIVE DATAGRAM
|
||||
NCBDGSENDBC* = 0x00000022 # NCB SEND BROADCAST DATAGRAM
|
||||
NCBDGRECVBC* = 0x00000023 # NCB RECEIVE BROADCAST DATAGRAM
|
||||
NCBADDNAME* = 0x00000030 # NCB ADD NAME
|
||||
NCBDELNAME* = 0x00000031 # NCB DELETE NAME
|
||||
NCBRESET* = 0x00000032 # NCB RESET
|
||||
NCBASTAT* = 0x00000033 # NCB ADAPTER STATUS
|
||||
NCBSSTAT* = 0x00000034 # NCB SESSION STATUS
|
||||
NCBCANCEL* = 0x00000035 # NCB CANCEL
|
||||
NCBADDGRNAME* = 0x00000036 # NCB ADD GROUP NAME
|
||||
NCBENUM* = 0x00000037 # NCB ENUMERATE LANA NUMBERS
|
||||
NCBUNLINK* = 0x00000070 # NCB UNLINK
|
||||
NCBSENDNA* = 0x00000071 # NCB SEND NO ACK
|
||||
NCBCHAINSENDNA* = 0x00000072 # NCB CHAIN SEND NO ACK
|
||||
NCBLANSTALERT* = 0x00000073 # NCB LAN STATUS ALERT
|
||||
NCBACTION* = 0x00000077 # NCB ACTION
|
||||
NCBFINDNAME* = 0x00000078 # NCB FIND NAME
|
||||
NCBTRACE* = 0x00000079 # NCB TRACE
|
||||
ASYNCH* = 0x00000080 # high bit set = asynchronous
|
||||
# NCB Return codes
|
||||
NRC_GOODRET* = 0x00000000 # good return
|
||||
# also returned when ASYNCH request accepted
|
||||
NRC_BUFLEN* = 0x00000001 # illegal buffer length
|
||||
NRC_ILLCMD* = 0x00000003 # illegal command
|
||||
NRC_CMDTMO* = 0x00000005 # command timed out
|
||||
NRC_INCOMP* = 0x00000006 # message incomplete, issue another command
|
||||
NRC_BADDR* = 0x00000007 # illegal buffer address
|
||||
NRC_SNUMOUT* = 0x00000008 # session number out of range
|
||||
NRC_NORES* = 0x00000009 # no resource available
|
||||
NRC_SCLOSED* = 0x0000000A # session closed
|
||||
NRC_CMDCAN* = 0x0000000B # command cancelled
|
||||
NRC_DUPNAME* = 0x0000000D # duplicate name
|
||||
NRC_NAMTFUL* = 0x0000000E # name table full
|
||||
NRC_ACTSES* = 0x0000000F # no deletions, name has active sessions
|
||||
NRC_LOCTFUL* = 0x00000011 # local session table full
|
||||
NRC_REMTFUL* = 0x00000012 # remote session table full
|
||||
NRC_ILLNN* = 0x00000013 # illegal name number
|
||||
NRC_NOCALL* = 0x00000014 # no callname
|
||||
NRC_NOWILD* = 0x00000015 # cannot put * in NCB_NAME
|
||||
NRC_INUSE* = 0x00000016 # name in use on remote adapter
|
||||
NRC_NAMERR* = 0x00000017 # name deleted
|
||||
NRC_SABORT* = 0x00000018 # session ended abnormally
|
||||
NRC_NAMCONF* = 0x00000019 # name conflict detected
|
||||
NRC_IFBUSY* = 0x00000021 # interface busy, IRET before retrying
|
||||
NRC_TOOMANY* = 0x00000022 # too many commands outstanding, retry later
|
||||
NRC_BRIDGE* = 0x00000023 # NCB_lana_num field invalid
|
||||
NRC_CANOCCR* = 0x00000024 # command completed while cancel occurring
|
||||
NRC_CANCEL* = 0x00000026 # command not valid to cancel
|
||||
NRC_DUPENV* = 0x00000030 # name defined by anther local process
|
||||
NRC_ENVNOTDEF* = 0x00000034 # environment undefined. RESET required
|
||||
NRC_OSRESNOTAV* = 0x00000035 # required OS resources exhausted
|
||||
NRC_MAXAPPS* = 0x00000036 # max number of applications exceeded
|
||||
NRC_NOSAPS* = 0x00000037 # no saps available for netbios
|
||||
NRC_NORESOURCES* = 0x00000038 # requested resources are not available
|
||||
NRC_INVADDRESS* = 0x00000039 # invalid ncb address or length > segment
|
||||
NRC_INVDDID* = 0x0000003B # invalid NCB DDID
|
||||
NRC_LOCKFAIL* = 0x0000003C # lock of user area failed
|
||||
NRC_OPENERR* = 0x0000003F # NETBIOS not loaded
|
||||
NRC_SYSTEM* = 0x00000040 # system error
|
||||
NRC_PENDING* = 0x000000FF # asynchronous command is not yet finished
|
||||
# main user entry point for NetBIOS 3.0
|
||||
# Usage: Result = Netbios( pncb );
|
||||
|
||||
proc Netbios*(P: PNCB): Char{.stdcall, dynlib: "netapi32.dll",
|
||||
importc: "Netbios".}
|
||||
# implementation
|
||||
208
lib/windows/ole2.nim
Normal file
208
lib/windows/ole2.nim
Normal file
@@ -0,0 +1,208 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2006 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
import
|
||||
windows
|
||||
|
||||
const
|
||||
GUID_NULL*: TGUID = (D1: 0x00000000, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000])
|
||||
IID_IUnknown*: TGUID = (D1: 0x00000000, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IClassFactory*: TGUID = (D1: 0x00000001, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IMarshal*: TGUID = (D1: 0x00000003, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IMalloc*: TGUID = (D1: 0x00000002, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IStdMarshalInfo*: TGUID = (D1: 0x00000018, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IExternalConnection*: TGUID = (D1: 0x00000019, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IEnumUnknown*: TGUID = (D1: 0x00000100, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IBindCtx*: TGUID = (D1: 0x0000000E, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IEnumMoniker*: TGUID = (D1: 0x00000102, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IRunnableObject*: TGUID = (D1: 0x00000126, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IRunningObjectTable*: TGUID = (D1: 0x00000010, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IPersist*: TGUID = (D1: 0x0000010C, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IPersistStream*: TGUID = (D1: 0x00000109, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IMoniker*: TGUID = (D1: 0x0000000F, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IEnumString*: TGUID = (D1: 0x00000101, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IStream*: TGUID = (D1: 0x0000000C, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IEnumStatStg*: TGUID = (D1: 0x0000000D, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IStorage*: TGUID = (D1: 0x0000000B, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IPersistFile*: TGUID = (D1: 0x0000010B, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IPersistStorage*: TGUID = (D1: 0x0000010A, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_ILockBytes*: TGUID = (D1: 0x0000000A, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IEnumFormatEtc*: TGUID = (D1: 0x00000103, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IEnumStatData*: TGUID = (D1: 0x00000105, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IRootStorage*: TGUID = (D1: 0x00000012, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IAdviseSink*: TGUID = (D1: 0x0000010F, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IAdviseSink2*: TGUID = (D1: 0x00000125, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IDataObject*: TGUID = (D1: 0x0000010E, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IDataAdviseHolder*: TGUID = (D1: 0x00000110, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IMessageFilter*: TGUID = (D1: 0x00000016, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IRpcChannelBuffer*: TGUID = (D1: 0xD5F56B60, D2: 0x0000593B,
|
||||
D3: 0x0000101A, D4: [0x000000B5, 0x00000069, 0x00000008, 0x00000000,
|
||||
0x0000002B, 0x0000002D, 0x000000BF, 0x0000007A])
|
||||
IID_IRpcProxyBuffer*: TGUID = (D1: 0xD5F56A34, D2: 0x0000593B, D3: 0x0000101A, D4: [
|
||||
0x000000B5, 0x00000069, 0x00000008, 0x00000000, 0x0000002B, 0x0000002D,
|
||||
0x000000BF, 0x0000007A])
|
||||
IID_IRpcStubBuffer*: TGUID = (D1: 0xD5F56AFC, D2: 0x0000593B, D3: 0x0000101A, D4: [
|
||||
0x000000B5, 0x00000069, 0x00000008, 0x00000000, 0x0000002B, 0x0000002D,
|
||||
0x000000BF, 0x0000007A])
|
||||
IID_IPSFactoryBuffer*: TGUID = (D1: 0xD5F569D0, D2: 0x0000593B,
|
||||
D3: 0x0000101A, D4: [0x000000B5, 0x00000069, 0x00000008, 0x00000000,
|
||||
0x0000002B, 0x0000002D, 0x000000BF, 0x0000007A])
|
||||
IID_ICreateTypeInfo*: TGUID = (D1: 0x00020405, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_ICreateTypeLib*: TGUID = (D1: 0x00020406, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IDispatch*: TGUID = (D1: 0x00020400, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IEnumVariant*: TGUID = (D1: 0x00020404, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_ITypeComp*: TGUID = (D1: 0x00020403, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_ITypeInfo*: TGUID = (D1: 0x00020401, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_ITypeLib*: TGUID = (D1: 0x00020402, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IErrorInfo*: TGUID = (D1: 0x1CF2B120, D2: 0x0000547D, D3: 0x0000101B, D4: [
|
||||
0x0000008E, 0x00000065, 0x00000008, 0x00000000, 0x0000002B, 0x0000002B,
|
||||
0x000000D1, 0x00000019])
|
||||
IID_ICreateErrorInfo*: TGUID = (D1: 0x22F03340, D2: 0x0000547D,
|
||||
D3: 0x0000101B, D4: [0x0000008E, 0x00000065, 0x00000008, 0x00000000,
|
||||
0x0000002B, 0x0000002B, 0x000000D1, 0x00000019])
|
||||
IID_ISupportErrorInfo*: TGUID = (D1: 0xDF0B3D60, D2: 0x0000548F,
|
||||
D3: 0x0000101B, D4: [0x0000008E, 0x00000065, 0x00000008, 0x00000000,
|
||||
0x0000002B, 0x0000002B, 0x000000D1, 0x00000019])
|
||||
IID_IOleAdviseHolder*: TGUID = (D1: 0x00000111, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IOleCache*: TGUID = (D1: 0x0000011E, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IOleCache2*: TGUID = (D1: 0x00000128, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IOleCacheControl*: TGUID = (D1: 0x00000129, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IParseDisplayName*: TGUID = (D1: 0x0000011A, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IOleContainer*: TGUID = (D1: 0x0000011B, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IOleClientSite*: TGUID = (D1: 0x00000118, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IOleObject*: TGUID = (D1: 0x00000112, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IOleWindow*: TGUID = (D1: 0x00000114, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IOleLink*: TGUID = (D1: 0x0000011D, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IOleItemContainer*: TGUID = (D1: 0x0000011C, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IOleInPlaceUIWindow*: TGUID = (D1: 0x00000115, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IOleInPlaceActiveObject*: TGUID = (D1: 0x00000117, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IOleInPlaceFrame*: TGUID = (D1: 0x00000116, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IOleInPlaceObject*: TGUID = (D1: 0x00000113, D2: 0x00000000,
|
||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
||||
IID_IOleInPlaceSite*: TGUID = (D1: 0x00000119, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IViewObject*: TGUID = (D1: 0x0000010D, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IViewObject2*: TGUID = (D1: 0x00000127, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IDropSource*: TGUID = (D1: 0x00000121, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IDropTarget*: TGUID = (D1: 0x00000122, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
IID_IEnumOleVerb*: TGUID = (D1: 0x00000104, D2: 0x00000000, D3: 0x00000000, D4: [
|
||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000046])
|
||||
202
lib/windows/psapi.nim
Normal file
202
lib/windows/psapi.nim
Normal file
@@ -0,0 +1,202 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
# PSAPI interface unit
|
||||
|
||||
# Contains the definitions for the APIs provided by PSAPI.DLL
|
||||
|
||||
import # Data structure templates
|
||||
Windows
|
||||
|
||||
const
|
||||
psapiDll = "psapi.dll"
|
||||
|
||||
proc EnumProcesses*(lpidProcess: ptr DWORD, cb: DWORD,
|
||||
cbNeeded: ptr DWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EnumProcesses".}
|
||||
proc EnumProcessModules*(hProcess: HANDLE, lphModule: ptr HMODULE, cb: DWORD, lpcbNeeded: LPDWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EnumProcessModules".}
|
||||
|
||||
proc GetModuleBaseNameA*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleBaseNameA".}
|
||||
proc GetModuleBaseNameW*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleBaseNameW".}
|
||||
when defined(winUnicode):
|
||||
proc GetModuleBaseName*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleBaseNameW".}
|
||||
else:
|
||||
proc GetModuleBaseName*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleBaseNameA".}
|
||||
|
||||
proc GetModuleFileNameExA*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleFileNameExA".}
|
||||
proc GetModuleFileNameExW*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleFileNameExW".}
|
||||
when defined(winUnicode):
|
||||
proc GetModuleFileNameEx*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleFileNameExW".}
|
||||
else:
|
||||
proc GetModuleFileNameEx*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleFileNameExA".}
|
||||
|
||||
type
|
||||
MODULEINFO* {.final.} = object
|
||||
lpBaseOfDll*: LPVOID
|
||||
SizeOfImage*: DWORD
|
||||
EntryPoint*: LPVOID
|
||||
LPMODULEINFO* = ptr MODULEINFO
|
||||
|
||||
proc GetModuleInformation*(hProcess: HANDLE, hModule: HMODULE, lpmodinfo: LPMODULEINFO, cb: DWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetModuleInformation".}
|
||||
proc EmptyWorkingSet*(hProcess: HANDLE): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EmptyWorkingSet".}
|
||||
proc QueryWorkingSet*(hProcess: HANDLE, pv: PVOID, cb: DWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "QueryWorkingSet".}
|
||||
proc QueryWorkingSetEx*(hProcess: HANDLE, pv: PVOID, cb: DWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "QueryWorkingSetEx".}
|
||||
proc InitializeProcessForWsWatch*(hProcess: HANDLE): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "InitializeProcessForWsWatch".}
|
||||
|
||||
type
|
||||
PSAPI_WS_WATCH_INFORMATION* {.final.} = object
|
||||
FaultingPc*: LPVOID
|
||||
FaultingVa*: LPVOID
|
||||
PPSAPI_WS_WATCH_INFORMATION* = ptr PSAPI_WS_WATCH_INFORMATION
|
||||
|
||||
proc GetWsChanges*(hProcess: HANDLE, lpWatchInfo: PPSAPI_WS_WATCH_INFORMATION, cb: DWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetWsChanges".}
|
||||
|
||||
proc GetMappedFileNameA*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetMappedFileNameA".}
|
||||
proc GetMappedFileNameW*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetMappedFileNameW".}
|
||||
when defined(winUnicode):
|
||||
proc GetMappedFileName*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetMappedFileNameW".}
|
||||
else:
|
||||
proc GetMappedFileName*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetMappedFileNameA".}
|
||||
|
||||
proc EnumDeviceDrivers*(lpImageBase: LPVOID, cb: DWORD, lpcbNeeded: LPDWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EnumDeviceDrivers".}
|
||||
|
||||
proc GetDeviceDriverBaseNameA*(ImageBase: LPVOID, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameA".}
|
||||
proc GetDeviceDriverBaseNameW*(ImageBase: LPVOID, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameW".}
|
||||
when defined(winUnicode):
|
||||
proc GetDeviceDriverBaseName*(ImageBase: LPVOID, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameW".}
|
||||
else:
|
||||
proc GetDeviceDriverBaseName*(ImageBase: LPVOID, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameA".}
|
||||
|
||||
proc GetDeviceDriverFileNameA*(ImageBase: LPVOID, lpFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameA".}
|
||||
proc GetDeviceDriverFileNameW*(ImageBase: LPVOID, lpFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameW".}
|
||||
when defined(winUnicode):
|
||||
proc GetDeviceDriverFileName*(ImageBase: LPVOID, lpFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameW".}
|
||||
else:
|
||||
proc GetDeviceDriverFileName*(ImageBase: LPVOID, lpFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameA".}
|
||||
|
||||
type
|
||||
PROCESS_MEMORY_COUNTERS* {.final.} = object
|
||||
cb*: DWORD
|
||||
PageFaultCount*: DWORD
|
||||
PeakWorkingSetSize: SIZE_T
|
||||
WorkingSetSize: SIZE_T
|
||||
QuotaPeakPagedPoolUsage: SIZE_T
|
||||
QuotaPagedPoolUsage: SIZE_T
|
||||
QuotaPeakNonPagedPoolUsage: SIZE_T
|
||||
QuotaNonPagedPoolUsage: SIZE_T
|
||||
PagefileUsage: SIZE_T
|
||||
PeakPagefileUsage: SIZE_T
|
||||
PPROCESS_MEMORY_COUNTERS* = ptr PROCESS_MEMORY_COUNTERS
|
||||
|
||||
type
|
||||
PROCESS_MEMORY_COUNTERS_EX* {.final.} = object
|
||||
cb*: DWORD
|
||||
PageFaultCount*: DWORD
|
||||
PeakWorkingSetSize: SIZE_T
|
||||
WorkingSetSize: SIZE_T
|
||||
QuotaPeakPagedPoolUsage: SIZE_T
|
||||
QuotaPagedPoolUsage: SIZE_T
|
||||
QuotaPeakNonPagedPoolUsage: SIZE_T
|
||||
QuotaNonPagedPoolUsage: SIZE_T
|
||||
PagefileUsage: SIZE_T
|
||||
PeakPagefileUsage: SIZE_T
|
||||
PrivateUsage: SIZE_T
|
||||
PPROCESS_MEMORY_COUNTERS_EX* = ptr PROCESS_MEMORY_COUNTERS_EX
|
||||
|
||||
proc GetProcessMemoryInfo*(hProcess: HANDLE, ppsmemCounters: PPROCESS_MEMORY_COUNTERS, cb: DWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetProcessMemoryInfo".}
|
||||
|
||||
type
|
||||
PERFORMANCE_INFORMATION* {.final.} = object
|
||||
cb*: DWORD
|
||||
CommitTotal: SIZE_T
|
||||
CommitLimit: SIZE_T
|
||||
CommitPeak: SIZE_T
|
||||
PhysicalTotal: SIZE_T
|
||||
PhysicalAvailable: SIZE_T
|
||||
SystemCache: SIZE_T
|
||||
KernelTotal: SIZE_T
|
||||
KernelPaged: SIZE_T
|
||||
KernelNonpaged: SIZE_T
|
||||
PageSize: SIZE_T
|
||||
HandleCount*: DWORD
|
||||
ProcessCount*: DWORD
|
||||
ThreadCount*: DWORD
|
||||
PPERFORMANCE_INFORMATION* = ptr PERFORMANCE_INFORMATION
|
||||
# Skip definition of PERFORMACE_INFORMATION...
|
||||
|
||||
proc GetPerformanceInfo*(pPerformanceInformation: PPERFORMANCE_INFORMATION, cb: DWORD): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetPerformanceInfo".}
|
||||
|
||||
type
|
||||
ENUM_PAGE_FILE_INFORMATION* {.final.} = object
|
||||
cb*: DWORD
|
||||
Reserved*: DWORD
|
||||
TotalSize: SIZE_T
|
||||
TotalInUse: SIZE_T
|
||||
PeakUsage: SIZE_T
|
||||
PENUM_PAGE_FILE_INFORMATION* = ptr ENUM_PAGE_FILE_INFORMATION
|
||||
|
||||
# Callback procedure
|
||||
type
|
||||
PENUM_PAGE_FILE_CALLBACKW* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCWSTR): WINBOOL{.stdcall.}
|
||||
PENUM_PAGE_FILE_CALLBACKA* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCSTR): WINBOOL{.stdcall.}
|
||||
|
||||
#TODO
|
||||
proc EnumPageFilesA*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKA, pContext: LPVOID): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EnumPageFilesA".}
|
||||
proc EnumPageFilesW*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKW, pContext: LPVOID): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EnumPageFilesW".}
|
||||
when defined(winUnicode):
|
||||
proc EnumPageFiles*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKW, pContext: LPVOID): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EnumPageFilesW".}
|
||||
type PENUM_PAGE_FILE_CALLBACK* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCWSTR): WINBOOL{.stdcall.}
|
||||
else:
|
||||
proc EnumPageFiles*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKA, pContext: LPVOID): WINBOOL {.stdcall,
|
||||
dynlib: psapiDll, importc: "EnumPageFilesA".}
|
||||
type PENUM_PAGE_FILE_CALLBACK* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCSTR): WINBOOL{.stdcall.}
|
||||
|
||||
proc GetProcessImageFileNameA*(hProcess: HANDLE, lpImageFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetProcessImageFileNameA".}
|
||||
proc GetProcessImageFileNameW*(hProcess: HANDLE, lpImageFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetProcessImageFileNameW".}
|
||||
when defined(winUnicode):
|
||||
proc GetProcessImageFileName*(hProcess: HANDLE, lpImageFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetProcessImageFileNameW".}
|
||||
else:
|
||||
proc GetProcessImageFileName*(hProcess: HANDLE, lpImageFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
||||
dynlib: psapiDll, importc: "GetProcessImageFileNameA".}
|
||||
863
lib/windows/shellapi.nim
Normal file
863
lib/windows/shellapi.nim
Normal file
@@ -0,0 +1,863 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2006 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
{.deadCodeElim: on.}
|
||||
|
||||
# leave out unused functions so the unit can be used on win2000 as well
|
||||
|
||||
#+-------------------------------------------------------------------------
|
||||
#
|
||||
# Microsoft Windows
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
# File: shellapi.h
|
||||
#
|
||||
# Header translation by Marco van de Voort for Free Pascal Platform
|
||||
# SDK dl'ed January 2002
|
||||
#
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# shellapi.h - SHELL.DLL functions, types, and definitions
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
import
|
||||
Windows
|
||||
|
||||
type
|
||||
HDROP* = THandle
|
||||
UINT_PTR* = ptr UINT
|
||||
DWORD_PTR* = ptr DWORD
|
||||
pHICON* = ptr HICON
|
||||
pBool* = ptr BOOL
|
||||
STARTUPINFOW* {.final.} = object # a guess. Omission should get fixed in Windows.
|
||||
cb*: DWORD
|
||||
lpReserved*: LPTSTR
|
||||
lpDesktop*: LPTSTR
|
||||
lpTitle*: LPTSTR
|
||||
dwX*: DWORD
|
||||
dwY*: DWORD
|
||||
dwXSize*: DWORD
|
||||
dwYSize*: DWORD
|
||||
dwXCountChars*: DWORD
|
||||
dwYCountChars*: DWORD
|
||||
dwFillAttribute*: DWORD
|
||||
dwFlags*: DWORD
|
||||
wShowWindow*: int16
|
||||
cbReserved2*: int16
|
||||
lpReserved2*: LPBYTE
|
||||
hStdInput*: HANDLE
|
||||
hStdOutput*: HANDLE
|
||||
hStdError*: HANDLE
|
||||
|
||||
LPSTARTUPINFOW* = ptr STARTUPINFOW
|
||||
TSTARTUPINFOW* = STARTUPINFOW
|
||||
PSTARTUPINFOW* = ptr STARTUPINFOW #unicode
|
||||
|
||||
proc DragQueryFileA*(arg1: HDROP, arg2: UINT, arg3: LPSTR, arg4: UINT): UINT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileA".}
|
||||
proc DragQueryFileW*(arg1: HDROP, arg2: UINT, arg3: LPWSTR, arg4: UINT): UINT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileW".}
|
||||
proc DragQueryFile*(arg1: HDROP, arg2: UINT, arg3: LPSTR, arg4: UINT): UINT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileA".}
|
||||
proc DragQueryFile*(arg1: HDROP, arg2: UINT, arg3: LPWSTR, arg4: UINT): UINT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileW".}
|
||||
proc DragQueryPoint*(arg1: HDROP, arg2: LPPOINT): BOOL{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "DragQueryPoint".}
|
||||
proc DragFinish*(arg1: HDROP){.stdcall, dynlib: "shell32.dll",
|
||||
importc: "DragFinish".}
|
||||
proc DragAcceptFiles*(hwnd: HWND, arg2: BOOL){.stdcall, dynlib: "shell32.dll",
|
||||
importc: "DragAcceptFiles".}
|
||||
proc ShellExecuteA*(HWND: hwnd, lpOperation: LPCSTR, lpFile: LPCSTR,
|
||||
lpParameters: LPCSTR, lpDirectory: LPCSTR, nShowCmd: int32): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteA".}
|
||||
proc ShellExecuteW*(hwnd: HWND, lpOperation: LPCWSTR, lpFile: LPCWSTR,
|
||||
lpParameters: LPCWSTR, lpDirectory: LPCWSTR, nShowCmd: int32): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteW".}
|
||||
proc ShellExecute*(HWND: hwnd, lpOperation: LPCSTR, lpFile: LPCSTR,
|
||||
lpParameters: LPCSTR, lpDirectory: LPCSTR, nShowCmd: int32): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteA".}
|
||||
proc ShellExecute*(hwnd: HWND, lpOperation: LPCWSTR, lpFile: LPCWSTR,
|
||||
lpParameters: LPCWSTR, lpDirectory: LPCWSTR, nShowCmd: int32): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteW".}
|
||||
proc FindExecutableA*(lpFile: LPCSTR, lpDirectory: LPCSTR, lpResult: LPSTR): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableA".}
|
||||
proc FindExecutableW*(lpFile: LPCWSTR, lpDirectory: LPCWSTR, lpResult: LPWSTR): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableW".}
|
||||
proc FindExecutable*(lpFile: LPCSTR, lpDirectory: LPCSTR, lpResult: LPSTR): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableA".}
|
||||
proc FindExecutable*(lpFile: LPCWSTR, lpDirectory: LPCWSTR, lpResult: LPWSTR): HInst{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableW".}
|
||||
proc CommandLineToArgvW*(lpCmdLine: LPCWSTR, pNumArgs: ptr int32): pLPWSTR{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "CommandLineToArgvW".}
|
||||
proc ShellAboutA*(HWND: hWnd, szApp: LPCSTR, szOtherStuff: LPCSTR, HICON: hIcon): int32{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ShellAboutA".}
|
||||
proc ShellAboutW*(HWND: hWnd, szApp: LPCWSTR, szOtherStuff: LPCWSTR,
|
||||
HICON: hIcon): int32{.stdcall, dynlib: "shell32.dll",
|
||||
importc: "ShellAboutW".}
|
||||
proc ShellAbout*(HWND: hWnd, szApp: LPCSTR, szOtherStuff: LPCSTR, HICON: hIcon): int32{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ShellAboutA".}
|
||||
proc ShellAbout*(HWND: hWnd, szApp: LPCWSTR, szOtherStuff: LPCWSTR, HICON: hIcon): int32{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ShellAboutW".}
|
||||
proc DuplicateIcon*(inst: HINST, icon: HICON): HIcon{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "DuplicateIcon".}
|
||||
proc ExtractAssociatedIconA*(hInst: HINST, lpIconPath: LPSTR, lpiIcon: LPWORD): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconA".}
|
||||
proc ExtractAssociatedIconW*(hInst: HINST, lpIconPath: LPWSTR, lpiIcon: LPWORD): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconW".}
|
||||
proc ExtractAssociatedIcon*(hInst: HINST, lpIconPath: LPSTR, lpiIcon: LPWORD): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconA".}
|
||||
proc ExtractAssociatedIcon*(hInst: HINST, lpIconPath: LPWSTR, lpiIcon: LPWORD): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconW".}
|
||||
proc ExtractIconA*(hInst: HINST, lpszExeFileName: LPCSTR, nIconIndex: UINT): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconA".}
|
||||
proc ExtractIconW*(hInst: HINST, lpszExeFileName: LPCWSTR, nIconIndex: UINT): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconW".}
|
||||
proc ExtractIcon*(hInst: HINST, lpszExeFileName: LPCSTR, nIconIndex: UINT): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconA".}
|
||||
proc ExtractIcon*(hInst: HINST, lpszExeFileName: LPCWSTR, nIconIndex: UINT): HICON{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconW".}
|
||||
# if(WINVER >= 0x0400)
|
||||
type # init with sizeof(DRAGINFO)
|
||||
DRAGINFOA* {.final.} = object
|
||||
uSize*: UINT
|
||||
pt*: POINT
|
||||
fNC*: BOOL
|
||||
lpFileList*: LPSTR
|
||||
grfKeyState*: DWORD
|
||||
|
||||
TDRAGINFOA* = DRAGINFOA
|
||||
LPDRAGINFOA* = ptr DRAGINFOA # init with sizeof(DRAGINFO)
|
||||
DRAGINFOW* {.final.} = object
|
||||
uSize*: UINT
|
||||
pt*: POINT
|
||||
fNC*: BOOL
|
||||
lpFileList*: LPWSTR
|
||||
grfKeyState*: DWORD
|
||||
|
||||
TDRAGINFOW* = DRAGINFOW
|
||||
LPDRAGINFOW* = ptr DRAGINFOW
|
||||
|
||||
when defined(UNICODE):
|
||||
type
|
||||
DRAGINFO* = DRAGINFOW
|
||||
TDRAGINFO* = DRAGINFOW
|
||||
LPDRAGINFO* = LPDRAGINFOW
|
||||
else:
|
||||
type
|
||||
DRAGINFO* = DRAGINFOA
|
||||
TDRAGINFO* = DRAGINFOW
|
||||
LPDRAGINFO* = LPDRAGINFOA
|
||||
const
|
||||
ABM_NEW* = 0x00000000
|
||||
ABM_REMOVE* = 0x00000001
|
||||
ABM_QUERYPOS* = 0x00000002
|
||||
ABM_SETPOS* = 0x00000003
|
||||
ABM_GETSTATE* = 0x00000004
|
||||
ABM_GETTASKBARPOS* = 0x00000005
|
||||
ABM_ACTIVATE* = 0x00000006 # lParam == TRUE/FALSE means activate/deactivate
|
||||
ABM_GETAUTOHIDEBAR* = 0x00000007
|
||||
ABM_SETAUTOHIDEBAR* = 0x00000008 # this can fail at any time. MUST check the result
|
||||
# lParam = TRUE/FALSE Set/Unset
|
||||
# uEdge = what edge
|
||||
ABM_WINDOWPOSCHANGED* = 0x00000009
|
||||
ABM_SETSTATE* = 0x0000000A
|
||||
ABN_STATECHANGE* = 0x00000000 # these are put in the wparam of callback messages
|
||||
ABN_POSCHANGED* = 0x00000001
|
||||
ABN_FULLSCREENAPP* = 0x00000002
|
||||
ABN_WINDOWARRANGE* = 0x00000003 # lParam == TRUE means hide
|
||||
# flags for get state
|
||||
ABS_AUTOHIDE* = 0x00000001
|
||||
ABS_ALWAYSONTOP* = 0x00000002
|
||||
ABE_LEFT* = 0
|
||||
ABE_TOP* = 1
|
||||
ABE_RIGHT* = 2
|
||||
ABE_BOTTOM* = 3
|
||||
|
||||
type
|
||||
AppBarData* {.final.} = object
|
||||
cbSize*: DWORD
|
||||
hWnd*: HWND
|
||||
uCallbackMessage*: UINT
|
||||
uEdge*: UINT
|
||||
rc*: RECT
|
||||
lParam*: LPARAM # message specific
|
||||
|
||||
TAPPBARDATA* = AppBarData
|
||||
PAPPBARDATA* = ptr AppBarData
|
||||
|
||||
proc SHAppBarMessage*(dwMessage: DWORD, pData: APPBARDATA): UINT_PTR{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHAppBarMessage".}
|
||||
#
|
||||
# EndAppBar
|
||||
#
|
||||
proc DoEnvironmentSubstA*(szString: LPSTR, cchString: UINT): DWORD{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstA".}
|
||||
proc DoEnvironmentSubstW*(szString: LPWSTR, cchString: UINT): DWORD{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstW".}
|
||||
proc DoEnvironmentSubst*(szString: LPSTR, cchString: UINT): DWORD{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstA".}
|
||||
proc DoEnvironmentSubst*(szString: LPWSTR, cchString: UINT): DWORD{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstW".}
|
||||
#Macro
|
||||
proc EIRESID*(x: int32): int32
|
||||
proc ExtractIconExA*(lpszFile: LPCSTR, nIconIndex: int32, phiconLarge: pHICON,
|
||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ExtractIconExA".}
|
||||
proc ExtractIconExW*(lpszFile: LPCWSTR, nIconIndex: int32, phiconLarge: pHICON,
|
||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ExtractIconExW".}
|
||||
proc ExtractIconExA*(lpszFile: LPCSTR, nIconIndex: int32,
|
||||
phiconLarge: var HICON, phiconSmall: var HIcon,
|
||||
nIcons: UINT): UINT{.stdcall, dynlib: "shell32.dll",
|
||||
importc: "ExtractIconExA".}
|
||||
proc ExtractIconExW*(lpszFile: LPCWSTR, nIconIndex: int32,
|
||||
phiconLarge: var HICON, phiconSmall: var HIcon,
|
||||
nIcons: UINT): UINT{.stdcall, dynlib: "shell32.dll",
|
||||
importc: "ExtractIconExW".}
|
||||
proc ExtractIconEx*(lpszFile: LPCSTR, nIconIndex: int32, phiconLarge: pHICON,
|
||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ExtractIconExA".}
|
||||
proc ExtractIconEx*(lpszFile: LPCWSTR, nIconIndex: int32, phiconLarge: pHICON,
|
||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ExtractIconExW".}
|
||||
proc ExtractIconEx*(lpszFile: LPCSTR, nIconIndex: int32, phiconLarge: var HICON,
|
||||
phiconSmall: var HIcon, nIcons: UINT): UINT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ExtractIconExA".}
|
||||
proc ExtractIconEx*(lpszFile: LPCWSTR, nIconIndex: int32,
|
||||
phiconLarge: var HICON, phiconSmall: var HIcon, nIcons: UINT): UINT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconExW".}
|
||||
#
|
||||
# Shell File Operations
|
||||
#
|
||||
#ifndef FO_MOVE //these need to be kept in sync with the ones in shlobj.h}
|
||||
const
|
||||
FO_MOVE* = 0x00000001
|
||||
FO_COPY* = 0x00000002
|
||||
FO_DELETE* = 0x00000003
|
||||
FO_RENAME* = 0x00000004
|
||||
FOF_MULTIDESTFILES* = 0x00000001
|
||||
FOF_CONFIRMMOUSE* = 0x00000002
|
||||
FOF_SILENT* = 0x00000004 # don't create progress/report
|
||||
FOF_RENAMEONCOLLISION* = 0x00000008
|
||||
FOF_NOCONFIRMATION* = 0x00000010 # Don't prompt the user.
|
||||
FOF_WANTMAPPINGHANDLE* = 0x00000020 # Fill in SHFILEOPSTRUCT.hNameMappings
|
||||
FOF_ALLOWUNDO* = 0x00000040 # Must be freed using SHFreeNameMappings
|
||||
FOF_FILESONLY* = 0x00000080 # on *.*, do only files
|
||||
FOF_SIMPLEPROGRESS* = 0x00000100 # means don't show names of files
|
||||
FOF_NOCONFIRMMKDIR* = 0x00000200 # don't confirm making any needed dirs
|
||||
FOF_NOERRORUI* = 0x00000400 # don't put up error UI
|
||||
FOF_NOCOPYSECURITYATTRIBS* = 0x00000800 # dont copy NT file Security Attributes
|
||||
FOF_NORECURSION* = 0x00001000 # don't recurse into directories.
|
||||
#if (_WIN32_IE >= 0x0500)
|
||||
FOF_NO_CONNECTED_ELEMENTS* = 0x00002000 # don't operate on connected elements.
|
||||
FOF_WANTNUKEWARNING* = 0x00004000 # during delete operation, warn if nuking instead of recycling (partially overrides FOF_NOCONFIRMATION)
|
||||
#endif
|
||||
#if (_WIN32_WINNT >= 0x0501)
|
||||
FOF_NORECURSEREPARSE* = 0x00008000 # treat reparse points as objects, not containers
|
||||
#endif
|
||||
|
||||
type
|
||||
FILEOP_FLAGS* = int16
|
||||
|
||||
const
|
||||
PO_DELETE* = 0x00000013 # printer is being deleted
|
||||
PO_RENAME* = 0x00000014 # printer is being renamed
|
||||
PO_PORTCHANGE* = 0x00000020 # port this printer connected to is being changed
|
||||
# if this id is set, the strings received by
|
||||
# the copyhook are a doubly-null terminated
|
||||
# list of strings. The first is the printer
|
||||
# name and the second is the printer port.
|
||||
PO_REN_PORT* = 0x00000034 # PO_RENAME and PO_PORTCHANGE at same time.
|
||||
# no POF_ flags currently defined
|
||||
|
||||
type
|
||||
PRINTEROP_FLAGS* = int16 #endif}
|
||||
# FO_MOVE
|
||||
# implicit parameters are:
|
||||
# if pFrom or pTo are unqualified names the current directories are
|
||||
# taken from the global current drive/directory settings managed
|
||||
# by Get/SetCurrentDrive/Directory
|
||||
#
|
||||
# the global confirmation settings
|
||||
# only used if FOF_SIMPLEPROGRESS
|
||||
|
||||
type
|
||||
SHFILEOPSTRUCTA* {.final.} = object
|
||||
hwnd*: HWND
|
||||
wFunc*: UINT
|
||||
pFrom*: LPCSTR
|
||||
pTo*: LPCSTR
|
||||
fFlags*: FILEOP_FLAGS
|
||||
fAnyOperationsAborted*: BOOL
|
||||
hNameMappings*: LPVOID
|
||||
lpszProgressTitle*: LPCSTR # only used if FOF_SIMPLEPROGRESS
|
||||
|
||||
TSHFILEOPSTRUCTA* = SHFILEOPSTRUCTA
|
||||
LPSHFILEOPSTRUCTA* = ptr SHFILEOPSTRUCTA
|
||||
SHFILEOPSTRUCTW* {.final.} = object
|
||||
hwnd*: HWND
|
||||
wFunc*: UINT
|
||||
pFrom*: LPCWSTR
|
||||
pTo*: LPCWSTR
|
||||
fFlags*: FILEOP_FLAGS
|
||||
fAnyOperationsAborted*: BOOL
|
||||
hNameMappings*: LPVOID
|
||||
lpszProgressTitle*: LPCWSTR
|
||||
|
||||
TSHFILEOPSTRUCTW* = SHFILEOPSTRUCTW
|
||||
LPSHFILEOPSTRUCTW* = ptr SHFILEOPSTRUCTW
|
||||
|
||||
when defined(UNICODE):
|
||||
type
|
||||
SHFILEOPSTRUCT* = SHFILEOPSTRUCTW
|
||||
TSHFILEOPSTRUCT* = SHFILEOPSTRUCTW
|
||||
LPSHFILEOPSTRUCT* = LPSHFILEOPSTRUCTW
|
||||
else:
|
||||
type
|
||||
SHFILEOPSTRUCT* = SHFILEOPSTRUCTA
|
||||
TSHFILEOPSTRUCT* = SHFILEOPSTRUCTA
|
||||
LPSHFILEOPSTRUCT* = LPSHFILEOPSTRUCTA
|
||||
proc SHFileOperationA*(lpFileOp: LPSHFILEOPSTRUCTA): int32{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHFileOperationA".}
|
||||
proc SHFileOperationW*(lpFileOp: LPSHFILEOPSTRUCTW): int32{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHFileOperationW".}
|
||||
proc SHFileOperation*(lpFileOp: LPSHFILEOPSTRUCTA): int32{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHFileOperationA".}
|
||||
proc SHFileOperation*(lpFileOp: LPSHFILEOPSTRUCTW): int32{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHFileOperationW".}
|
||||
proc SHFreeNameMappings*(hNameMappings: THandle){.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHFreeNameMappings".}
|
||||
type
|
||||
SHNAMEMAPPINGA* {.final.} = object
|
||||
pszOldPath*: LPSTR
|
||||
pszNewPath*: LPSTR
|
||||
cchOldPath*: int32
|
||||
cchNewPath*: int32
|
||||
|
||||
TSHNAMEMAPPINGA* = SHNAMEMAPPINGA
|
||||
LPSHNAMEMAPPINGA* = ptr SHNAMEMAPPINGA
|
||||
SHNAMEMAPPINGW* {.final.} = object
|
||||
pszOldPath*: LPWSTR
|
||||
pszNewPath*: LPWSTR
|
||||
cchOldPath*: int32
|
||||
cchNewPath*: int32
|
||||
|
||||
TSHNAMEMAPPINGW* = SHNAMEMAPPINGW
|
||||
LPSHNAMEMAPPINGW* = ptr SHNAMEMAPPINGW
|
||||
|
||||
when not(defined(UNICODE)):
|
||||
type
|
||||
SHNAMEMAPPING* = SHNAMEMAPPINGW
|
||||
TSHNAMEMAPPING* = SHNAMEMAPPINGW
|
||||
LPSHNAMEMAPPING* = LPSHNAMEMAPPINGW
|
||||
else:
|
||||
type
|
||||
SHNAMEMAPPING* = SHNAMEMAPPINGA
|
||||
TSHNAMEMAPPING* = SHNAMEMAPPINGA
|
||||
LPSHNAMEMAPPING* = LPSHNAMEMAPPINGA
|
||||
#
|
||||
# End Shell File Operations
|
||||
#
|
||||
#
|
||||
# Begin ShellExecuteEx and family
|
||||
#
|
||||
# ShellExecute() and ShellExecuteEx() error codes
|
||||
# regular WinExec() codes
|
||||
|
||||
const
|
||||
SE_ERR_FNF* = 2 # file not found
|
||||
SE_ERR_PNF* = 3 # path not found
|
||||
SE_ERR_ACCESSDENIED* = 5 # access denied
|
||||
SE_ERR_OOM* = 8 # out of memory
|
||||
SE_ERR_DLLNOTFOUND* = 32 # endif WINVER >= 0x0400
|
||||
# error values for ShellExecute() beyond the regular WinExec() codes
|
||||
SE_ERR_SHARE* = 26
|
||||
SE_ERR_ASSOCINCOMPLETE* = 27
|
||||
SE_ERR_DDETIMEOUT* = 28
|
||||
SE_ERR_DDEFAIL* = 29
|
||||
SE_ERR_DDEBUSY* = 30
|
||||
SE_ERR_NOASSOC* = 31 #if(WINVER >= 0x0400)}
|
||||
# Note CLASSKEY overrides CLASSNAME
|
||||
SEE_MASK_CLASSNAME* = 0x00000001
|
||||
SEE_MASK_CLASSKEY* = 0x00000003 # Note INVOKEIDLIST overrides IDLIST
|
||||
SEE_MASK_IDLIST* = 0x00000004
|
||||
SEE_MASK_INVOKEIDLIST* = 0x0000000C
|
||||
SEE_MASK_ICON* = 0x00000010
|
||||
SEE_MASK_HOTKEY* = 0x00000020
|
||||
SEE_MASK_NOCLOSEPROCESS* = 0x00000040
|
||||
SEE_MASK_CONNECTNETDRV* = 0x00000080
|
||||
SEE_MASK_FLAG_DDEWAIT* = 0x00000100
|
||||
SEE_MASK_DOENVSUBST* = 0x00000200
|
||||
SEE_MASK_FLAG_NO_UI* = 0x00000400
|
||||
SEE_MASK_UNICODE* = 0x00004000
|
||||
SEE_MASK_NO_CONSOLE* = 0x00008000
|
||||
SEE_MASK_ASYNCOK* = 0x00100000
|
||||
SEE_MASK_HMONITOR* = 0x00200000 #if (_WIN32_IE >= 0x0500)
|
||||
SEE_MASK_NOQUERYCLASSSTORE* = 0x01000000
|
||||
SEE_MASK_WAITFORINPUTIDLE* = 0x02000000 #endif (_WIN32_IE >= 0x500)
|
||||
#if (_WIN32_IE >= 0x0560)
|
||||
SEE_MASK_FLAG_LOG_USAGE* = 0x04000000 #endif
|
||||
# (_WIN32_IE >= 0x560)
|
||||
|
||||
type
|
||||
SHELLEXECUTEINFOA* {.final.} = object
|
||||
cbSize*: DWORD
|
||||
fMask*: ULONG
|
||||
hwnd*: HWND
|
||||
lpVerb*: LPCSTR
|
||||
lpFile*: LPCSTR
|
||||
lpParameters*: LPCSTR
|
||||
lpDirectory*: LPCSTR
|
||||
nShow*: int32
|
||||
hInstApp*: HINST
|
||||
lpIDList*: LPVOID
|
||||
lpClass*: LPCSTR
|
||||
hkeyClass*: HKEY
|
||||
dwHotKey*: DWORD
|
||||
hMonitor*: HANDLE # also: hIcon
|
||||
hProcess*: HANDLE
|
||||
|
||||
TSHELLEXECUTEINFOA* = SHELLEXECUTEINFOA
|
||||
LPSHELLEXECUTEINFOA* = ptr SHELLEXECUTEINFOA
|
||||
SHELLEXECUTEINFOW* {.final.} = object
|
||||
cbSize*: DWORD
|
||||
fMask*: ULONG
|
||||
hwnd*: HWND
|
||||
lpVerb*: lpcwstr
|
||||
lpFile*: lpcwstr
|
||||
lpParameters*: lpcwstr
|
||||
lpDirectory*: lpcwstr
|
||||
nShow*: int32
|
||||
hInstApp*: HINST
|
||||
lpIDList*: LPVOID
|
||||
lpClass*: LPCWSTR
|
||||
hkeyClass*: HKEY
|
||||
dwHotKey*: DWORD
|
||||
hMonitor*: HANDLE # also: hIcon
|
||||
hProcess*: HANDLE
|
||||
|
||||
TSHELLEXECUTEINFOW* = SHELLEXECUTEINFOW
|
||||
LPSHELLEXECUTEINFOW* = ptr SHELLEXECUTEINFOW
|
||||
|
||||
when defined(UNICODE):
|
||||
type
|
||||
SHELLEXECUTEINFO* = SHELLEXECUTEINFOW
|
||||
TSHELLEXECUTEINFO* = SHELLEXECUTEINFOW
|
||||
LPSHELLEXECUTEINFO* = LPSHELLEXECUTEINFOW
|
||||
else:
|
||||
type
|
||||
SHELLEXECUTEINFO* = SHELLEXECUTEINFOA
|
||||
TSHELLEXECUTEINFO* = SHELLEXECUTEINFOA
|
||||
LPSHELLEXECUTEINFO* = LPSHELLEXECUTEINFOA
|
||||
proc ShellExecuteExA*(lpExecInfo: LPSHELLEXECUTEINFOA): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ShellExecuteExA".}
|
||||
proc ShellExecuteExW*(lpExecInfo: LPSHELLEXECUTEINFOW): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ShellExecuteExW".}
|
||||
proc ShellExecuteEx*(lpExecInfo: LPSHELLEXECUTEINFOA): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ShellExecuteExA".}
|
||||
proc ShellExecuteEx*(lpExecInfo: LPSHELLEXECUTEINFOW): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "ShellExecuteExW".}
|
||||
proc WinExecErrorA*(HWND: hwnd, error: int32, lpstrFileName: LPCSTR,
|
||||
lpstrTitle: LPCSTR){.stdcall, dynlib: "shell32.dll",
|
||||
importc: "WinExecErrorA".}
|
||||
proc WinExecErrorW*(HWND: hwnd, error: int32, lpstrFileName: LPCWSTR,
|
||||
lpstrTitle: LPCWSTR){.stdcall, dynlib: "shell32.dll",
|
||||
importc: "WinExecErrorW".}
|
||||
proc WinExecError*(HWND: hwnd, error: int32, lpstrFileName: LPCSTR,
|
||||
lpstrTitle: LPCSTR){.stdcall, dynlib: "shell32.dll",
|
||||
importc: "WinExecErrorA".}
|
||||
proc WinExecError*(HWND: hwnd, error: int32, lpstrFileName: LPCWSTR,
|
||||
lpstrTitle: LPCWSTR){.stdcall, dynlib: "shell32.dll",
|
||||
importc: "WinExecErrorW".}
|
||||
type
|
||||
SHCREATEPROCESSINFOW* {.final.} = object
|
||||
cbSize*: DWORD
|
||||
fMask*: ULONG
|
||||
hwnd*: HWND
|
||||
pszFile*: LPCWSTR
|
||||
pszParameters*: LPCWSTR
|
||||
pszCurrentDirectory*: LPCWSTR
|
||||
hUserToken*: HANDLE
|
||||
lpProcessAttributes*: LPSECURITY_ATTRIBUTES
|
||||
lpThreadAttributes*: LPSECURITY_ATTRIBUTES
|
||||
bInheritHandles*: BOOL
|
||||
dwCreationFlags*: DWORD
|
||||
lpStartupInfo*: LPSTARTUPINFOW
|
||||
lpProcessInformation*: LPPROCESS_INFORMATION
|
||||
|
||||
TSHCREATEPROCESSINFOW* = SHCREATEPROCESSINFOW
|
||||
PSHCREATEPROCESSINFOW* = ptr SHCREATEPROCESSINFOW
|
||||
|
||||
proc SHCreateProcessAsUserW*(pscpi: PSHCREATEPROCESSINFOW): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHCreateProcessAsUserW".}
|
||||
#
|
||||
# End ShellExecuteEx and family }
|
||||
#
|
||||
#
|
||||
# RecycleBin
|
||||
#
|
||||
# struct for query recycle bin info
|
||||
type
|
||||
SHQUERYRBINFO* {.final.} = object
|
||||
cbSize*: DWORD
|
||||
i64Size*: int64
|
||||
i64NumItems*: int64
|
||||
|
||||
TSHQUERYRBINFO* = SHQUERYRBINFO
|
||||
LPSHQUERYRBINFO* = ptr SHQUERYRBINFO # flags for SHEmptyRecycleBin
|
||||
|
||||
const
|
||||
SHERB_NOCONFIRMATION* = 0x00000001
|
||||
SHERB_NOPROGRESSUI* = 0x00000002
|
||||
SHERB_NOSOUND* = 0x00000004
|
||||
|
||||
proc SHQueryRecycleBinA*(pszRootPath: LPCSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinA".}
|
||||
proc SHQueryRecycleBinW*(pszRootPath: LPCWSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinW".}
|
||||
proc SHQueryRecycleBin*(pszRootPath: LPCSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinA".}
|
||||
proc SHQueryRecycleBin*(pszRootPath: LPCWSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinW".}
|
||||
proc SHEmptyRecycleBinA*(hwnd: HWND, pszRootPath: LPCSTR, dwFlags: DWORD): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinA".}
|
||||
proc SHEmptyRecycleBinW*(hwnd: HWND, pszRootPath: LPCWSTR, dwFlags: DWORD): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinW".}
|
||||
proc SHEmptyRecycleBin*(hwnd: HWND, pszRootPath: LPCSTR, dwFlags: DWORD): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinA".}
|
||||
proc SHEmptyRecycleBin*(hwnd: HWND, pszRootPath: LPCWSTR, dwFlags: DWORD): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinW".}
|
||||
#
|
||||
# end of RecycleBin
|
||||
#
|
||||
#
|
||||
# Tray notification definitions
|
||||
#
|
||||
type
|
||||
NOTIFYICONDATAA* {.final.} = object
|
||||
cbSize*: DWORD
|
||||
hWnd*: HWND
|
||||
uID*: UINT
|
||||
uFlags*: UINT
|
||||
uCallbackMessage*: UINT
|
||||
hIcon*: HICON
|
||||
szTip*: array[0..127, CHAR]
|
||||
dwState*: DWORD
|
||||
dwStateMask*: DWORD
|
||||
szInfo*: array[0..255, CHAR]
|
||||
uTimeout*: UINT # also: uVersion
|
||||
szInfoTitle*: array[0..63, CHAR]
|
||||
dwInfoFlags*: DWORD
|
||||
guidItem*: TGUID
|
||||
|
||||
TNOTIFYICONDATAA* = NOTIFYICONDATAA
|
||||
PNOTIFYICONDATAA* = ptr NOTIFYICONDATAA
|
||||
NOTIFYICONDATAW* {.final.} = object
|
||||
cbSize*: DWORD
|
||||
hWnd*: HWND
|
||||
uID*: UINT
|
||||
uFlags*: UINT
|
||||
uCallbackMessage*: UINT
|
||||
hIcon*: HICON
|
||||
szTip*: array[0..127, WCHAR]
|
||||
dwState*: DWORD
|
||||
dwStateMask*: DWORD
|
||||
szInfo*: array[0..255, WCHAR]
|
||||
uTimeout*: UINT # also uVersion : UINT
|
||||
szInfoTitle*: array[0..63, CHAR]
|
||||
dwInfoFlags*: DWORD
|
||||
guidItem*: TGUID
|
||||
|
||||
TNOTIFYICONDATAW* = NOTIFYICONDATAW
|
||||
PNOTIFYICONDATAW* = ptr NOTIFYICONDATAW
|
||||
|
||||
when defined(UNICODE):
|
||||
type
|
||||
NOTIFYICONDATA* = NOTIFYICONDATAW
|
||||
TNOTIFYICONDATA* = NOTIFYICONDATAW
|
||||
PNOTIFYICONDATA* = PNOTIFYICONDATAW
|
||||
else:
|
||||
type
|
||||
NOTIFYICONDATA* = NOTIFYICONDATAA
|
||||
TNOTIFYICONDATA* = NOTIFYICONDATAA
|
||||
PNOTIFYICONDATA* = PNOTIFYICONDATAA
|
||||
const
|
||||
NIN_SELECT* = WM_USER + 0
|
||||
NINF_KEY* = 0x00000001
|
||||
NIN_KEYSELECT* = NIN_SELECT or NINF_KEY
|
||||
NIN_BALLOONSHOW* = WM_USER + 2
|
||||
NIN_BALLOONHIDE* = WM_USER + 3
|
||||
NIN_BALLOONTIMEOUT* = WM_USER + 4
|
||||
NIN_BALLOONUSERCLICK* = WM_USER + 5
|
||||
NIM_ADD* = 0x00000000
|
||||
NIM_MODIFY* = 0x00000001
|
||||
NIM_DELETE* = 0x00000002
|
||||
NIM_SETFOCUS* = 0x00000003
|
||||
NIM_SETVERSION* = 0x00000004
|
||||
NOTIFYICON_VERSION* = 3
|
||||
NIF_MESSAGE* = 0x00000001
|
||||
NIF_ICON* = 0x00000002
|
||||
NIF_TIP* = 0x00000004
|
||||
NIF_STATE* = 0x00000008
|
||||
NIF_INFO* = 0x00000010
|
||||
NIF_GUID* = 0x00000020
|
||||
NIS_HIDDEN* = 0x00000001
|
||||
NIS_SHAREDICON* = 0x00000002 # says this is the source of a shared icon
|
||||
# Notify Icon Infotip flags
|
||||
NIIF_NONE* = 0x00000000 # icon flags are mutually exclusive
|
||||
# and take only the lowest 2 bits
|
||||
NIIF_INFO* = 0x00000001
|
||||
NIIF_WARNING* = 0x00000002
|
||||
NIIF_ERROR* = 0x00000003
|
||||
NIIF_ICON_MASK* = 0x0000000F
|
||||
NIIF_NOSOUND* = 0x00000010
|
||||
|
||||
proc Shell_NotifyIconA*(dwMessage: Dword, lpData: PNOTIFYICONDATAA): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconA".}
|
||||
proc Shell_NotifyIconW*(dwMessage: Dword, lpData: PNOTIFYICONDATAW): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconW".}
|
||||
proc Shell_NotifyIcon*(dwMessage: Dword, lpData: PNOTIFYICONDATAA): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconA".}
|
||||
proc Shell_NotifyIcon*(dwMessage: Dword, lpData: PNOTIFYICONDATAW): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconW".}
|
||||
#
|
||||
# The SHGetFileInfo API provides an easy way to get attributes
|
||||
# for a file given a pathname.
|
||||
#
|
||||
# PARAMETERS
|
||||
#
|
||||
# pszPath file name to get info about
|
||||
# dwFileAttributes file attribs, only used with SHGFI_USEFILEATTRIBUTES
|
||||
# psfi place to return file info
|
||||
# cbFileInfo size of structure
|
||||
# uFlags flags
|
||||
#
|
||||
# RETURN
|
||||
# TRUE if things worked
|
||||
#
|
||||
# out: icon
|
||||
# out: icon index
|
||||
# out: SFGAO_ flags
|
||||
# out: display name (or path)
|
||||
# out: type name
|
||||
type
|
||||
SHFILEINFOA* {.final.} = object
|
||||
hIcon*: HICON # out: icon
|
||||
iIcon*: int32 # out: icon index
|
||||
dwAttributes*: DWORD # out: SFGAO_ flags
|
||||
szDisplayName*: array[0..(MAX_PATH) - 1, CHAR] # out: display name (or path)
|
||||
szTypeName*: array[0..79, CHAR] # out: type name
|
||||
|
||||
TSHFILEINFOA* = SHFILEINFOA
|
||||
pSHFILEINFOA* = ptr SHFILEINFOA
|
||||
SHFILEINFOW* {.final.} = object
|
||||
hIcon*: HICON # out: icon
|
||||
iIcon*: int32 # out: icon index
|
||||
dwAttributes*: DWORD # out: SFGAO_ flags
|
||||
szDisplayName*: array[0..(MAX_PATH) - 1, WCHAR] # out: display name (or path)
|
||||
szTypeName*: array[0..79, WCHAR] # out: type name
|
||||
|
||||
TSHFILEINFOW* = SHFILEINFOW
|
||||
pSHFILEINFOW* = ptr SHFILEINFOW
|
||||
|
||||
when defined(UNICODE):
|
||||
type
|
||||
SHFILEINFO* = SHFILEINFOW
|
||||
TSHFILEINFO* = SHFILEINFOW
|
||||
pFILEINFO* = SHFILEINFOW
|
||||
else:
|
||||
type
|
||||
SHFILEINFO* = SHFILEINFOA
|
||||
TSHFILEINFO* = SHFILEINFOA
|
||||
pFILEINFO* = SHFILEINFOA
|
||||
# NOTE: This is also in shlwapi.h. Please keep in synch.
|
||||
|
||||
const
|
||||
SHGFI_ICON* = 0x00000100 # get Icon
|
||||
SHGFI_DISPLAYNAME* = 0x00000200 # get display name
|
||||
SHGFI_TYPENAME* = 0x00000400 # get type name
|
||||
SHGFI_ATTRIBUTES* = 0x00000800 # get attributes
|
||||
SHGFI_ICONLOCATION* = 0x00001000 # get icon location
|
||||
SHGFI_EXETYPE* = 0x00002000 # return exe type
|
||||
SHGFI_SYSICONINDEX* = 0x00004000 # get system icon index
|
||||
SHGFI_LINKOVERLAY* = 0x00008000 # put a link overlay on icon
|
||||
SHGFI_SELECTED* = 0x00010000 # show icon in selected state
|
||||
SHGFI_ATTR_SPECIFIED* = 0x00020000 # get only specified attributes
|
||||
SHGFI_LARGEICON* = 0x00000000 # get large icon
|
||||
SHGFI_SMALLICON* = 0x00000001 # get small icon
|
||||
SHGFI_OPENICON* = 0x00000002 # get open icon
|
||||
SHGFI_SHELLICONSIZE* = 0x00000004 # get shell size icon
|
||||
SHGFI_PIDL* = 0x00000008 # pszPath is a pidl
|
||||
SHGFI_USEFILEATTRIBUTES* = 0x00000010 # use passed dwFileAttribute
|
||||
SHGFI_ADDOVERLAYS* = 0x00000020 # apply the appropriate overlays
|
||||
SHGFI_OVERLAYINDEX* = 0x00000040 # Get the index of the overlay
|
||||
# in the upper 8 bits of the iIcon
|
||||
|
||||
proc SHGetFileInfoA*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
||||
psfi: pSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
||||
proc SHGetFileInfoW*(pszPath: LPCWSTR, dwFileAttributes: DWORD,
|
||||
psfi: pSHFILEINFOW, cbFileInfo, UFlags: UINT): DWORD{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoW".}
|
||||
proc SHGetFileInfo*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
||||
psfi: pSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
||||
proc SHGetFileInfoA*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
||||
psfi: var TSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
||||
proc SHGetFileInfoW*(pszPath: LPCWSTR, dwFileAttributes: DWORD,
|
||||
psfi: var TSHFILEINFOW, cbFileInfo, UFlags: UINT): DWORD{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoW".}
|
||||
proc SHGetFileInfo*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
||||
psfi: var TSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
||||
proc SHGetFileInfo*(pszPath: LPCWSTR, dwFileAttributes: DWORD,
|
||||
psfi: var TSHFILEINFOW, cbFileInfo, UFlags: UINT): DWORD{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoW".}
|
||||
proc SHGetDiskFreeSpaceExA*(pszDirectoryName: LPCSTR,
|
||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExA".}
|
||||
proc SHGetDiskFreeSpaceExW*(pszDirectoryName: LPCWSTR,
|
||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExW".}
|
||||
proc SHGetDiskFreeSpaceEx*(pszDirectoryName: LPCSTR,
|
||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExA".}
|
||||
proc SHGetDiskFreeSpace*(pszDirectoryName: LPCSTR,
|
||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExA".}
|
||||
proc SHGetDiskFreeSpaceEx*(pszDirectoryName: LPCWSTR,
|
||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExW".}
|
||||
proc SHGetDiskFreeSpace*(pszDirectoryName: LPCWSTR,
|
||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExW".}
|
||||
proc SHGetNewLinkInfoA*(pszLinkTo: LPCSTR, pszDir: LPCSTR, pszName: LPSTR,
|
||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoA".}
|
||||
proc SHGetNewLinkInfoW*(pszLinkTo: LPCWSTR, pszDir: LPCWSTR, pszName: LPWSTR,
|
||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoW".}
|
||||
proc SHGetNewLinkInfo*(pszLinkTo: LPCSTR, pszDir: LPCSTR, pszName: LPSTR,
|
||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoA".}
|
||||
proc SHGetNewLinkInfo*(pszLinkTo: LPCWSTR, pszDir: LPCWSTR, pszName: LPWSTR,
|
||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoW".}
|
||||
const
|
||||
SHGNLI_PIDL* = 0x00000001 # pszLinkTo is a pidl
|
||||
SHGNLI_PREFIXNAME* = 0x00000002 # Make name "Shortcut to xxx"
|
||||
SHGNLI_NOUNIQUE* = 0x00000004 # don't do the unique name generation
|
||||
SHGNLI_NOLNK* = 0x00000008 # don't add ".lnk" extension
|
||||
PRINTACTION_OPEN* = 0
|
||||
PRINTACTION_PROPERTIES* = 1
|
||||
PRINTACTION_NETINSTALL* = 2
|
||||
PRINTACTION_NETINSTALLLINK* = 3
|
||||
PRINTACTION_TESTPAGE* = 4
|
||||
PRINTACTION_OPENNETPRN* = 5
|
||||
PRINTACTION_DOCUMENTDEFAULTS* = 6
|
||||
PRINTACTION_SERVERPROPERTIES* = 7
|
||||
|
||||
proc SHInvokePrinterCommandA*(HWND: hwnd, uAction: UINT, lpBuf1: LPCSTR,
|
||||
lpBuf2: LPCSTR, fModal: Bool): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandA".}
|
||||
proc SHInvokePrinterCommandW*(HWND: hwnd, uAction: UINT, lpBuf1: LPCWSTR,
|
||||
lpBuf2: LPCWSTR, fModal: Bool): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandW".}
|
||||
proc SHInvokePrinterCommand*(HWND: hwnd, uAction: UINT, lpBuf1: LPCSTR,
|
||||
lpBuf2: LPCSTR, fModal: Bool): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandA".}
|
||||
proc SHInvokePrinterCommand*(HWND: hwnd, uAction: UINT, lpBuf1: LPCWSTR,
|
||||
lpBuf2: LPCWSTR, fModal: Bool): Bool{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandW".}
|
||||
proc SHLoadNonloadedIconOverlayIdentifiers*(): HResult{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandW".}
|
||||
proc SHIsFileAvailableOffline*(pwszPath: LPCWSTR, pdwStatus: LPDWORD): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHIsFileAvailableOffline".}
|
||||
const
|
||||
OFFLINE_STATUS_LOCAL* = 0x00000001 # If open, it's open locally
|
||||
OFFLINE_STATUS_REMOTE* = 0x00000002 # If open, it's open remotely
|
||||
OFFLINE_STATUS_INCOMPLETE* = 0x00000004 # The local copy is currently incomplete.
|
||||
# The file will not be available offline
|
||||
# until it has been synchronized.
|
||||
# sets the specified path to use the string resource
|
||||
# as the UI instead of the file system name
|
||||
|
||||
proc SHSetLocalizedName*(pszPath: LPWSTR, pszResModule: LPCWSTR, idsRes: int32): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHSetLocalizedName".}
|
||||
proc SHEnumerateUnreadMailAccountsA*(hKeyUser: HKEY, dwIndex: DWORD,
|
||||
pszMailAddress: LPSTR,
|
||||
cchMailAddress: int32): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHEnumerateUnreadMailAccountsA".}
|
||||
proc SHEnumerateUnreadMailAccountsW*(hKeyUser: HKEY, dwIndex: DWORD,
|
||||
pszMailAddress: LPWSTR,
|
||||
cchMailAddress: int32): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHEnumerateUnreadMailAccountsW".}
|
||||
proc SHEnumerateUnreadMailAccounts*(hKeyUser: HKEY, dwIndex: DWORD,
|
||||
pszMailAddress: LPWSTR,
|
||||
cchMailAddress: int32): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHEnumerateUnreadMailAccountsW".}
|
||||
proc SHGetUnreadMailCountA*(hKeyUser: HKEY, pszMailAddress: LPCSTR,
|
||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
||||
pszShellExecuteCommand: LPSTR,
|
||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountA".}
|
||||
proc SHGetUnreadMailCountW*(hKeyUser: HKEY, pszMailAddress: LPCWSTR,
|
||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
||||
pszShellExecuteCommand: LPWSTR,
|
||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountW".}
|
||||
proc SHGetUnreadMailCount*(hKeyUser: HKEY, pszMailAddress: LPCSTR,
|
||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
||||
pszShellExecuteCommand: LPSTR,
|
||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountA".}
|
||||
proc SHGetUnreadMailCount*(hKeyUser: HKEY, pszMailAddress: LPCWSTR,
|
||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
||||
pszShellExecuteCommand: LPWSTR,
|
||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountW".}
|
||||
proc SHSetUnreadMailCountA*(pszMailAddress: LPCSTR, dwCount: DWORD,
|
||||
pszShellExecuteCommand: LPCSTR): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountA".}
|
||||
proc SHSetUnreadMailCountW*(pszMailAddress: LPCWSTR, dwCount: DWORD,
|
||||
pszShellExecuteCommand: LPCWSTR): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountW".}
|
||||
proc SHSetUnreadMailCount*(pszMailAddress: LPCSTR, dwCount: DWORD,
|
||||
pszShellExecuteCommand: LPCSTR): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountA".}
|
||||
proc SHSetUnreadMailCount*(pszMailAddress: LPCWSTR, dwCount: DWORD,
|
||||
pszShellExecuteCommand: LPCWSTR): HRESULT{.stdcall,
|
||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountW".}
|
||||
proc SHGetImageList*(iImageList: int32, riid: TIID, ppvObj: ptr pointer): HRESULT{.
|
||||
stdcall, dynlib: "shell32.dll", importc: "SHGetImageList".}
|
||||
const
|
||||
SHIL_LARGE* = 0 # normally 32x32
|
||||
SHIL_SMALL* = 1 # normally 16x16
|
||||
SHIL_EXTRALARGE* = 2
|
||||
SHIL_SYSSMALL* = 3 # like SHIL_SMALL, but tracks system small icon metric correctly
|
||||
SHIL_LAST* = SHIL_SYSSMALL
|
||||
|
||||
# implementation
|
||||
|
||||
proc EIRESID(x: int32): int32 =
|
||||
result = -x
|
||||
93
lib/windows/shfolder.nim
Normal file
93
lib/windows/shfolder.nim
Normal file
@@ -0,0 +1,93 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2006 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# shfolder.dll is distributed standard with IE5.5, so it should ship
|
||||
# with 2000/XP or higher but is likely to be installed on NT/95/98 or
|
||||
# ME as well. It works on all these systems.
|
||||
#
|
||||
# The info found here is also in the registry:
|
||||
# HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\
|
||||
# HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\
|
||||
#
|
||||
# Note that not all CSIDL_* constants are supported by shlfolder.dll,
|
||||
# they should be supported by the shell32.dll, though again not on all
|
||||
# systems.
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
{.deadCodeElim: on.}
|
||||
|
||||
import
|
||||
windows
|
||||
|
||||
const
|
||||
LibName* = "SHFolder.dll"
|
||||
|
||||
const
|
||||
CSIDL_PROGRAMS* = 0x00000002 # %SYSTEMDRIVE%\Program Files
|
||||
CSIDL_PERSONAL* = 0x00000005 # %USERPROFILE%\My Documents
|
||||
CSIDL_FAVORITES* = 0x00000006 # %USERPROFILE%\Favorites
|
||||
CSIDL_STARTUP* = 0x00000007 # %USERPROFILE%\Start menu\Programs\Startup
|
||||
CSIDL_RECENT* = 0x00000008 # %USERPROFILE%\Recent
|
||||
CSIDL_SENDTO* = 0x00000009 # %USERPROFILE%\Sendto
|
||||
CSIDL_STARTMENU* = 0x0000000B # %USERPROFILE%\Start menu
|
||||
CSIDL_MYMUSIC* = 0x0000000D # %USERPROFILE%\Documents\My Music
|
||||
CSIDL_MYVIDEO* = 0x0000000E # %USERPROFILE%\Documents\My Videos
|
||||
CSIDL_DESKTOPDIRECTORY* = 0x00000010 # %USERPROFILE%\Desktop
|
||||
CSIDL_NETHOOD* = 0x00000013 # %USERPROFILE%\NetHood
|
||||
CSIDL_TEMPLATES* = 0x00000015 # %USERPROFILE%\Templates
|
||||
CSIDL_COMMON_STARTMENU* = 0x00000016 # %PROFILEPATH%\All users\Start menu
|
||||
CSIDL_COMMON_PROGRAMS* = 0x00000017 # %PROFILEPATH%\All users\Start menu\Programs
|
||||
CSIDL_COMMON_STARTUP* = 0x00000018 # %PROFILEPATH%\All users\Start menu\Programs\Startup
|
||||
CSIDL_COMMON_DESKTOPDIRECTORY* = 0x00000019 # %PROFILEPATH%\All users\Desktop
|
||||
CSIDL_APPDATA* = 0x0000001A # %USERPROFILE%\Application Data (roaming)
|
||||
CSIDL_PRINTHOOD* = 0x0000001B # %USERPROFILE%\Printhood
|
||||
CSIDL_LOCAL_APPDATA* = 0x0000001C # %USERPROFILE%\Local Settings\Application Data (non roaming)
|
||||
CSIDL_COMMON_FAVORITES* = 0x0000001F # %PROFILEPATH%\All users\Favorites
|
||||
CSIDL_INTERNET_CACHE* = 0x00000020 # %USERPROFILE%\Local Settings\Temporary Internet Files
|
||||
CSIDL_COOKIES* = 0x00000021 # %USERPROFILE%\Cookies
|
||||
CSIDL_HISTORY* = 0x00000022 # %USERPROFILE%\Local settings\History
|
||||
CSIDL_COMMON_APPDATA* = 0x00000023 # %PROFILESPATH%\All Users\Application Data
|
||||
CSIDL_WINDOWS* = 0x00000024 # %SYSTEMROOT%
|
||||
CSIDL_SYSTEM* = 0x00000025 # %SYSTEMROOT%\SYSTEM32 (may be system on 95/98/ME)
|
||||
CSIDL_PROGRAM_FILES* = 0x00000026 # %SYSTEMDRIVE%\Program Files
|
||||
CSIDL_MYPICTURES* = 0x00000027 # %USERPROFILE%\My Documents\My Pictures
|
||||
CSIDL_PROFILE* = 0x00000028 # %USERPROFILE%
|
||||
CSIDL_PROGRAM_FILES_COMMON* = 0x0000002B # %SYSTEMDRIVE%\Program Files\Common
|
||||
CSIDL_COMMON_TEMPLATES* = 0x0000002D # %PROFILEPATH%\All Users\Templates
|
||||
CSIDL_COMMON_DOCUMENTS* = 0x0000002E # %PROFILEPATH%\All Users\Documents
|
||||
CSIDL_COMMON_ADMINTOOLS* = 0x0000002F # %PROFILEPATH%\All Users\Start Menu\Programs\Administrative Tools
|
||||
CSIDL_ADMINTOOLS* = 0x00000030 # %USERPROFILE%\Start Menu\Programs\Administrative Tools
|
||||
CSIDL_COMMON_MUSIC* = 0x00000035 # %PROFILEPATH%\All Users\Documents\my music
|
||||
CSIDL_COMMON_PICTURES* = 0x00000036 # %PROFILEPATH%\All Users\Documents\my pictures
|
||||
CSIDL_COMMON_VIDEO* = 0x00000037 # %PROFILEPATH%\All Users\Documents\my videos
|
||||
CSIDL_CDBURN_AREA* = 0x0000003B # %USERPROFILE%\Local Settings\Application Data\Microsoft\CD Burning
|
||||
CSIDL_PROFILES* = 0x0000003E # %PROFILEPATH%
|
||||
CSIDL_FLAG_CREATE* = 0x00008000 # (force creation of requested folder if it doesn't exist yet)
|
||||
# Original entry points
|
||||
|
||||
proc SHGetFolderPathA*(Ahwnd: HWND, Csidl: int, Token: THandle, Flags: DWord,
|
||||
Path: cstring): HRESULT{.stdcall, dynlib: LibName,
|
||||
importc: "SHGetFolderPathA".}
|
||||
proc SHGetFolderPathW*(Ahwnd: HWND, Csidl: int, Token: THandle, Flags: DWord,
|
||||
Path: cstring): HRESULT{.stdcall, dynlib: LibName,
|
||||
importc: "SHGetFolderPathW".}
|
||||
proc SHGetFolderPath*(Ahwnd: HWND, Csidl: int, Token: THandle, Flags: DWord,
|
||||
Path: cstring): HRESULT{.stdcall, dynlib: LibName,
|
||||
importc: "SHGetFolderPathA".}
|
||||
type
|
||||
PFNSHGetFolderPathA* = proc (Ahwnd: HWND, Csidl: int, Token: THandle,
|
||||
Flags: DWord, Path: cstring): HRESULT{.stdcall.}
|
||||
PFNSHGetFolderPathW* = proc (Ahwnd: HWND, Csidl: int, Token: THandle,
|
||||
Flags: DWord, Path: cstring): HRESULT{.stdcall.}
|
||||
PFNSHGetFolderPath* = PFNSHGetFolderPathA
|
||||
TSHGetFolderPathA* = PFNSHGetFolderPathA
|
||||
TSHGetFolderPathW* = PFNSHGetFolderPathW
|
||||
TSHGetFolderPath* = TSHGetFolderPathA
|
||||
|
||||
23945
lib/windows/windows.nim
Normal file
23945
lib/windows/windows.nim
Normal file
File diff suppressed because it is too large
Load Diff
18
tests/system/params.nim
Normal file
18
tests/system/params.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
import osproc
|
||||
import parseopt2
|
||||
import sequtils
|
||||
|
||||
let argv = commandLineParams()
|
||||
|
||||
if argv == @[]:
|
||||
# this won't work with spaces
|
||||
assert execShellCmd(getAppFilename() & " \"foo bar\" --aa:bar=a --a=c:d --ab -c --a[baz]:doo") == 0
|
||||
else:
|
||||
let f = toSeq(getopt())
|
||||
echo f.repr
|
||||
assert f[0].kind == cmdArgument and f[0].key == "foo bar" and f[0].val == ""
|
||||
assert f[1].kind == cmdLongOption and f[1].key == "aa" and f[1].val == "bar=a"
|
||||
assert f[2].kind == cmdLongOption and f[2].key == "a=c" and f[2].val == "d"
|
||||
assert f[3].kind == cmdLongOption and f[3].key == "ab" and f[3].val == ""
|
||||
assert f[4].kind == cmdShortOption and f[4].key == "c" and f[4].val == ""
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
import
|
||||
parseutils, strutils, pegs, os, osproc, streams, parsecfg, browsers, json,
|
||||
marshal, cgi, parseopt, caasdriver
|
||||
marshal, cgi, parseopt #, caas
|
||||
|
||||
const
|
||||
cmdTemplate = r"nimrod cc --hints:on $# $#"
|
||||
@@ -364,10 +364,10 @@ proc outputJSON(reject, compile, run: TResults) =
|
||||
var s = pretty(doc)
|
||||
writeFile(jsonFile, s)
|
||||
|
||||
proc runCaasTests(r: var TResults) =
|
||||
for test, output, status, mode in caasTestsRunner():
|
||||
r.addResult(test, "", output & "-> " & $mode,
|
||||
if status: reSuccess else: reOutputsDiffer)
|
||||
# proc runCaasTests(r: var TResults) =
|
||||
# for test, output, status, mode in caasTestsRunner():
|
||||
# r.addResult(test, "", output & "-> " & $mode,
|
||||
# if status: reSuccess else: reOutputsDiffer)
|
||||
|
||||
proc main() =
|
||||
os.putenv "NIMTEST_NO_COLOR", "1"
|
||||
@@ -411,7 +411,7 @@ proc main() =
|
||||
writeResults(runJson, r)
|
||||
of "special":
|
||||
runSpecialTests(r, p.cmdLineRest.string)
|
||||
runCaasTests(r)
|
||||
# runCaasTests(r)
|
||||
writeResults(runJson, r)
|
||||
of "rodfiles":
|
||||
runRodFiles(r, p.cmdLineRest.string)
|
||||
|
||||
@@ -18,44 +18,12 @@ const
|
||||
("mysql", "mysql"),
|
||||
("postgres", ""),
|
||||
("sqlite3", "sqlite3"),
|
||||
("tcl", "tcl"),
|
||||
("cairo/cairo", "cairo"),
|
||||
("cairo/cairoft", "cairo"),
|
||||
("cairo/cairowin32", "cairo"),
|
||||
("cairo/cairoxlib", "cairo"),
|
||||
|
||||
("gtk/atk", "atk"),
|
||||
("gtk/gdk2", "gdk"),
|
||||
("gtk/gdk2pixbuf", "gdk"),
|
||||
("gtk/gdkglext", "gdk"),
|
||||
("gtk/glib2", ""),
|
||||
("gtk/gtk2", "gtk"),
|
||||
("gtk/gtkglext", "gtk"),
|
||||
("gtk/gtkhtml", "gtk"),
|
||||
("gtk/libglade2", "glade"),
|
||||
("gtk/pango", "pango"),
|
||||
("gtk/pangoutils", "pango"),
|
||||
|
||||
("lua/lua", "lua"),
|
||||
("lua/lauxlib", "luaL"),
|
||||
("lua/lualib", "lua"),
|
||||
|
||||
("opengl/gl", ""),
|
||||
("opengl/glext", ""),
|
||||
("opengl/wingl", ""),
|
||||
("opengl/glu", ""),
|
||||
("opengl/glut", ""),
|
||||
("opengl/glx", ""),
|
||||
|
||||
("pcre/pcre", "pcre")
|
||||
]
|
||||
|
||||
proc createDirs =
|
||||
createDir("lib/newwrap/sdl")
|
||||
createDir("lib/newwrap/cairo")
|
||||
createDir("lib/newwrap/gtk")
|
||||
createDir("lib/newwrap/lua")
|
||||
createDir("lib/newwrap/opengl")
|
||||
createDir("lib/newwrap/pcre")
|
||||
|
||||
for filename, prefix in items(filelist):
|
||||
|
||||
@@ -66,17 +66,14 @@ srcdoc2: "packages/docutils/rstgen"
|
||||
|
||||
webdoc: "wrappers/libcurl;pure/md5;wrappers/mysql;wrappers/iup"
|
||||
webdoc: "wrappers/sqlite3;wrappers/postgres;wrappers/tinyc"
|
||||
webdoc: "wrappers/python;wrappers/tcl;wrappers/expat;wrappers/pcre"
|
||||
webdoc: "wrappers/expat;wrappers/pcre"
|
||||
webdoc: "wrappers/tre;wrappers/openssl"
|
||||
webdoc: "wrappers/libuv;wrappers/joyent_http_parser"
|
||||
|
||||
webdoc: "posix/posix;wrappers/odbcsql;impure/dialogs"
|
||||
webdoc: "wrappers/zip/zlib;wrappers/zip/libzip"
|
||||
webdoc: "wrappers/cairo"
|
||||
webdoc: "wrappers/gtk"
|
||||
webdoc: "wrappers/libsvm.nim;wrappers/mongo.nim"
|
||||
webdoc: "windows"
|
||||
webdoc: "wrappers/x11;wrappers/opengl;wrappers/lua"
|
||||
webdoc: "wrappers/readline/readline;wrappers/readline/history"
|
||||
webdoc: "wrappers/readline/rltypedefs"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user