aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-04-08 16:36:39 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-04-08 18:35:10 +0300
commit8b0fe501e77a1f4032a396b97ad317f09e160ee3 (patch)
tree54b59aa6fb696d12e2eaac711fe35246627bf0a4
parentc66eacd1d56cebce6986217bf6ea321018323952 (diff)
Add support for manifest serializing long lines mode
-rw-r--r--libbutl/manifest-serializer.bash.in26
-rw-r--r--libbutl/manifest.cxx27
-rw-r--r--tests/manifest-serializer/driver.in4
-rw-r--r--tests/manifest-serializer/testscript55
4 files changed, 99 insertions, 13 deletions
diff --git a/libbutl/manifest-serializer.bash.in b/libbutl/manifest-serializer.bash.in
index b1220e1..06770ba 100644
--- a/libbutl/manifest-serializer.bash.in
+++ b/libbutl/manifest-serializer.bash.in
@@ -11,13 +11,13 @@ fi
@import libbutl/utility@
# Serialize the manifest reading the binary representation from stdin and
-# writing to stdout.
+# writing to stdout. Unless --long-lines is specified, break lines in values.
#
# Normally you would use the start/finish functions below.
#
-function butl_serialize_manifest ()
+function butl_serialize_manifest () # [--long-lines]
{
- "$(butl_path)/manifest" serialize
+ "$(butl_path)/manifest" "$@" serialize
}
# Start the manifest serialization co-process setting the following "return"
@@ -27,7 +27,8 @@ function butl_serialize_manifest ()
# butl_manifest_serializer_ofd
# butl_manifest_serializer_pid
#
-# If <file> is not specified, then write to stdout.
+# If <file> is not specified, then write to stdout. Unless --long-lines is
+# specified, break lines in values.
#
# The typical usage:
#
@@ -41,8 +42,21 @@ function butl_serialize_manifest ()
#
# butl_manifest_serializer_finish
#
-function butl_manifest_serializer_start () # [<file>]
+function butl_manifest_serializer_start () # [--long-lines] [<file>]
{
+ local ops=()
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --long-lines)
+ ops+=("$1")
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+
if [ "$#" -gt 0 ]; then
exec {butl_manifest_serializer_ofd}>"$1"
else
@@ -51,7 +65,7 @@ function butl_manifest_serializer_start () # [<file>]
# See notes in butl_manifest_parser_start() on bash co-process issues.
#
- coproc { butl_serialize_manifest; } >&"$butl_manifest_serializer_ofd"
+ coproc { butl_serialize_manifest "${ops[@]}"; } >&"$butl_manifest_serializer_ofd"
butl_manifest_serializer_ifd="${COPROC[1]}"
butl_manifest_serializer_pid="$COPROC_PID"
}
diff --git a/libbutl/manifest.cxx b/libbutl/manifest.cxx
index d095c45..b3811a5 100644
--- a/libbutl/manifest.cxx
+++ b/libbutl/manifest.cxx
@@ -81,7 +81,7 @@ cmd_parse ()
}
static int
-cmd_serialize ()
+cmd_serialize (bool long_lines)
{
using serializer = manifest_serializer;
using serialization = manifest_serialization;
@@ -97,7 +97,7 @@ cmd_serialize ()
cout.exceptions (ios::badbit | ios::failbit);
- serializer s (cout, "stdout");
+ serializer s (cout, "stdout", long_lines);
for (string l; !eof (getline (cin, l, '\0')); )
{
@@ -132,21 +132,38 @@ cmd_serialize ()
return 0;
}
+// Usages:
+//
+// argv[0] parse
+// argv[0] [--long-lines] serialize
+//
int
main (int argc, char* argv[])
{
// We should switch to CLI if we need anything more elaborate.
//
- if (argc < 2)
+ int i (1);
+ bool long_lines (false);
+ for (; i != argc; ++i)
+ {
+ string op (argv[i]);
+
+ if (op == "--long-lines")
+ long_lines = true;
+ else
+ break;
+ }
+
+ if (i == argc)
{
cerr << "error: missing command" << endl;
return 1;
}
- string c (argv[1]);
+ string c (argv[i]);
if (c == "parse") return cmd_parse ();
- if (c == "serialize") return cmd_serialize ();
+ if (c == "serialize") return cmd_serialize (long_lines);
cerr << "error: unknown command '" << c << "'" << endl;
return 1;
diff --git a/tests/manifest-serializer/driver.in b/tests/manifest-serializer/driver.in
index 7c4efad..2703d03 100644
--- a/tests/manifest-serializer/driver.in
+++ b/tests/manifest-serializer/driver.in
@@ -23,9 +23,9 @@ while read -r n; do
break
else
if [ "$f" ]; then
- f=
+ f=
else
- printf "\n" >&"$fd"
+ printf "\n" >&"$fd"
fi
printf "%s" "$v" >&"$fd"
fi
diff --git a/tests/manifest-serializer/testscript b/tests/manifest-serializer/testscript
index d027b7a..c3da2c3 100644
--- a/tests/manifest-serializer/testscript
+++ b/tests/manifest-serializer/testscript
@@ -3,6 +3,7 @@
# license : MIT; see accompanying LICENSE file
: stdout
+:
{
$* <<EOI >>EOO
@@ -38,6 +39,7 @@
}
: file
+:
{
$* <<EOI >=file;
@@ -58,6 +60,7 @@
}
: list
+:
{
$* <<EOI >>EOO
@@ -79,6 +82,58 @@
EOO
}
+: break-lines
+:
+{
+ $* <<EOI >>EOO
+
+ 1
+
+ name
+ foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
+ EOI
+ : 1
+ name: foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\
+ oooo
+ EOO
+}
+
+: long-lines
+:
+{
+ : file
+ :
+ {
+ $* --long-lines file <<EOI >=file;
+
+ 1
+
+ name
+ foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
+ EOI
+
+ cat file >>EOO
+ : 1
+ name: foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
+ EOO
+ }
+
+ : stdout
+ :
+ {
+ $* --long-lines <<EOI >>EOO
+
+ 1
+
+ name
+ foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
+ EOI
+ : 1
+ name: foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
+ EOO
+ }
+}
+
: version
:
{