From b6fb43a0eb175610ea618bcee8ab765e511c3c05 Mon Sep 17 00:00:00 2001 From: ghuter <ghuter@disroot.org> Date: Thu, 30 Mar 2023 15:58:48 +0200 Subject: [PATCH] modify memory_option.sh --- src/memory_option.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/memory_option.sh b/src/memory_option.sh index 54a2c6e..30a3831 100755 --- a/src/memory_option.sh +++ b/src/memory_option.sh @@ -3,9 +3,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later # Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr> -MEMINFO_PATH="/proc/meminfo" +meminfo_path=/proc/meminfo -FUNCTION_TEMPLATE="void set_result_offset%s(GenericPointer ptr, GenericPointer data) +function_template="void set_result_offset%s(GenericPointer ptr, GenericPointer data) { uint64_t* result = (uint64_t *) ptr; result[%s] = (uint64_t) data; @@ -14,16 +14,15 @@ FUNCTION_TEMPLATE="void set_result_offset%s(GenericPointer ptr, GenericPointer d nb_counters=0 echo '#include <inttypes.h>' -echo "#include <info_reader.h>" +echo '#include <info_reader.h>' echo echo 'static char *memory_counters[] = {' while read line; do - nb_counters=$(expr $nb_counters + 1) - word=$(echo $line | awk '{print $1}') - echo " \"${word::-1}\"," -done <$MEMINFO_PATH -echo "};" + : $((nb_counters += 1)) + echo "$line" | awk -F ':' '{printf(" \"%s\",\n", $1)}' +done < "$meminfo_path" +echo '};' echo echo "#define NB_COUNTERS $nb_counters" @@ -31,16 +30,16 @@ echo count=0 while [ $count -lt $nb_counters ]; do - printf "$FUNCTION_TEMPLATE" $count $count - count=$(expr $count + 1) + printf "$function_template" $count $count + : $((count += 1)) done -echo "static void (*setter_functions[])(GenericPointer, GenericPointer) = {" +echo 'static void (*setter_functions[])(GenericPointer, GenericPointer) = {' count=0 while [ $count -lt $nb_counters ]; do echo " set_result_offset$count," - count=$(expr $count + 1) + : $((count += 1)) done -echo "};" +echo '};' echo -- GitLab