50 lines
872 B
Plaintext
50 lines
872 B
Plaintext
use re
|
|
use str
|
|
|
|
fn -value [v]{
|
|
var p = (re:find '^(\d+)\((\w+)\)$' $v)
|
|
if (and (has-key $p groups) (== (count $p[groups]) 3)) {
|
|
put [
|
|
&number=$p[groups][1][text]
|
|
&text=$p[groups][2][text]
|
|
]
|
|
}
|
|
}
|
|
|
|
fn -values [v]{
|
|
var vv = [ (str:split ',' $v) ]
|
|
if (== (count $vv) 1) {
|
|
-value $vv[0]
|
|
} else {
|
|
put [ (each $-value~ $vv) ]
|
|
}
|
|
}
|
|
|
|
fn -get-id []{
|
|
var id = [&]
|
|
str:split ' ' (id) | each [e]{
|
|
var p = [ (str:split '=' $e) ]
|
|
if (== (count $p) 2) {
|
|
set id[$p[0]] = (-values $p[1])
|
|
}
|
|
}
|
|
put $id
|
|
}
|
|
|
|
fn -get [k]{
|
|
var id = (-get-id)
|
|
if (has-key $id $k) {
|
|
put $id[$k]
|
|
}
|
|
}
|
|
|
|
fn -is-root []{
|
|
== (-get uid)[number] 0
|
|
}
|
|
|
|
edit:add-var get-id~ $-get-id~
|
|
edit:add-var get-uid~ []{ -get uid }
|
|
edit:add-var get-gid~ []{ -get gid }
|
|
edit:add-var get-groups~ []{ -get groups; -get groupes }
|
|
edit:add-var is-root~ $-is-root~
|