Date: Tue, 18 Jul 2017 05:02:16 -0000
Options are now categorized explicitly into 2 groups:

  * Customizable options
    --------------------
    These are the object-like macros in `default_options.h.in'; they are
    given the prefix `CUSTOM_', and they can be overriden by the definitions
    provided by `custom_options.h' in the build directory.

  * Constant options
    ----------------
    These are the object-like macros in `constant_options.h' and elsewhere;
    they are given the prefix `DROPBEAR_', and they are intended never to be
    overriden.

In this way, it becomes very easy to identify the nature of the option, where
it may or should be defined, and how it should be used.

This refactoring can be accomplished entirely programmatically, by running
the following shell commands:

  clean() { awk '{print $2}' | sort -u; }
  filter_options() { git grep -P "^#define\s+$1" "$2" | clean; }
  filter_defaults() { filter_options "$1" default_options.h.in; }

  initial_case() { read o; printf %s "$o"; }
  other_cases() { while read o; do printf '\|%s' "$o"; done; }
  cases() { initial_case; other_cases; }

  pattern='DROPBEAR_(?!DEFAULT_OPTIONS_H_)'
  options=$(filter_defaults "$pattern" | cut -c 10- | cases)
  script="s/\bDROPBEAR_\($options\)\b/CUSTOM_\1/g"

  options=$(filter_defaults '(?!DROPBEAR_|_)' | cases)
  script+=";s/\b\($options\)\b/CUSTOM_&/g"

  script+=';s/\b_PATH_\(TTY\|CP\)\b/CUSTOM_PATH_\1/g'

  pattern='(?!DROPBEAR_|LTM|IS)'
  options=$(filter_options "$pattern" constant_options.h | cases)
  script+=";s/\b\($options\)\b/DROPBEAR_&/g"

  script+=';s/\bIS_DROPBEAR_\(SERVER\|CLIENT\)\b/DROPBEAR_IS_\1/g'

  git ls-files | grep -v CHANGES | xargs sed -i "$script"

  get_whitespace_errors() { git diff --check | grep -v '^+'; }
  tab=$(printf \\t)
  fix() { sed -i "$2{s/[ ]*$tab/$tab/g;s/[ $tab]\{1,\}\$//}" "$1"; }
  parse() { while IFS=: read file line _; do fix "$file" "$line"; done; }
  get_whitespace_errors | parse

It's way too much to check manually:

  $ git diff --shortstat
   67 files changed, 763 insertions(+), 763 deletions(-)

However, everything seems to build just fine!
---
 agentfwd.h                                |   8 +-
 algo.h                                    |   8 +-
 buffer.c                                  |   4 +-
 chansession.h                             |   6 +-
 cli-agentfwd.c                            |   4 +-
 cli-auth.c                                |  40 ++---
 cli-authinteract.c                        |  10 +-
 cli-authpasswd.c                          |  12 +-
 cli-authpubkey.c                          |  14 +-
 cli-chansession.c                         |   4 +-
 cli-kex.c                                 |  14 +-
 cli-main.c                                |   8 +-
 cli-runopts.c                             | 104 ++++++------
 cli-session.c                             |  20 +--
 cli-tcpfwd.c                              |  12 +-
 common-algo.c                             | 132 +++++++--------
 common-channel.c                          |  18 +-
 common-kex.c                              |  48 +++---
 common-runopts.c                          |   4 +-
 common-session.c                          |  36 ++--
 constant_options.h                        |  98 +++++------
 crypto_desc.c                             |   6 +-
 dbrandom.c                                |  12 +-
 dbutil.c                                  |   4 +-
 dbutil.h                                  |   2 +-
 default_options.h.in                      | 264 +++++++++++++++---------------
 dh_groups.c                               |   8 +-
 dh_groups.h                               |   4 +-
 dropbear.8                                |   2 +-
 dropbearkey.c                             |  24 +--
 dss.c                                     |  28 ++--
 dss.h                                     |   4 +-
 ecdsa.c                                   |   4 +-
 ecdsa.h                                   |   2 +-
 gendss.c                                  |   4 +-
 gendss.h                                  |   4 +-
 genrsa.c                                  |   4 +-
 genrsa.h                                  |   4 +-
 gensignkey.c                              |  16 +-
 kex.h                                     |   8 +-
 keyimport.c                               |  30 ++--
 libtomcrypt/src/headers/tomcrypt_custom.h |   8 +-
 netio.c                                   |  10 +-
 netio.h                                   |   2 +-
 packet.c                                  |  24 +--
 rsa.c                                     |  16 +-
 rsa.h                                     |   4 +-
 runopts.h                                 |  32 ++--
 scp.c                                     |   4 +-
 session.h                                 |   8 +-
 signkey.c                                 |  80 ++++-----
 signkey.h                                 |  14 +-
 sshpty.c                                  |   6 +-
 svr-agentfwd.c                            |   2 +-
 svr-auth.c                                |  10 +-
 svr-authpam.c                             |   4 +-
 svr-authpasswd.c                          |   2 +-
 svr-authpubkey.c                          |   2 +-
 svr-authpubkeyoptions.c                   |   6 +-
 svr-chansession.c                         |  38 ++---
 svr-kex.c                                 |  28 ++--
 svr-main.c                                |  40 ++---
 svr-runopts.c                             | 110 ++++++-------
 svr-session.c                             |   4 +-
 svr-tcpfwd.c                              |  22 +--
 svr-x11fwd.c                              |   8 +-
 x11fwd.h                                  |   4 +-
 67 files changed, 763 insertions(+), 763 deletions(-)

The patch has been compressed with `bzip2' and added as an attachment.

Save the attachment to `/path/to/refactor.patch.bz2', and then apply it:

    bzcat /path/to/refactor.patch.bz2 | git am

Attachment: refactor.patch.bz2
Description: BZip2 compressed data

Reply via email to