summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Savinen <tjsa@iki.fi>2005-11-15 18:53:17 +0000
committerHadrien Dorio <hadrien.dorio@gmail.com>2017-12-16 00:24:06 +0100
commitdcefa7a144fb35b23d1ca339d58f3b9e58e7faa3 (patch)
tree733c9942e36b0c7ecaf7597036806d7f1d2a536a
parent63ae206f2970076a9d09e90d7fbcb17ec1fa26e4 (diff)
downloadbinary-block-editor-dcefa7a144fb35b23d1ca339d58f3b9e58e7faa3.tar.gz
binary-block-editor-dcefa7a144fb35b23d1ca339d58f3b9e58e7faa3.zip
0.1.8
-rw-r--r--ChangeLog6
-rwxr-xr-xconfigure20
-rw-r--r--configure.ac2
-rw-r--r--doc/bbe.130
-rw-r--r--doc/bbe.html35
-rw-r--r--doc/bbe.info63
-rw-r--r--doc/bbe.texi43
-rw-r--r--src/bbe.c25
-rw-r--r--src/bbe.h10
-rw-r--r--src/buffer.c44
-rw-r--r--src/execute.c83
11 files changed, 231 insertions, 130 deletions
diff --git a/ChangeLog b/ChangeLog
index 626d962..a6f2b47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-11-15 Timo Savinen <tjsa@iki.fi>
+
+ * Version 0.1.8
+ * block commands < and > added
+ * block initialize commands u and f added
+
2005-11-08 Timo Savinen <tjsa@iki.fi>
* Version 0.1.7
diff --git a/configure b/configure
index 9119616..26f245d 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.59 for bbe 0.1.7.
+# Generated by GNU Autoconf 2.59 for bbe 0.1.8.
#
# Report bugs to <tjsa@iki.fi>.
#
@@ -269,8 +269,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='bbe'
PACKAGE_TARNAME='bbe'
-PACKAGE_VERSION='0.1.7'
-PACKAGE_STRING='bbe 0.1.7'
+PACKAGE_VERSION='0.1.8'
+PACKAGE_STRING='bbe 0.1.8'
PACKAGE_BUGREPORT='tjsa@iki.fi'
ac_unique_file="src/bbe.c"
@@ -780,7 +780,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures bbe 0.1.7 to adapt to many kinds of systems.
+\`configure' configures bbe 0.1.8 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -846,7 +846,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of bbe 0.1.7:";;
+ short | recursive ) echo "Configuration of bbe 0.1.8:";;
esac
cat <<\_ACEOF
@@ -965,7 +965,7 @@ fi
test -n "$ac_init_help" && exit 0
if $ac_init_version; then
cat <<\_ACEOF
-bbe configure 0.1.7
+bbe configure 0.1.8
generated by GNU Autoconf 2.59
Copyright (C) 2003 Free Software Foundation, Inc.
@@ -979,7 +979,7 @@ cat >&5 <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by bbe $as_me 0.1.7, which was
+It was created by bbe $as_me 0.1.8, which was
generated by GNU Autoconf 2.59. Invocation command line was
$ $0 $@
@@ -1623,7 +1623,7 @@ fi
# Define the identity of the package.
PACKAGE='bbe'
- VERSION='0.1.7'
+ VERSION='0.1.8'
cat >>confdefs.h <<_ACEOF
@@ -4660,7 +4660,7 @@ _ASBOX
} >&5
cat >&5 <<_CSEOF
-This file was extended by bbe $as_me 0.1.7, which was
+This file was extended by bbe $as_me 0.1.8, which was
generated by GNU Autoconf 2.59. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -4723,7 +4723,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-bbe config.status 0.1.7
+bbe config.status 0.1.8
configured by $0, generated by GNU Autoconf 2.59,
with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
diff --git a/configure.ac b/configure.ac
index 886c6bd..6bf754f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
-AC_INIT(bbe, 0.1.7, tjsa@iki.fi)
+AC_INIT(bbe, 0.1.8, tjsa@iki.fi)
AC_CONFIG_SRCDIR(src/bbe.c)
AC_CONFIG_AUX_DIR(config)
AM_INIT_AUTOMAKE
diff --git a/doc/bbe.1 b/doc/bbe.1
index 64c67c0..2ce819c 100644
--- a/doc/bbe.1
+++ b/doc/bbe.1
@@ -25,7 +25,7 @@
.\" .br insert line break
.\" .sp <n> insert n+1 empty lines
.\" for manpage-specific macros, see man(7)
-.TH "BBE" "1" "2005-10-20" "" ""
+.TH "BBE" "1" "2005-11-13" "" ""
.SH "NAME"
bbe \- binary block editor
.SH "SYNOPSIS"
@@ -127,6 +127,12 @@ Before printing a block, the input stream offset at the begining of the block is
B \fIf\fR
Before printing a block, the block number is printed (first block == 1)
\fIf\fR can be H, D or O for Hexadecimal, Decimal or Octal format of block number.
+.TP
+> \fIfile\fR
+Before printing a block, the contents of file \fIfile\fR is printed.
+.TP
+< \fIfile\fR
+After printing a block, the contents of file \fIfile\fR is printed.
.LP
\fBByte commands\fR
.TP
@@ -170,21 +176,27 @@ w \fIfile\fR
Write bytes from the current block to file \fIfile\fR. Commands before w\-command have effect to what will be written. %B or %nB in \fIfile\fR will be replaced by current block number. n in %nB is field length,
leading zero in n causes the block number to be left padded with zeroes.
.TP
-& \fIbyte\fR
-Performs binary and with \fIbyte\fR.
+& \fIc\fR
+Performs binary and with \fIc\fR.
.TP
-| \fIbyte\fR
-Performs binary or with \fIbyte\fR.
+| \fIc\fR
+Performs binary or with \fIc\fR.
.TP
-^ \fIbyte\fR
-Performs binary xor with \fIbyte\fR.
+^ \fIc\fR
+Performs binary xor with \fIc\fR.
.TP
~
Performs binary negation.
+.TP
+u \fIn\fR \fIc\fR
+All bytes from start of the block to offset \fIn\fR are replaced by \fIc\fR.
+.TP
+f \fIn\fR \fIc\fR
+All bytes starting from offset \fIn\fR to end of the block are replaced by \fIc\fR.
.LP
Nonvisible characters in strings can be escaped same way as in block definition strings. Character '/' in s and y commands can be any visible character.
.LP
-Note that the D, A, I, F, B, c, s, i, y, p and d commands cause the length of input and output streams to be different.
+Note that the D, A, I, F, B, c, s, i, y, p, <, > and d commands cause the length of input and output streams to be different.
.SH "EXAMPLES"
.TP
@@ -203,4 +215,4 @@ Blocks between strings "\\x2f\\x34\\x6a" and "\\xff\\xff" are written to file /t
.BR sed (1).
.SH "AUTHOR"
-Timo Savinen <tjsa@iki.fi>.
+Timo Savinen <tjsa@iki.fi >
diff --git a/doc/bbe.html b/doc/bbe.html
index 0066ea9..1c3505f 100644
--- a/doc/bbe.html
+++ b/doc/bbe.html
@@ -7,7 +7,7 @@
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
-This file documents the `bbe' - binary block editor
+This file documents version 0.1.8 of `bbe', a binary block editor.
Copyright (C) 2005 Timo Savinen
@@ -48,7 +48,7 @@ Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>
<h2 class="unnumbered">bbe</h2>
-<p>This file documents the <span class="command">bbe</span> - binary block editor
+<p>This file documents version 0.1.8 of <span class="command">bbe</span>, a binary block editor.
<p>Copyright &copy; 2005 Timo Savinen
@@ -306,7 +306,11 @@ Stream offset starts at zero. <var>f</var> can have one of following values:
</dl>
<br><dt><code>B </code><var>f</var><dd>Before block contents the current block number and colon is printed in format specified by <var>f</var>.
-Block numbering starts at one. <var>f</var> can have one of the sames codes as <code>F</code>-command
+Block numbering starts at one. <var>f</var> can have one of the sames codes as <code>F</code>-command.
+
+ <br><dt><code>&gt; </code><span class="file">file</span><dd>Before printing a block, the contents of file <span class="file">file</span> is printed.
+
+ <br><dt><code>&lt; </code><span class="file">file</span><dd>After printing a block, the contents of file <span class="file">file</span> is printed.
</dl>
<h4 class="subheading">Byte commands are:</h4>
@@ -331,6 +335,10 @@ in range <code>'0'</code> &ndash; <code>'9'</code> are not converted.
<br><dt><code>l </code><var>n</var><dd>Commands appearing after <code>l</code>-command have no effect concerning bytes starting from the byte number <var>n</var> of the block.
+ <br><dt><code>u </code><var>n</var> <var>c</var><dd>All bytes from start of the block to offset <var>n</var> are replaced by <var>c</var>.
+
+ <br><dt><code>f </code><var>n</var> <var>c</var><dd>All bytes starting from offset <var>n</var> to the end of the block are replaced by <var>c</var>.
+
<br><dt><code>p </code><var>format</var><dd>Contents of block is printed in formats specified by <var>format</var>. <var>format</var> can contain following format codes:
<dl>
<dt><var>H</var><dd>Hexadecimal.
@@ -351,7 +359,8 @@ in range <code>'0'</code> &ndash; <code>'9'</code> are not converted.
<br><dt><code>s/</code><var>search</var><code>/</code><var>replace</var><code>/</code><dd>All occurences of <var>search</var> are replaced by <var>replace</var>. <var>replace</var> can be empty. Separator <code>/</code> can be replaced by any
character not present in <var>search</var> or <var>replace</var>.
- <br><dt><code>w </code><span class="file">file</span><dd>Contents of blocks are written to file <span class="file">file</span>. <strong>Note</strong>: Data inserted by commands <code>A</code> and <code>I</code>
+ <br><dt><code>w </code><span class="file">file</span><dd>Contents of blocks are written to file <span class="file">file</span>. <strong>Note</strong>: Data inserted by commands <code>A</code>, <code>I</code>,
+<code>&gt;</code> and <code>&lt;</code>
are written to file <span class="file">file</span> and <code>j</code> and <code>l</code> commands have no effect on <code>w</code>-commands. Zero size files are not preserved.<br>
Filename can contain format string <code>%B</code> or <code>%nB</code>, these format strings are replace by current block number (starting from one), causing every block to have it's own file.
In <code>%nB</code>, the <code>n</code> is field width in range 0-99. If <code>n</code> has a leading zero, then the block numbers will be left padded with zeroes.
@@ -359,11 +368,11 @@ In <code>%nB</code>, the <code>n</code> is field width in range 0-99. If <code>n
<br><dt><code>y/</code><var>source</var><code>/</code><var>dest</var><code>/</code><dd>Translate bytes in <var>source</var> to the corresponding bytes in <var>dest</var>. <var>source</var> and <var>dest</var> must have equal length.
Separator <code>/</code> can be replaced by any character not present in <var>source</var> or <var>dest</var>.
- <br><dt><code>&amp; c</code><dd>Performs binary and with <var>c</var> on block contents.
+ <br><dt><code>&amp; </code><var>c</var><dd>Performs binary and with <var>c</var> on block contents.
- <br><dt><code>| c</code><dd>Performs binary or with <var>c</var> on block contents.
+ <br><dt><code>| </code><var>c</var><dd>Performs binary or with <var>c</var> on block contents.
- <br><dt><code>^ c</code><dd>Performs exclusive or with <var>c</var> on block contents.
+ <br><dt><code>^ </code><var>c</var><dd>Performs exclusive or with <var>c</var> on block contents.
<br><dt><code>~</code><dd>Performs binary negation on block contents.
</dl>
@@ -385,10 +394,6 @@ systems are not tested.
<dl>
<dt><em>Strings in block definition</em><dt><em>Search string in </em><code>s</code><em> command</em><dd>are limited to <em>16384</em> bytes.
-<br>
-
- <br><dt><em>Total data to be inserted by </em><code>s</code><em> and </em><code>i</code><em> commands</em><dd>is <em>245760</em> bytes, that means the total data in command definitions, of course it can be inserted several times.
-<br>
</dl>
<div class="node">
@@ -411,13 +416,13 @@ and if the end of input stream is found before 128'th byte of the last block is
<li>Start of the block is searched. If found, data before block is written to output stream (unless <span class="option">-s</span> is defined) and
step 2 is executed.
- <li>Block commands affecting the start of the block (<code>I</code>, <code>D</code>, <code>J</code>, <code>N</code>, <code>F</code> and <code>B</code>) are executed.
+ <li>Block commands affecting the start of the block (<code>I</code>, <code>D</code>, <code>J</code>, <code>N</code>, <code>F</code>, <code>&gt;</code> and <code>B</code>) are executed.
<li>The block is scanned byte by byte and all byte commands (lower case letters) are executed.
<strong>Note</strong>: Commands are executed on results of previous commands, if e.g. the first byte of the block is deleted,
the following commands don't 'see' the removed byte.
- <li>When end of the block is reached the end of the block commands (<code>A</code>) are executed.
+ <li>When end of the block is reached the end of the block commands (<code>A</code> and <code>&lt;</code>) are executed.
<li>Next block is searched, data between the blocks, if not suppressed with <span class="option">-s</span>, is written to output stream.
</ol>
@@ -486,7 +491,9 @@ The start sequence is not printed.<br>
<br><dt><span class="samp">bbe -b "/\xff\xd8\xff/:/\xff\xd9/" -s -e "w pic%02B.jpg" -o /dev/null manual.pdf</span><dd>Extract jpg-images from pdf-file to separate jpg-files (assuming that the jpg start/stop sequences
does not appear in other context than jpg-images).
-Files will be named as <span class="file">pic01.jpg</span>, <span class="file">pic02.jpg</span>, <span class="file">pic03.jpg</span>,<small class="dots">...</small>
+Files will be named as <span class="file">pic01.jpg</span>, <span class="file">pic02.jpg</span>, <span class="file">pic03.jpg</span>,<small class="dots">...</small> <br>
+
+ <br><dt><span class="samp">bbe -b "_&lt;body&gt;_:_&lt;/body&gt;_" -s -o temp nicebody.html</span><dt><span class="samp">bbe -b "_&lt;body&gt;_:_&lt;/body&gt;_" -e "D;&lt; temp" -o tmpindex.html index.html</span><dt><span class="samp">mv tmpindex.html index.html</span><dd>The body part of the html-document <span class="file">index.html</span> is replaced by the body of the document <span class="file">nicebody.html</span>.
</dl>
<div class="node">
diff --git a/doc/bbe.info b/doc/bbe.info
index 771d0c0..63cb3ba 100644
--- a/doc/bbe.info
+++ b/doc/bbe.info
@@ -1,6 +1,6 @@
This is bbe.info, produced by makeinfo version 4.7 from bbe.texi.
- This file documents the `bbe' - binary block editor
+ This file documents version 0.1.8 of `bbe', a binary block editor.
Copyright (C) 2005 Timo Savinen
@@ -23,7 +23,7 @@ File: bbe.info, Node: Top, Next: Overview, Prev: (dir), Up: (dir)
bbe
***
-This file documents the `bbe' - binary block editor
+This file documents version 0.1.8 of `bbe', a binary block editor.
Copyright (C) 2005 Timo Savinen
@@ -302,7 +302,13 @@ Block commands are:
`B F'
Before block contents the current block number and colon is
printed in format specified by F. Block numbering starts at one.
- F can have one of the sames codes as `F'-command
+ F can have one of the sames codes as `F'-command.
+
+`> `file''
+ Before printing a block, the contents of file `file' is printed.
+
+`< `file''
+ After printing a block, the contents of file `file' is printed.
Byte commands are:
------------------
@@ -335,6 +341,13 @@ block, first byte is number zero.
Commands appearing after `l'-command have no effect concerning
bytes starting from the byte number N of the block.
+`u N C'
+ All bytes from start of the block to offset N are replaced by C.
+
+`f N C'
+ All bytes starting from offset N to the end of the block are
+ replaced by C.
+
`p FORMAT'
Contents of block is printed in formats specified by FORMAT.
FORMAT can contain following format codes:
@@ -367,9 +380,9 @@ block, first byte is number zero.
`w `file''
Contents of blocks are written to file `file'. *Note*: Data
- inserted by commands `A' and `I' are written to file `file' and
- `j' and `l' commands have no effect on `w'-commands. Zero size
- files are not preserved.
+ inserted by commands `A', `I', `>' and `<' are written to file
+ `file' and `j' and `l' commands have no effect on `w'-commands.
+ Zero size files are not preserved.
Filename can contain format string `%B' or `%nB', these format
strings are replace by current block number (starting from one),
causing every block to have it's own file. In `%nB', the `n' is
@@ -381,13 +394,13 @@ block, first byte is number zero.
SOURCE and DEST must have equal length. Separator `/' can be
replaced by any character not present in SOURCE or DEST.
-`& c'
+`& C'
Performs binary and with C on block contents.
-`| c'
+`| C'
Performs binary or with C on block contents.
-`^ c'
+`^ C'
Performs exclusive or with C on block contents.
`~'
@@ -407,9 +420,6 @@ GB), other systems are not tested.
_Strings in block definition_
_Search string in `s' command_
are limited to _16384_ bytes.
-_Total data to be inserted by `s' and `i' commands_
- is _245760_ bytes, that means the total data in command
- definitions, of course it can be inserted several times.

