From: Niels Möller Date: Wed, 27 Aug 2008 08:51:22 +0000 (+0200) Subject: (sexp_convert_item): Keep comments in advanced X-Git-Tag: nettle_2.0_release_20090608~85 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f24a9915e1233df8730fe943ff9e7d76d8d982e;p=thirdparty%2Fnettle.git (sexp_convert_item): Keep comments in advanced output. (parse_options): New --lock option. (main): Optionally lock output file. Rev: nettle/tools/sexp-conv.c:1.2 --- diff --git a/tools/sexp-conv.c b/tools/sexp-conv.c index 58487833..e156877c 100644 --- a/tools/sexp-conv.c +++ b/tools/sexp-conv.c @@ -33,6 +33,16 @@ #include #include +#if HAVE_FCNTL_LOCKING +# if HAVE_SYS_TYPES_H +# include +# endif +# if HAVE_UNISTD_H +# include +# endif +# include +#endif + #include "buffer.h" #include "nettle-meta.h" @@ -127,6 +137,15 @@ sexp_convert_item(struct sexp_parser *parser, sexp_put_string(output, mode_out, &token->string); break; + case SEXP_COMMENT: + if (mode_out == SEXP_ADVANCED) + { + sexp_put_data(output, token->string.size, token->string.contents); + /* This newline is necessary only if the comment comes first + in a list. It would be nice to supress extra newlines. */ + sexp_put_newline(output, indent); + } + break; default: /* Internal error */ abort(); @@ -181,11 +200,12 @@ struct conv_options enum sexp_mode mode; int prefer_hex; int once; + int lock; unsigned width; const struct nettle_hash *hash; }; -enum { OPT_ONCE = 300, OPT_HASH }; +enum { OPT_ONCE = 300, OPT_HASH, OPT_LOCK }; static int match_argument(const char *given, const char *name) @@ -201,6 +221,7 @@ parse_options(struct conv_options *o, o->mode = SEXP_ADVANCED; o->prefer_hex = 0; o->once = 0; + o->lock = 0; o->hash = NULL; o->width = 72; @@ -219,6 +240,9 @@ parse_options(struct conv_options *o, { "hash", optional_argument, NULL, OPT_HASH }, { "raw-hash", optional_argument, NULL, OPT_HASH }, { "width", required_argument, NULL, 'w' }, +#if HAVE_FCNTL_LOCKING + { "lock", no_argument, NULL, OPT_LOCK }, +#endif #if 0 /* Not yet implemented */ { "replace", required_argument, NULL, OPT_REPLACE }, @@ -293,7 +317,11 @@ parse_options(struct conv_options *o, } } break; - +#if HAVE_FCNTL_LOCKING + case OPT_LOCK: + o->lock = 1; + break; +#endif case '?': printf("Usage: sexp-conv [OPTION...]\n" " Conversion: sexp-conv [OPTION...]