Difference between revisions of "Bcopy"

From Scriptwiki
Jump to: navigation, search
m
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
The bcopy command is used to copy a (part of a) [[:Category:Binary Files|binary file]].
 
The bcopy command is used to copy a (part of a) [[:Category:Binary Files|binary file]].
 
  <nowiki>bcopy [-zc] <&copy> <N> <&source> <S> <M></nowiki>
 
  <nowiki>bcopy [-zc] <&copy> <N> <&source> <S> <M></nowiki>
This copies M bytes from &source starting at position S to &copy starting at position N.
+
This copies ''M'' bytes from ''&source'' starting at position ''S'' to ''&copy'' starting at position ''N''.
If &copy doesn't exist yet, the binary file will be created and zero filled to the Nth byte. If &copy already exists but smaller then N bytes, it will be extended with zeros to the Nth byte. If &copy already exists and is N bytes or larger, the copied bytes will overwrite the old bytes in &copy.
+
If ''&copy'' doesn't exist yet, the binary file will be created and zero filled to the ''N''th byte. If ''&copy'' already exists but smaller then ''N'' bytes, it will be extended with zeros to the ''N''th byte. If ''&copy'' already exists and is ''N'' bytes or larger, the copied bytes will overwrite the old bytes in ''&copy''.
If &source is smaller then S + M - 1 bytes and &source is equal or larger then S bytes, then all bytes starting from S to the last byte will be copied. If &source is smaller then S bytes, you will get an error.
+
If ''&source'' is smaller then ''S'' + ''M'' - 1 bytes and ''&source'' is equal or larger then ''S'' bytes, then all bytes starting from ''S'' to the last byte will be copied. If ''&source'' is smaller then ''S'' bytes, you will get an error.
You can use M = -1 to copy all bytes starting from byte S to the last byte.
+
You can use ''M'' = -1 to copy all bytes starting from byte ''S'' to the last byte.
  
The -z switch will zero fill all bytes in &source that were copied.
+
The ''-z'' switch will zero fill all bytes in ''&source'' that were copied.
The -c switch will chop &copy to N + M bytes.
+
 
 +
The ''-c'' switch will chop ''&copy'' to ''N'' + ''M'' bytes.
  
 
== Examples ==
 
== Examples ==
 
  [[bset]] &data 1 65 66 67 68 69
 
  [[bset]] &data 1 65 66 67 68 69
 
  bcopy &test 1 &data 3 2
 
  bcopy &test 1 &data 3 2
  [[echo]] -a [[$bvar]](&test,1,$bvar(&test,0))
+
  [[echo]] -a [[$bvar]](&test,1,$bvar(&test,0)) returns ''67 68''
''67 68''
 
 
This will copy the values 67 68 from &data to the first position of &test.
 
This will copy the values 67 68 from &data to the first position of &test.
  
Line 19: Line 19:
 
  bset &test 1 97
 
  bset &test 1 97
 
  bcopy &test 5 &data 4 -1
 
  bcopy &test 5 &data 4 -1
  echo -a $bvar(&test,1,$bvar(&test,0))
+
  echo -a $bvar(&test,1,$bvar(&test,0)) returns ''97 0 0 0 68 69''
''97 0 0 0 68 69''
 
 
This will copy values 68 69 from &data to the fifth postion of &test. Positions 2-4 of &test will be zero filled.
 
This will copy values 68 69 from &data to the fifth postion of &test. Positions 2-4 of &test will be zero filled.
  
Line 26: Line 25:
 
  bset &test 1 97 98 99 100
 
  bset &test 1 97 98 99 100
 
  bcopy -z &test 2 &data 3 2
 
  bcopy -z &test 2 &data 3 2
  echo -a $bvar(&data,1,$bvar(&data,0))
+
  echo -a $bvar(&data,1,$bvar(&data,0)) returns ''65 66 0 0 69''
''65 66 0 0 69''
+
  echo -a $bvar(&test,1,$bvar(&test,0)) returns ''97 67 68 100''
  echo -a $bvar(&test,1,$bvar(&test,0))
 
''97 67 68 100''
 
 
This will copy values 67 68 from &data to the second position of &test. The -z switch will replace the copied values 67 68 of &data to zeros. Notice that values 98 99 will be overwritten.
 
This will copy values 67 68 from &data to the second position of &test. The -z switch will replace the copied values 67 68 of &data to zeros. Notice that values 98 99 will be overwritten.
  
Line 35: Line 32:
 
  bset &test 1 97 98 99 100
 
  bset &test 1 97 98 99 100
 
  bcopy -c &test 2 &data 3 2
 
  bcopy -c &test 2 &data 3 2
  echo -a $bvar(&test,1,$bvar(&test,0))
+
  echo -a $bvar(&test,1,$bvar(&test,0)) returns ''97 67 68''
''97 67 68''
 
 
This will copy values 67 68 from &data to the second position of &test. The -c switch will chop value 100.
 
This will copy values 67 68 from &data to the second position of &test. The -c switch will chop value 100.
 +
 +
[[Category:Binary Files]]
 +
[[Category:Commands]]

Latest revision as of 19:55, 13 October 2006

The bcopy command is used to copy a (part of a) binary file.

bcopy [-zc] <&copy> <N> <&source> <S> <M>

This copies M bytes from &source starting at position S to &copy starting at position N. If &copy doesn't exist yet, the binary file will be created and zero filled to the Nth byte. If &copy already exists but smaller then N bytes, it will be extended with zeros to the Nth byte. If &copy already exists and is N bytes or larger, the copied bytes will overwrite the old bytes in &copy. If &source is smaller then S + M - 1 bytes and &source is equal or larger then S bytes, then all bytes starting from S to the last byte will be copied. If &source is smaller then S bytes, you will get an error. You can use M = -1 to copy all bytes starting from byte S to the last byte.

The -z switch will zero fill all bytes in &source that were copied.

The -c switch will chop &copy to N + M bytes.

Examples

bset &data 1 65 66 67 68 69
bcopy &test 1 &data 3 2
echo -a $bvar(&test,1,$bvar(&test,0)) returns 67 68

This will copy the values 67 68 from &data to the first position of &test.

bset &data 1 65 66 67 68 69
bset &test 1 97
bcopy &test 5 &data 4 -1
echo -a $bvar(&test,1,$bvar(&test,0)) returns 97 0 0 0 68 69

This will copy values 68 69 from &data to the fifth postion of &test. Positions 2-4 of &test will be zero filled.

bset &data 1 65 66 67 68 69
bset &test 1 97 98 99 100
bcopy -z &test 2 &data 3 2
echo -a $bvar(&data,1,$bvar(&data,0)) returns 65 66 0 0 69
echo -a $bvar(&test,1,$bvar(&test,0)) returns 97 67 68 100

This will copy values 67 68 from &data to the second position of &test. The -z switch will replace the copied values 67 68 of &data to zeros. Notice that values 98 99 will be overwritten.

bset &data 1 65 66 67 68 69
bset &test 1 97 98 99 100
bcopy -c &test 2 &data 3 2
echo -a $bvar(&test,1,$bvar(&test,0)) returns 97 67 68

This will copy values 67 68 from &data to the second position of &test. The -c switch will chop value 100.