File: bbe.info, Node: bbe programs, Next: Problems, Prev: Invoking bbe, Up: Top
@@ -432,7 +442,7 @@ Basic execution cycle:
executed.
2. Block commands affecting the start of the block (`I', `D', `J',
- `N', `F' and `B') are executed.
+ `N', `F', `>' and `B') are executed.
3. The block is scanned byte by byte and all byte commands (lower
case letters) are executed. *Note*: Commands are executed on
@@ -440,7 +450,7 @@ Basic execution cycle:
is deleted, the following commands don't 'see' the removed byte.
4. When end of the block is reached the end of the block commands
- (`A') are executed.
+ (`A' and `<') are executed.
5. Next block is searched, data between the blocks, if not suppressed
with `-s', is written to output stream.
@@ -510,6 +520,11 @@ Few examples:
that the jpg start/stop sequences does not appear in other context
than jpg-images). Files will be named as `pic01.jpg',
`pic02.jpg', `pic03.jpg',...
+`bbe -b "_<body>_:_</body>_" -s -o temp nicebody.html'
+`bbe -b "_<body>_:_</body>_" -e "D;< temp" -o tmpindex.html index.html'
+`mv tmpindex.html index.html'
+ The body part of the html-document `index.html' is replaced by the
+ body of the document `nicebody.html'.

File: bbe.info, Node: Problems, Prev: bbe programs, Up: Top
@@ -530,15 +545,15 @@ problems.

Tag Table:
-Node: Top766
-Node: Overview1811
-Node: Samples2298
-Node: Invoking bbe3696
-Node: Invocation4230
-Node: Block5242
-Node: Commands7288
-Node: Limits11616
-Node: bbe programs12169
-Node: Problems16270
+Node: Top781
+Node: Overview1841
+Node: Samples2328
+Node: Invoking bbe3726
+Node: Invocation4260
+Node: Block5272
+Node: Commands7318
+Node: Limits11994
+Node: bbe programs12372
+Node: Problems16758

End Tag Table
diff --git a/doc/bbe.texi b/doc/bbe.texi
index a56d989..5e8ade6 100644
--- a/doc/bbe.texi
+++ b/doc/bbe.texi
@@ -6,10 +6,10 @@
@finalout
@c %**end of header
-@set VERSION 0.1.7
+@set VERSION 0.1.8
@copying
-This file documents the @command{bbe} - binary block editor
+This file documents version @value{VERSION} of @command{bbe}, a binary block editor.
Copyright @copyright{} 2005 Timo Savinen
@@ -308,7 +308,13 @@ Octal.
@item B @var{f}
Before block contents the current block number and colon is printed in format specified by @var{f}.
-Block numbering starts at one. @var{f} can have one of the sames codes as @code{F}-command
+Block numbering starts at one. @var{f} can have one of the sames codes as @code{F}-command.
+
+@item > @file{file}
+Before printing a block, the contents of file @file{file} is printed.
+
+@item < @file{file}
+After printing a block, the contents of file @file{file} is printed.
@end table
@subheading Byte commands are:
@@ -340,6 +346,12 @@ Commands appearing after @code{j}-command have no effect concerning bytes 0-@var
@item l @var{n}
Commands appearing after @code{l}-command have no effect concerning bytes starting from the byte number @var{n} of the block.
+@item u @var{n} @var{c}
+All bytes from start of the block to offset @var{n} are replaced by @var{c}.
+
+@item f @var{n} @var{c}
+All bytes starting from offset @var{n} to the end of the block are replaced by @var{c}.
+
@item p @var{format}
Contents of block is printed in formats specified by @var{format}. @var{format} can contain following format codes:
@table @var
@@ -369,7 +381,8 @@ All occurences of @var{search} are replaced by @var{replace}. @var{replace} can
character not present in @var{search} or @var{replace}.
@item w @file{file}
-Contents of blocks are written to file @file{file}. @strong{Note}: Data inserted by commands @code{A} and @code{I}
+Contents of blocks are written to file @file{file}. @strong{Note}: Data inserted by commands @code{A}, @code{I},
+@code{>} and @code{<}
are written to file @file{file} and @code{j} and @code{l} commands have no effect on @code{w}-commands. Zero size files are not preserved.@*
Filename can contain format string @code{%B} or @code{%nB}, these format strings are replace by current block number (starting from one), causing every block to have it's own file.
In @code{%nB}, the @code{n} is field width in range 0-99. If @code{n} has a leading zero, then the block numbers will be left padded with zeroes.
@@ -379,13 +392,13 @@ In @code{%nB}, the @code{n} is field width in range 0-99. If @code{n} has a lead
Translate bytes in @var{source} to the corresponding bytes in @var{dest}. @var{source} and @var{dest} must have equal length.
Separator @code{/} can be replaced by any character not present in @var{source} or @var{dest}.
-@item & c
+@item & @var{c}
Performs binary and with @var{c} on block contents.
-@item | c
+@item | @var{c}
Performs binary or with @var{c} on block contents.
-@item ^ c
+@item ^ @var{c}
Performs exclusive or with @var{c} on block contents.
@item ~
@@ -406,11 +419,6 @@ There are however, some limitations in block and command definitions:
@item Strings in block definition
@itemx Search string in @code{s} command
are limited to @emph{16384} bytes.
-@*
-
-@item Total data to be inserted by @code{s} and @code{i} commands
-is @emph{245760} bytes, that means the total data in command definitions, of course it can be inserted several times.
-@*
@end table
@@ -429,7 +437,7 @@ Start of the block is searched. If found, data before block is written to output
step 2 is executed.
@item
-Block commands affecting the start of the block (@code{I}, @code{D}, @code{J}, @code{N}, @code{F} and @code{B}) are executed.
+Block commands affecting the start of the block (@code{I}, @code{D}, @code{J}, @code{N}, @code{F}, @code{>} and @code{B}) are executed.
@item
The block is scanned byte by byte and all byte commands (lower case letters) are executed.
@@ -437,7 +445,7 @@ The block is scanned byte by byte and all byte commands (lower case letters) are
the following commands don't 'see' the removed byte.
@item
-When end of the block is reached the end of the block commands (@code{A}) are executed.
+When end of the block is reached the end of the block commands (@code{A} and @code{<}) are executed.
@item
Next block is searched, data between the blocks, if not suppressed with @option{-s}, is written to output stream.
@@ -525,7 +533,12 @@ The least significant nybble of bytes after @code{x5f} is cleared.@*
@item bbe -b "/\xff\xd8\xff/:/\xff\xd9/" -s -e "w pic%02B.jpg" -o /dev/null manual.pdf
Extract jpg-images from pdf-file to separate jpg-files (assuming that the jpg start/stop sequences
does not appear in other context than jpg-images).
-Files will be named as @file{pic01.jpg}, @file{pic02.jpg}, @file{pic03.jpg},@dots{}
+Files will be named as @file{pic01.jpg}, @file{pic02.jpg}, @file{pic03.jpg},@dots{} @*
+
+@item bbe -b "_<body>_:_</body>_" -s -o temp nicebody.html
+@itemx bbe -b "_<body>_:_</body>_" -e "D;< temp" -o tmpindex.html index.html
+@itemx mv tmpindex.html index.html
+The body part of the html-document @file{index.html} is replaced by the body of the document @file{nicebody.html}.
@end table
diff --git a/src/bbe.c b/src/bbe.c
index 5ba73f3..e0e10da 100644
--- a/src/bbe.c
+++ b/src/bbe.c
@@ -20,7 +20,7 @@
*
*/
-/* $Id: bbe.c,v 1.40 2005/11/01 19:01:16 timo Exp $ */
+/* $Id: bbe.c,v 1.42 2005/11/15 13:59:15 timo Exp $ */
#include "bbe.h"
#ifdef HAVE_GETOPT_H
@@ -72,13 +72,13 @@ char *convert_strings[] = {
"",
};
/* commands to be executed at start of buffer */
-#define BLOCK_START_COMMANDS "DIJLFBN"
+#define BLOCK_START_COMMANDS "DIJLFBN>"
/* commands to be executed for each byte */
-#define BYTE_COMMANDS "acdirsywjpl&|^~"
+#define BYTE_COMMANDS "acdirsywjpl&|^~uf"
/* commands to be executed at end of buffer */
-#define BLOCK_END_COMMANDS "A"
+#define BLOCK_END_COMMANDS "A<"
/* format types for p command */
char *p_formats="DOHAB";
@@ -149,7 +149,7 @@ parse_long(char *long_int)
if(!isdigit(*scan)) panic("Error in number",long_int,NULL);
break;
case 'o':
- if(!isdigit(*scan) || *scan > '8') panic("Error in number",long_int,NULL);
+ if(!isdigit(*scan) || *scan >= '8') panic("Error in number",long_int,NULL);
break;
case 'x':
if(!isxdigit(*scan)) panic("Error in number",long_int,NULL);
@@ -226,7 +226,7 @@ parse_string(char *string,off_t *length)
min_len=3;
break;
case '0':
- while(isdigit(*p) && *p <= '8' && j < 4) num[j++] = *p++;
+ while(isdigit(*p) && *p < '8' && j < 4) num[j++] = *p++;
min_len=1;
break;
default:
@@ -301,7 +301,7 @@ parse_block(char *bs)
while(isxdigit(*p)) buf[i++] = *p++;
break;
case '0':
- while(isdigit(*p) && *p <= '8') buf[i++] = *p++;
+ while(isdigit(*p) && *p < '8') buf[i++] = *p++;
break;
default:
while(isdigit(*p)) buf[i++] = *p++;
@@ -348,7 +348,7 @@ parse_block(char *bs)
while(isxdigit(*p)) buf[i++] = *p++;
break;
case '0':
- while(isdigit(*p) && *p <= '8') buf[i++] = *p++;
+ while(isdigit(*p) && *p < '8') buf[i++] = *p++;
break;
default:
while(isdigit(*p)) buf[i++] = *p++;
@@ -466,6 +466,8 @@ parse_command(char *command_string)
new->s1 = parse_string(token[1],&new->s1_len);
break;
case 'w':
+ case '<':
+ case '>':
if(i != 2 || strlen(token[0]) > 1) panic("Error in command",command_string,NULL);
new->s1 = xstrdup(token[1]);
break;
@@ -568,6 +570,13 @@ parse_command(char *command_string)
case '~':
if(i != 1 || strlen(token[0]) > 1) panic("Error in command",command_string,NULL);
break;
+ case 'u':
+ case 'f':
+ if(i != 3 || strlen(token[0]) > 1) panic("Error in command",command_string,NULL);
+ new->offset = parse_long(token[1]);
+ new->s1 = parse_string(token[2],&new->s1_len);
+ if(new->s1_len != 1) panic("Error in command",command_string,NULL);
+ break;
default:
panic("Unknown command",command_string,NULL);
break;
diff --git a/src/bbe.h b/src/bbe.h
index cf00c6b..e0dc3e4 100644
--- a/src/bbe.h
+++ b/src/bbe.h
@@ -20,7 +20,7 @@
*
*/
-/* $Id: bbe.h,v 1.27 2005/10/27 16:37:14 timo Exp $ */
+/* $Id: bbe.h,v 1.28 2005/11/11 13:06:53 timo Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -146,8 +146,6 @@ struct output_buffer {
unsigned char *end;
unsigned char *write_pos; // current write psotion;
unsigned char *low_pos; // low water mark
- unsigned char *cycle_start; // at this position started the last command cycle
- // (written bytes n curren cycle are between cycle_start and write_pos
off_t block_offset; // block offset (start = 0) number of bytes written at position write_pos
};
@@ -202,9 +200,6 @@ init_commands(struct commands *c);
extern void
close_commands(struct commands *c);
-extern inline void
-set_cycle_start();
-
extern void
close_output_stream();
@@ -215,9 +210,6 @@ extern void
execute_program(struct commands *c);
extern void
-reverse_bytes(size_t count);
-
-extern void
write_string(char *string);
extern char *
diff --git a/src/buffer.c b/src/buffer.c
index 9566e08..c546d5c 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -20,7 +20,7 @@
*
*/
-/* $Id: buffer.c,v 1.33 2005/10/19 18:39:13 timo Exp $ */
+/* $Id: buffer.c,v 1.35 2005/11/14 10:40:47 timo Exp $ */
#include "bbe.h"
#include <stdlib.h>
@@ -465,20 +465,13 @@ write_string(char *string)
void
write_buffer(unsigned char *buf,off_t length)
{
- unsigned char *save_pos;
if(!length) return;
- if(length > (off_t) (OUTPUT_BUFFER_SIZE - (out_buffer.write_pos - out_buffer.buffer)))
+ if(out_buffer.write_pos + length >= out_buffer.end)
{
- save_pos = out_buffer.cycle_start < out_buffer.low_pos ? out_buffer.cycle_start : out_buffer.low_pos;
- if(save_pos == out_buffer.buffer)
- panic("Write buffer too small",NULL,NULL);
- write_output_stream(out_buffer.buffer,save_pos - out_buffer.buffer);
- write_w_command(out_buffer.buffer,save_pos - out_buffer.buffer);
- memmove(out_buffer.buffer,save_pos,out_buffer.write_pos - save_pos);
- out_buffer.write_pos = out_buffer.buffer + (out_buffer.write_pos - save_pos);
- out_buffer.cycle_start = out_buffer.buffer + (out_buffer.cycle_start - save_pos);
+ if(out_buffer.write_pos == out_buffer.buffer) panic("Out buffer too small, should not happen!",NULL,NULL);
+ flush_buffer();
}
memcpy(out_buffer.write_pos,buf,length);
out_buffer.write_pos += length;
@@ -497,39 +490,14 @@ put_byte(unsigned char byte)
inline void
write_next_byte()
{
- unsigned char *save_pos;
-
out_buffer.write_pos++;
out_buffer.block_offset++;
- if(out_buffer.write_pos > out_buffer.end)
+ if(out_buffer.write_pos >= out_buffer.end)
{
- save_pos = out_buffer.cycle_start < out_buffer.low_pos ? out_buffer.cycle_start : out_buffer.low_pos;
- if(save_pos == out_buffer.buffer)
- panic("Write buffer too small",NULL,NULL);
- write_output_stream(out_buffer.buffer,save_pos - out_buffer.buffer);
- write_w_command(out_buffer.buffer,save_pos - out_buffer.buffer);
- memmove(out_buffer.buffer,save_pos,out_buffer.write_pos - save_pos);
- out_buffer.write_pos = out_buffer.buffer + (out_buffer.write_pos - save_pos);
- out_buffer.cycle_start = out_buffer.buffer + (out_buffer.cycle_start - save_pos);
+ flush_buffer();
}
}
-/* reverse_bytes, reverse the write position (for replace etc.) */
-inline void
-reverse_bytes(size_t count)
-{
- out_buffer.write_pos -= count;
- out_buffer.block_offset -= count;
- if(out_buffer.write_pos < out_buffer.buffer) panic("Too many bytes reversed, should not happen",NULL,NULL);
-}
-
-/* set editing cycle start position */
-inline void
-set_cycle_start()
-{
- out_buffer.cycle_start = out_buffer.write_pos;
-}
-
/* write unwritten data from buffer to disk */
void
flush_buffer()
diff --git a/src/execute.c b/src/execute.c
index 53ac02b..bfc3b29 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -20,7 +20,7 @@
*
*/
-/* $Id: execute.c,v 1.33 2005/11/01 19:01:16 timo Exp $ */
+/* $Id: execute.c,v 1.37 2005/11/15 13:59:15 timo Exp $ */
#include "bbe.h"
#include <stdlib.h>
@@ -118,6 +118,7 @@ off_t_to_string(off_t number,char format)
+#define IO_BLOCK_SIZE (8 * 1024)
/* execute given commands */
void
@@ -127,8 +128,11 @@ execute_commands(struct command_list *c)
unsigned char a,b;
unsigned char *p;
char *str;
+ off_t read_count;
+ static unsigned char ioblock[IO_BLOCK_SIZE];
if(skip_this_block) return;
+
while(c != NULL)
{
switch(c->letter)
@@ -411,6 +415,27 @@ execute_commands(struct command_list *c)
case '~':
put_byte(~*out_buffer.write_pos);
break;
+ case '<':
+ case '>':
+ if (fseeko(c->fd,0,SEEK_SET)) panic("Cannot seek file",c->s1,strerror(errno));
+ do
+ {
+ read_count = fread(ioblock,1,IO_BLOCK_SIZE,c->fd);
+ write_buffer(ioblock,read_count);
+ } while(read_count);
+ break;
+ case 'u':
+ if(in_buffer.block_offset <= c->offset)
+ {
+ put_byte(c->s1[0]);
+ }
+ break;
+ case 'f':
+ if(in_buffer.block_offset >= c->offset)
+ {
+ put_byte(c->s1[0]);
+ }
+ break;
case 'w':
break;
}
@@ -563,6 +588,35 @@ init_commands(struct commands *commands)
}
c = c->next;
}
+
+ c = commands->block_start;
+
+ while(c != NULL)
+ {
+ switch(c->letter)
+ {
+ case '>':
+ c->fd = fopen(c->s1,"r");
+ if(c->fd == NULL) panic("Cannot open file for reading",c->s1,strerror(errno));
+ break;
+ }
+ c = c->next;
+ }
+
+ c = commands->block_end;
+
+ while(c != NULL)
+ {
+ switch(c->letter)
+ {
+ case '<':
+ c->fd = fopen(c->s1,"r");
+ if(c->fd == NULL) panic("Cannot open file for reading",c->s1,strerror(errno));
+ break;
+ }
+ c = c->next;
+ }
+
}
@@ -591,6 +645,32 @@ close_commands(struct commands *commands)
}
c = c->next;
}
+
+ c = commands->block_start;
+
+ while(c != NULL)
+ {
+ switch(c->letter)
+ {
+ case '>':
+ fclose(c->fd);
+ break;
+ }
+ c = c->next;
+ }
+
+ c = commands->block_end;
+
+ while(c != NULL)
+ {
+ switch(c->letter)
+ {
+ case '<':
+ fclose(c->fd);
+ break;
+ }
+ c = c->next;
+ }
}
/* reset the rpos counter for next block, in case block was shorter eg. delete count */
@@ -625,7 +705,6 @@ execute_program(struct commands *commands)
execute_commands(commands->block_start);
do
{
- set_cycle_start();
delete_this_byte = 0;
inserting = 0;
block_end = last_byte();
OpenPOWER on IntegriCloud