#!/bin/bash ########################################################################### # # Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file gen_common_defs.sh # # @author (last) Quang Nguyen # @date (last) 27-May-2021 # @author (original) Peter Lucia # @date (original) 06-Apr-2021 # ############################################################################ if [[ "$1" == "-h" || "$1" == "--help" || $# -eq 0 ]]; then currentFile=$(basename "$0") echo "Usage: ./$currentFile " exit 1 fi OUTPUT_FILE=$1 COMMON_REPO=$2 COMMON_BRANCH=$3 PREFIX_MATCH=$4 CPP_HEADER=$5 TEMP_FILE="temp.txt" rm -rf "$COMMON_REPO" git clone -b "$COMMON_BRANCH" ssh://git@dvm-linux02:7999/comm/common.git "$COMMON_REPO" if [ $? -ne 0 ]; then echo "Could not clone common"; exit 1; fi if [ $(grep -oc "$PREFIX_MATCH.* = .*," -- "$COMMON_REPO/$CPP_HEADER") -gt 1 ] then echo "Enumeration has assigned number" grep -oh "$PREFIX_MATCH.* = .*," -- "$COMMON_REPO/$CPP_HEADER" > "$OUTPUT_FILE" else echo "Enumeration has auto assigned number" grep -oh "^ $PREFIX_MATCH[^;]*\/\/" -- "$COMMON_REPO/$CPP_HEADER" | grep -oh "$PREFIX_MATCH[^, ]*" > "$TEMP_FILE" awk 'BEGIN{i=0} /.*/{printf "%s = %d\n",$0,i; i++}' "$TEMP_FILE" > "$OUTPUT_FILE" rm "$TEMP_FILE" fi if [ $? -ne 0 ]; then echo "Error during grep"; exit 1; fi