>From ed9336d864d845621e8988fd46f9064701a97540 Mon Sep 17 00:00:00 2001 From: Bruce Korb Date: Sat, 30 May 2015 09:46:31 -0700 Subject: [PATCH 1/4] implement uuencode mode option Instead of deriving it from the source file or the current umask. * src/uuencode-opts.def (mode): new option * src/uuencode.c (process_opts): handle the code (encode): add warning when stdin and stderr are terminals print a warning message (a prompt to start typing input). Better than just hanging there leaving a puzzled user. * src/Makefile.am: add a rule for re-creating help text --- src/Makefile.am | 11 +++++++++++ src/uuencode-full-help.txt | 17 +++++++++++++---- src/uuencode-opts.def | 23 +++++++++++++++++++++++ src/uuencode.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 85c86fd..5c92ee2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -143,4 +143,15 @@ help-text : mk-help.sh $(bin_PROGRAMS) touch $@ $(SHELL) mk-help.sh $@ $(bin_PROGRAMS) +$(usage_texts) : + @set -x ; for f in $(usage_texts) ; \ + do test -f $(srcdir)/$$f && continue ; \ + g=$${f%%-*} ; test -x $(builddir)/$$g || { \ + cd $(builddir) ; $(MAKE) $$g ; } ; \ + case "$$f" in \ + *-short-* ) $(builddir)/$$g --bogus 2>&1 | sed 1d > $(srcdir)/$$f ;; \ + *-full-* ) $(builddir)/$$g --help > $(srcdir)/$$f ;; \ + esac ; \ + done + ## src/Makefile.am ends here diff --git a/src/uuencode-full-help.txt b/src/uuencode-full-help.txt index dc8f69b..caffdbc 100644 --- a/src/uuencode-full-help.txt +++ b/src/uuencode-full-help.txt @@ -3,13 +3,15 @@ Usage: uuencode [ - | -- ]... [] -m, --base64 convert using base64 -e, --encode-file-name encode the output file name + -p, --mode=PERMS file mode permissions + - is a set membership option -v, --version[=MODE] output version information and exit -h, --help display extended usage information and exit -!, --more-help extended usage information passed thru pager - -R, --save-opts[=FILE] save the option state to a config file FILE - -r, --load-opts=FILE load options from the config file FILE - - disabled with '--no-load-opts' - - may appear multiple times + -R, --save-opts[=FILE] save the option state to a config file + -r, --load-opts=FILE load options from a config file + - disabled as '--no-load-opts' + - may appear multiple times Options are specified by doubled hyphens and their name or by a single hyphen and the flag character. @@ -17,6 +19,13 @@ hyphen and the flag character. The following option preset mechanisms are supported: - reading file $HOME/.sharrc +The valid "mode" option keywords are: + xoth woth roth xgrp wgrp rgrp xusr wusr rusr rwxo rwxg rwxu xall wall rall + or an integer mask with any of the lower 9 bits set +or you may use a numeric representation. Preceding these with a '!' +will clear the bits, specifying 'none' will clear all bits, and 'all' +will set them all. Multiple entries may be passed as an option +argument list. 'uuencode' is used to create an ASCII representation of a file that can be sent over channels that may otherwise corrupt the data. Specifically, email cannot handle binary data and will often even insert a character when diff --git a/src/uuencode-opts.def b/src/uuencode-opts.def index be139ad..77edeef 100644 --- a/src/uuencode-opts.def +++ b/src/uuencode-opts.def @@ -68,6 +68,29 @@ flag = { _EODoc_; }; +flag = { + name = mode; + value = p; + descrip = 'file mode permissions'; + arg-name = perm-name; + arg-type = set; + keyword = xoth, woth, roth, xgrp, wgrp, rgrp, xusr, wusr, rusr, + rwxo, rwxg, rwxu, xall, wall, rall; + + doc = <<- _EODoc_ + By default, the output mode is set by the mode of the input file, or + (if the input is standard input) defaults to the current umask. + This option specifies the mode. The bit names match the bit names in @file{stat(2)}, + extended by @code{?all} codes for setting read/write/execute bits for all categories. + So to specify that everyone can read and the owner can write: + @example + @file{uuencode} @samp{-prall,wusr} + @end example + @noindent + or, equivalently, @samp{-p 0644}. NOTE: The number does @i{not} default to octal. + _EODoc_; +}; + doc-section = { ds-type = STANDARDS; ds-format = texi; diff --git a/src/uuencode.c b/src/uuencode.c index c651798..2b5c5de 100644 --- a/src/uuencode.c +++ b/src/uuencode.c @@ -147,6 +147,9 @@ encode (void) { int finishing = 0; + if (isatty (STDIN_FILENO) && isatty (STDERR_FILENO)) + fputs (_("Please start typing your input file...\n"), stderr); + do { unsigned char buf[45]; @@ -248,6 +251,39 @@ process_opts (int argc, char ** argv, int * mode) USAGE (UUENCODE_EXIT_USAGE_ERROR); } + if (HAVE_OPT(MODE)) + { +# define FLAG_OKAY(_f) ((S_I##_f) == (MODE_##_f)) + enum { ModeFlagValueCheck = 1 / + (FLAG_OKAY(RUSR) && FLAG_OKAY(WUSR) && FLAG_OKAY(XUSR) && + FLAG_OKAY(RGRP) && FLAG_OKAY(WGRP) && FLAG_OKAY(XGRP) && + FLAG_OKAY(ROTH) && FLAG_OKAY(WOTH) && FLAG_OKAY(XOTH)) }; +# undef FLAG_OKAY + int m = OPT_VALUE_MODE; + if ((m & ~0777) != 0) { + if (m & MODE_RWXO) + m |= MODE_XOTH | MODE_WOTH | MODE_ROTH; + + if (m & MODE_RWXG) + m |= MODE_XGRP | MODE_WGRP | MODE_RGRP; + + if (m & MODE_RWXU) + m |= MODE_XUSR | MODE_WUSR | MODE_RUSR; + + if (m & MODE_XALL) + m |= MODE_XOTH | MODE_XGRP | MODE_XUSR; + + if (m & MODE_WALL) + m |= MODE_WOTH | MODE_WGRP | MODE_WUSR; + + if (m & MODE_RALL) + m |= MODE_ROTH | MODE_RGRP | MODE_RUSR; + + m &= 0777; + } + *mode = m; + } + if (HAVE_OPT(ENCODE_FILE_NAME)) { size_t nmlen = strlen (output_name); -- 2.12.0