aIRC — File Browser
aIRCv0.8.69 / aIRCv0.8.69 / script / lists.mrc
lists.mrc — 6.89 KB — Download this file
;/**********************************************************************
; *
; * aIRC
; * Lists
; *
; **********************************************************************/
alias _start.filelist {
var %usrdir = $_usrdir $+ lists\
_dummy $findfile(%usrdir,*,0,1,_list.hash $nopath($1-) $shortfn($1-))
var %usrdir = $_usrdir $+ recent\
_dummy $findfile(%usrdir,*,0,1,_recent.hash $nopath($1-) $shortfn($1-))
}
ON *:FILERCVD:*:{ _recent.add files 10 $_fixfilename($filename,m) }
ON me:*:JOIN:#:{ _recent.add channel 10 $chan }
ON *:CONNECT:{
_recent.add nick 10 $me
_recent.add server 10 $_server $port
}
ON me:*:NICK:{ _recent.add nick 10 $newnick }
;
;
;
alias _filelist.file {
var %file = $_usrdir $+ $iif(l* iswm $1,lists,recent) $+ \ $+ $2
return $_chfile(%file)
}
alias _filelist.tablename { return _ $+ $iif(l* iswm $1,lists,recent) $+ _ $+ $2 }
alias _filelist.hash {
var %h = _ $+ $iif(l* iswm $1,lists,recent) $+ _ $+ $2,%file = $iif($3- != $null,$3-,$shortfn($_filelist.file($1,$2)))
_hmake %h 10
hload -n %h %file
}
alias _filelist.add {
if ($2 == $null) || ($3 !isnum) || ($3 < 0) || ($4- == $null) { return }
var %file = $shortfn($_filelist.file($1,$2)),%win = @__filelistadd,%i,%l
_openwins %win
loadbuf %win %file
%i = $fline(%win,$4-,0,0)
while (%i) {
%l = $fline(%win,$4-,%i,0)
if ($line(%win,%l) == $4-) { dline %win %l }
dec %i
}
iline %win 1 $4-
if ($3 > 0) { savebuf 1- $+ $3 %win %file }
else { savebuf %win %file }
close -@ %win
_filelist.hash $1 $2 %file
return 1
}
alias _filelist.ladd {
if ($2 == $null) || ($3 !isnum) || ($3 < 0) || ($4- == $null) { return }
var %file = $shortfn($_filelist.file($1,$2)),%win = @__filelistladd,%i,%l
_openwins %win
loadbuf %win %file
%i = $fline(%win,$4-,0,0)
while (%i) {
%l = $fline(%win,$4-,%i,0)
if ($line(%win,%l) == $4-) { dline %win %l }
dec %i
}
aline %win $4-
if ($3 > 0) { savebuf 1- $+ $3 %win %file }
else { savebuf %win %file }
close -@ %win
_filelist.hash $1 $2 %file
return $_filelist.total($1,$2)
}
alias _filelist.del {
if ($2 == $null) || ($3- == $null) { return }
var %file = $shortfn($_filelist.file($1,$2)),%win = @__filelistdel,%i,%l,%deleted = 0
_openwins %win
loadbuf %win %file
%i = $fline(%win,$3-,0,0)
while (%i) {
%l = $fline(%win,$3-,%i,0)
if ($line(%win,%l) == $3-) {
dline %win %l
inc %deleted
}
dec %i
}
savebuf %win %file
close -@ %win
_filelist.hash $1 $2 %file
return %deleted
}
alias _filelist.flush {
var %file = $shortfn($_filelist.file($1,$$2)),%lines = $lines(%file)
write -c %file
if ($show) { info.a Cleared list }
_filelist.hash $1 $2 %file
return %lines
}
alias _filelist.get {
var %h = _ $+ $iif(l* iswm $1,lists,recent) $+ _ $+ $2
return $hget(%h,$3)
}
alias _filelist.fileget { return $read -nl $+ $3 " $+ $_filelist.file($1,$$2) $+ " }
alias _filelist.total { return $lines($shortfn($_filelist.file($1,$2))) }
alias _filelist.tokadd {
var %i = 1,%file = $shortfn($_filelist.file($1,$2))
while ($_filelist.fileget($1,$2,%i) != $null) {
if ($gettok($ifmatch,$3,$4) === $5-) {
if (%i) { return $ifmatch }
}
inc %i
}
if ($lines(%file) > 0) { return $calc($ifmatch + 1) }
return 1
}
alias _filelist.tokdel {
var %i = 1,%file = " $+ $_filelist.file($1,$2) $+ "
while ($_filelist.fileget($1,$2,%i) != $null) {
if ($gettok($ifmatch,$3,$4) == $5-) {
write -dl $+ %i %file
break
}
inc %i
}
_filelist.hash $1 $2 %file
}
alias _filelist.moveup {
var %file = " $+ $_filelist.file($1,$2) $+ ",%i = $read -nl $+ $3 %file
if ($3 <= 1) { return }
write -l $+ $3 %file $read -nl $+ $calc($3 - 1) %file
write -l $+ $calc($3 - 1) %file %i
_filelist.hash $1 $2 %file
}
alias _filelist.movedown {
var %file = " $+ $_filelist.file($1,$2) $+ ",%i = $read -nl $+ $3 %file
if ($3 >= $lines(%file)) { return }
write -l $+ $3 %file $read -nl $+ $calc($3 + 1) %file
write -l $+ $calc($3 + 1) %file %i
_filelist.hash $1 $2 %file
}
alias _filelist.findline {
if ($2 == $null) || ($3- == $null) { return }
var %file = $shortfn($_filelist.file($1,$2)),%win = @__filelistfindline,%i,%l,%found
_openwins %win
loadbuf %win %file
%i = $fline(%win,$3-,0,0)
while (%i) {
%l = $fline(%win,$3-,%i,0)
if ($line(%win,%l) == $3-) {
%found = %l
break
}
dec %i
}
close -@ %win
_filelist.hash $1 $2 %file
return %found
}
;;
;
; $_recent.tablename(<type>)
; /_recent.add <type> <max> <text>
; /_recent.ladd <type> <max> <text>
; /_recent.del <type> <text>
; /_recent.flush <type>
; $_recent.file(<type>)
; $_recent.get(type,n)
; $_recent.total(type)
; /_recent.tokadd type N token text
; /_recent.tokdel type N token text
; /_recent.moveup type N
; /_recent.movedown type N
; $_recent.findline(type,text)
;
alias _recent.tablename { return $_filelist.tablename(r,$1) }
alias _recent.add { return $_filelist.add(r,$1,$2,$3-) }
alias _recent.ladd { return $_filelist.ladd(r,$1,$2,$3-) }
alias _recent.del { return $_filelist.del(r,$1,$2-) }
alias _recent.flush {
_filelist.flush r $1
return $result
}
alias _recent.file { return $_filelist.file(r,$1) }
alias _recent.get { return $_filelist.get(r,$1,$2) }
alias _recent.total { return $_filelist.total(r,$1) }
alias _recent.tokadd { return $_filelist.tokadd(r,$1,$2,$3,$4-) }
alias _recent.tokdel { return $_filelist.tokdel(r,$1,$2,$3,$4-) }
alias _recent.moveup { return $_filelist.moveup(r,$1,$2) }
alias _recent.movedown { return $_filelist.movedown(r,$1,$2) }
alias _recent.findline { return $_filelist.findline(r,$1,$2-) }
alias _recent.hash { return $_filelist.hash(r,$1,$2) }
;
;
; $_list.tablename(<type>)
; /_list.add <type> <text>
; /_list.ladd <type> <text>
; /_list.del <type> <text>
; /_list.flush <type>
; $_list.file(<type>)
; $_list.get(type,n)
; $_list.total(type)
; /_list.tokadd type N token text
; /_list.tokdel type N token text
; /_list.moveup type N
; /_list.movedown type N
; $_list.findline(type,text)
;
alias _list.tablename { return $_filelist.tablename(l,$1) }
alias _list.add { return $_filelist.add(l,$1,0,$2-) }
alias _list.ladd { return $_filelist.ladd(l,$1,0,$2-) }
alias _list.del { return $_filelist.del(l,$1,$2-) }
alias _list.flush {
_filelist.flush l $1
return $result
}
alias _list.file { return $_filelist.file(l,$1) }
alias _list.get { return $_filelist.get(l,$1,$2) }
alias _list.total { return $_filelist.total(l,$1) }
alias _list.tokadd { return $_filelist.tokadd(l,$1,$2,$3,$4-) }
alias _list.tokdel { return $_filelist.tokdel(l,$1,$2,$3,$4-) }
alias _list.moveup { return $_filelist.moveup(l,$1,$2) }
alias _list.movedown { return $_filelist.movedown(l,$1,$2) }
alias _list.findline { return $_filelist.findline(l,$1,$2-) }
alias _list.hash { return $_filelist.hash(l,$1,$2) }