From WikiChip
Difference between revisions of "mirc/commands/bcopy"
< mirc‎ | commands

m (Bot: de-linking old mIRC menu)
(Add'l syntax/examples)
Line 2: Line 2:
 
The '''/bcopy command''' can be used to copy any amount of bytes from one variable starting at a specific position into a second variable at a specific position. This command supports copying of overlapping buffers.  
 
The '''/bcopy command''' can be used to copy any amount of bytes from one variable starting at a specific position into a second variable at a specific position. This command supports copying of overlapping buffers.  
  
If the number of bytes to copy is -1, all bytes available will be copied over to the destination variable.
+
If the number of bytes to copy is -1, all bytes available will be copied over to the destination variable. If the destination position is -1, the bytes will be appended.
  
 
'''Note:''' The first byte starts at the position/index 1, 0 is invalid and will procudes an error.
 
'''Note:''' The first byte starts at the position/index 1, 0 is invalid and will procudes an error.
Line 11: Line 11:
 
== Switches ==
 
== Switches ==
 
* '''-z''' - Bytes copied from the source binary variable gets zero-filled after the copy
 
* '''-z''' - Bytes copied from the source binary variable gets zero-filled after the copy
* '''-c''' - Truncates the destination variable to a length of  <des_pos> + <numBytes>
+
* '''-c''' - Truncates the destination variable to remove bytes following the bytes copied. Where both N and M are positive, the new destination length is <des_pos> + <numBytes> -1
  
 
== Parameters ==
 
== Parameters ==
 
* '''<&dest_binvar>''' - The destination binary variable.
 
* '''<&dest_binvar>''' - The destination binary variable.
* '''<des_pos>''' - The position to which to copy the byte to.
+
* '''<des_pos>''' - The position to which to copy the byte to (or -1 to append to destination).
 
* '''<&src_binvar>''' - The source binary variable.
 
* '''<&src_binvar>''' - The source binary variable.
 
* '''<src_pos>''' - The position from which to start copying bytes.
 
* '''<src_pos>''' - The position from which to start copying bytes.
* '''<numBytes>''' - Number of bytes to copy (or -1 for everything).
+
* '''<numBytes>''' - Number of bytes to copy beginning at <src pos> (or -1 for everything).
  
 
== Example ==
 
== Example ==
Line 40: Line 40:
 
<pre>This is a
 
<pre>This is a
 
cool test!</pre>
 
cool test!</pre>
 +
 +
<source lang="mIRC">
 +
;while these variables exist:
 +
//bset &to 1 11 22 33 44 55 66 | bset &from 1 77 88 99 123
 +
and &to contains "11 22 33 44 55 66" and &to contains "77 88 99 123"
 +
each of the following commands are based on the above values and are not executed after any of the other alternatives...
 +
 +
bcopy &to 2 &from 1 3
 +
; copies 3 bytes at offset 1 of &from to overwrite the 3 bytes at offset 2 of &to. Length remains 6
 +
11 77 88 99 55 66
 +
 +
bcopy -z &to 2 &from 1 3
 +
; same alteration of &to, but all byte positions in &from which were copied are changed to 0x00's. &from is now "0 0 0 123"
 +
11 77 88 99 55 66
 +
 +
bcopy -c &to 2 &from 1 3
 +
; adding the -c switch causes any destination bytes following the copied bytes to be removed, shortening &to to length 4
 +
11 77 88 99
 +
bcopy -c &to 2 &from 1 0
 +
; does not generate an error, but does not truncate the destination because 0 bytes were copied
 +
11 22 33 44 55 66
 +
 +
bcopy &to 2 &from 1 99
 +
; M is larger than bytes available beginning at offset 1, so the 4 bytes are copied to destination positions 2-5 without affecting the destination's 6th byte.
 +
11 77 88 99 0 66
 +
 +
bcopy &to -1 &from 1 -1
 +
; Destination position -1 causes bytes to be appended. Using -1 as number of bytes to copy copies the entire &from string beginning at position 1.
 +
11 22 33 44 55 66 77 88 99 123
 +
 +
bcopy -c &to 1 &to 2 999
 +
; copies positions 2-6 to 1-5. Without the -c switch, the length would still be 6 with the 66 repeated.
 +
22 33 44 55 66
 +
 +
bcopy &to -1 &to 1 999
 +
; appends the 6 bytes, doubling the length to 12
 +
11 22 33 44 55 66 11 22 33 44 55 66
 +
 +
bcopy -c &to 2 &to 1 999
 +
; places the old contents of positions 1-6 into positions 2-7. The bytes are not update after each byte, so does not cause 11 to be replicated in each position.
 +
11 11 22 33 44 55 66
 +
 +
bcopy -c &to 3 &to 3 1
 +
; truncates a variable to length 3
 +
</source>
  
 
== Compatibility ==
 
== Compatibility ==

Revision as of 05:05, 3 December 2017

The /bcopy command can be used to copy any amount of bytes from one variable starting at a specific position into a second variable at a specific position. This command supports copying of overlapping buffers.

If the number of bytes to copy is -1, all bytes available will be copied over to the destination variable. If the destination position is -1, the bytes will be appended.

Note: The first byte starts at the position/index 1, 0 is invalid and will procudes an error.

Synopsis

/bcopy [-zc] <&dest_binvar> <des_pos> <&src_binvar> <src_pos> <numBytes>

Switches

  • -z - Bytes copied from the source binary variable gets zero-filled after the copy
  • -c - Truncates the destination variable to remove bytes following the bytes copied. Where both N and M are positive, the new destination length is <des_pos> + <numBytes> -1

Parameters

  • <&dest_binvar> - The destination binary variable.
  • <des_pos> - The position to which to copy the byte to (or -1 to append to destination).
  • <&src_binvar> - The source binary variable.
  • <src_pos> - The position from which to start copying bytes.
  • <numBytes> - Number of bytes to copy beginning at <src pos> (or -1 for everything).

Example

Alias Example {
  ; Create a binary variable 'example' and assign it some text
  bset -t &example 1 This is a cool test!
 
  ; Copy from 'example' from the 11th byte 10 bytes onward
  ; Zero-fill the part that was copied
  bcopy -z &example2 1 &example 11 10
 
  ; Print out &example's content (up to the first null)
  echo -a $bvar(&example, 1-).text
 
  ; Print out &example2's content
  echo -a $bvar(&example2, 1-).text 
}

The above example will output:

This is a
cool test!
;while these variables exist:
//bset &to 1 11 22 33 44 55 66 | bset &from 1 77 88 99 123
and &to contains "11 22 33 44 55 66" and &to contains "77 88 99 123"
each of the following commands are based on the above values and are not executed after any of the other alternatives...
 
bcopy &to 2 &from 1 3
; copies 3 bytes at offset 1 of &from to overwrite the 3 bytes at offset 2 of &to. Length remains 6
11 77 88 99 55 66
 
bcopy -z &to 2 &from 1 3
; same alteration of &to, but all byte positions in &from which were copied are changed to 0x00's. &from is now "0 0 0 123"
11 77 88 99 55 66
 
bcopy -c &to 2 &from 1 3
; adding the -c switch causes any destination bytes following the copied bytes to be removed, shortening &to to length 4
11 77 88 99
bcopy -c &to 2 &from 1 0
; does not generate an error, but does not truncate the destination because 0 bytes were copied
11 22 33 44 55 66
 
bcopy &to 2 &from 1 99
; M is larger than bytes available beginning at offset 1, so the 4 bytes are copied to destination positions 2-5 without affecting the destination's 6th byte.
11 77 88 99 0 66
 
bcopy &to -1 &from 1 -1
; Destination position -1 causes bytes to be appended. Using -1 as number of bytes to copy copies the entire &from string beginning at position 1.
11 22 33 44 55 66 77 88 99 123
 
bcopy -c &to 1 &to 2 999
; copies positions 2-6 to 1-5. Without the -c switch, the length would still be 6 with the 66 repeated.
22 33 44 55 66
 
bcopy &to -1 &to 1 999
; appends the 6 bytes, doubling the length to 12
11 22 33 44 55 66 11 22 33 44 55 66
 
bcopy -c &to 2 &to 1 999
; places the old contents of positions 1-6 into positions 2-7. The bytes are not update after each byte, so does not cause 11 to be replicated in each position.
11 11 22 33 44 55 66
 
bcopy -c &to 3 &to 3 1
; truncates a variable to length 3

Compatibility

Added: mIRC v5.7
Added on: 02 Feb 2000
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See also


[Expand]
v · d · e mIRC commands list