mIRC Home    About    Download    Register    News    Help

Print Thread
#227148 27/10/10 03:17 PM
Joined: Nov 2009
Posts: 81
V
Voglea Offline OP
Babel fish
OP Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
//fopen -no handle test.txt | fwrite handle test | fseek handle 2 | fwrite handle test | fclose handle

Quote:
tetest

maybe it bug and should be:
Quote:
tetestst

?

It works like binary variables, just I think this is wrong.

Voglea #227157 27/10/10 06:24 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
this isn't a bug, /fwrite is supposed to overwrite bytes. 'insertion' is not a simple low level operation like the rest of them, it requires the buffer to be extended and all bytes from the position of insertion to be copied over.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Voglea #227174 29/10/10 07:21 AM
Joined: Apr 2010
Posts: 966
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 966
I haven't tested it, but you could write your own like the following:

/FInsert -b <Handle> <Position> <Text>|<&bvar [BPosition [Len]]>
Handle: Name used in /fopen to open file
Position: The position of where should start insertation.
Text: Text you wish to insert.

If the -b switch is specified, then the command will treat the text as a binvary variable:
&bvar: The binary variable you'd like to insert
BPosition: The position within &bvar you'd like to start copying from. This is optional.
Len: The number of bytes you'd like to copy from the binary variable. This is optional, but if specified, position must be specified.

Code:
alias FInsert {
  var %bvar $false
  if ($1 == -b) { var %bvar $true | tokenize 32 $2- }
  if (!$fopen($1)) { echo $color(info).dd -a /FInsert: Invalid parameters( $+ $1 is no opened) | halt }
  elseif ($2. !isnum 0-) { echo $color(info).dd -a /FInsert: Invalid parameters(No such position as $2 | halt }
  elseif (!$len($3-)) { echo $color(info).dd -a /FIsert: Invalid Parameters(No data to specified) | halt }
  elseif (%bvar && $len($6-)) { echo $color(info).dd -a /FInsert: To many parameters Specified) | halt }
  elseif (%bvar && !$bvar($3,0)) { echo $color(info).dd -a /FInsert: Invalid Parameters(No data in $1 $+ ) | halt }
  elseif (%bvar && $len($4) && $4. !isnum 1-) { echo $color(info).dd -a /FInsert: Invalid parameters( $+ $4 is an invalid binvar position.) | halt }
  elseif (%bvar && $4 > $bvar($3,0)) { echo $color(info).dd -a /FInsert: Invalid parameters(No posistion $4 in $3 $+ ) | halt }
  elseif (%bvar && $Len($5) && $5. !isnum 1-) { echo $color(info).dd -a /FInsert: Invalid Parameters( $+ $5 is not a valid length.) | halt }
  else {
    fseek $1 $2
    noop $fread($1,$calc($file($fopen($1).fname).size - $2),&tmp)
    if (%bvar) { bcopy &tmp $calc($bvar(&tmp,0) +1) $3 $iif($4,$v1 $iif($5,$v1),1  -1)  }
    else { 
      bset -t &tmp $calc($bvar(&tmp,0) +1) $3-
    }
    fseek $1 $2
    fwrite -b $1 &tmp
  }
}


I am SReject
My Stuff

Link Copied to Clipboard