source: palm/trunk/SCRIPTS/palm_find_lowest_available_error_number @ 3045

Last change on this file since 3045 was 3024, checked in by knoop, 6 years ago

Added awesome lowest available error number finder script

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1#!/usr/bin/env bash
2#------------------------------------------------------------------------------#
3# This file is part of the PALM model system.
4#
5# PALM is free software: you can redistribute it and/or modify it under the terms
6# of the GNU General Public License as published by the Free Software Foundation,
7# either version 3 of the License, or (at your option) any later version.
8#
9# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along with
14# PALM. If not, see <http://www.gnu.org/licenses/>.
15#
16# Copyright 2018-2018  Leibniz Universitaet Hannover
17#------------------------------------------------------------------------------#
18#
19# Current revisions:
20# ------------------
21#
22#
23# Former revisions:
24# -----------------
25# $Id: palm_find_lowest_available_error_number 3024 2018-05-22 10:17:49Z Giersch $
26# Initial revision
27#
28#------------------------------------------------------------------------------#
29# palm_find_lowest_available_error_number does what its name indicates
30#------------------------------------------------------------------------------#
31SOURCE="${BASH_SOURCE[0]}"
32while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
33  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
34  SOURCE="$(readlink "$SOURCE")"
35  # if $SOURCE was a relative symlink, we need to resolve it
36  # relative to the path where the symlink file was located
37  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
38done
39SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
40
41working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
42trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
43
44contains() {
45    [[ ${1} =~ (^|[[:space:]])${2}($|[[:space:]]) ]] && return 0 || return 1
46}
47
48error_code_prefix="PA"
49
50all_found_error_codes=$(grep -P "CALL +message\(.+\)" ${trunk_dir}/SOURCE/* \
51      | grep -oP "${error_code_prefix}(?<!\d)\d{4}(?!\d)" | sort | uniq -c  \
52      | grep -oP "${error_code_prefix}(?<!\d)\d{4}(?!\d)")
53
54for n in {1..9999} ; do
55   current_code=$(printf "${error_code_prefix}%04d" $((10#${n})))
56   if ! contains "$all_found_error_codes" "$current_code"; then
57     echo $current_code
58     break
59   fi
60done
Note: See TracBrowser for help on using the repository browser.