diff options
author | Raimo Niskanen <[email protected]> | 2014-05-22 10:06:51 +0200 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2014-07-25 12:17:49 +0200 |
commit | 827f952ce799f2051f60f0f8002d2e3908b2b5da (patch) | |
tree | f5b7f55bd2c1b5428994867842a9356730553df7 /lib/snmp/src/misc | |
parent | 0408e4af1978177d7dee498ea3dced37aa56aefe (diff) | |
download | otp-827f952ce799f2051f60f0f8002d2e3908b2b5da.tar.gz otp-827f952ce799f2051f60f0f8002d2e3908b2b5da.tar.bz2 otp-827f952ce799f2051f60f0f8002d2e3908b2b5da.zip |
Rewrite ordering functions for maintainability
Diffstat (limited to 'lib/snmp/src/misc')
-rw-r--r-- | lib/snmp/src/misc/snmp_conf.erl | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index eb71c55cf4..0c9c755bf4 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -25,7 +25,7 @@ %% External exports %% Avoid warning for local function error/1 clashing with autoimported BIF. -compile({no_auto_import,[error/1]}). --export([read_files/2, no_gen/2, no_order/2, no_filter/1]). +-export([read_files/2, no_gen/2, no_order/2, no_filter/1, keyorder/4]). -export([read/2, read/3]). %% Basic (type) check functions @@ -158,6 +158,27 @@ no_gen(_Dir, _R) -> []. no_order(_, _) -> true. no_filter(X) -> X. +%% Order tuples on element N with Keys first in appearence order. +%% +%% An ordering function (A, B) shall return true iff +%% A is less than or equal to B i.e shall return +%% false iff A is to be ordered after B. +keyorder(N, A, B, _) when element(N, A) == element(N, B) -> + true; +keyorder(N, A, B, [Key | _]) + when tuple_size(A) >= 1, element(N, B) == Key -> + false; +keyorder(N, A, B, [Key | _]) + when element(N, A) == Key, tuple_size(B) >= 1 -> + true; +keyorder(N, A, B, [_ | Keys]) -> + keyorder(N, A, B, Keys); +keyorder(_, A, B, []) when tuple_size(A) >= 1, tuple_size(B) >= 1 -> + %% Do not order other keys + true; +keyorder(N, A, B, sort) -> + %% Order other keys according to standard sort order + element(N, A) =< element(N, B). read(File, Verify) -> |