This alias replicates the /remini command using $fread, /fopen, /fclose, /fseek and /write
Basically, we know that remini and writeini have constraints of doing what they're suppose to do in files larger than 64kb.
I created this in response to a comment from writeini Concept #1, this is my first attempt at using the File Handling commands, so any constructive criticism is welcome!
This snippet works exactly the same as remini, except it utilizes other mIRC commands to perform the function.
Usage: /_remini [item]
alias _remini {
;No file? Don't continue
if (!$exists($1)) { return }
;Is the <inifile> larger than 64kb?
if ($file($1).size > 65536) {
;Let's open the file
.fopen remini $1
;Does the <section> exist?
.fseek -w remini $+(*,$chr(91),$2,$chr(93),*)
;No <section> found, halting process
if (!$fread(remini)) {
.fclose remini
return
}
var %x = $lines($1), %y = 1, %t = 0
while (%y <= %x) {
;Now we're going to read line by line looking for <section>
.fseek -l remini %y
;Here's the data from the line we're reading
var %l = $fread(remini)
;We found <section>
if ($remove(%l,$chr(91),$chr(93)) == $2) {
var %r = $calc(%y + 1)
while (%r <= %x) {
.fseek -l remini %r
;Finding the number of [items] in the <section> now
if ($chr(91) != $left($fread(remini),1)) { inc %t }
;Scanning of [items] complete, let's move on
else { break }
inc %r
}
;Let's close the file so we can start deleting data
if (%t) {
if (!$3) { .fclose remini }
}
;This is where we determine if to delete an [item] or <section>
while (%t) {
;Our [items] begin on this line
var %s = $calc(%y + %t)
if ($3) {
.fseek -l remini %s
;We found our [item]
if ($gettok($fread(remini),1,61) == $3) {
;Let's close the file so we can delete
.fclose remini
write $+(-dl,%s) $1
;We're done here, no point continuing
halt
}
}
;This is where we delete all [items]
else { write $+(-dl,%s) $1 }
dec %t
}
;Delete <section> if that's all that was given
if (!$3) { write $+(-dl,%y) $1 }
;We're done here, no point continuing the loop
break
}
inc %y
}
;We're done here, let's close the file if it's open
if ($fopen(remini)) { .fclose remini }
}
;File size isn't larger than 64kb, so we invoke standard command
else { remini $1- }
}