#!/usr/bin/env awk
#
# Returns all flows whose index appears in 'f'
#
# Parameters:
#   - f: the flow index(es) to test
#
# Dependencies:
#   - basicFlow
#
# See Also:
#   - packet
#
# Examples:
#   - tawk 'flow(123)' file.txt        # test for flow 123
#   - tawk 'flow("123;456")' file.txt  # test for flow 123 or 456
#   - tawk 'flow("123-456")' file.txt  # test for flow 123, 124, ... or 456

@include "hdr"
@include "_validate_col"

function flow(f,        _i, _l, _flows, _uid) {
    _uid = _validate_col("flowInd", _my_flowInd)
    if (hdr()) return __PRIHDR__
    if (match(f, /^([0-9]+)-([0-9]+)$/, _flows)) { # range
        return ($_uid >= strtonum(_flows[1]) && $_uid <= strtonum(_flows[2]))
    } else if (f ~ /^[0-9A-Za-z]+(;[0-9A-Za-z]+)*$/) {
        _l = split(f, _flows, /;/)
        for (_i = 1; _i <= _l; _i++) {
            if ($_uid == _flows[_i]) {
                return 1
            }
        }
        return 0
    }
}
