diff --git a/.clang-format b/.clang-format
deleted file mode 100644
index 784c8a93..00000000
--- a/.clang-format
+++ /dev/null
@@ -1,107 +0,0 @@
----
-Language: Cpp
-# BasedOnStyle: Google
-AccessModifierOffset: -1
-AlignAfterOpenBracket: Align
-AlignConsecutiveAssignments: false
-AlignConsecutiveDeclarations: false
-AlignEscapedNewlines: Left
-AlignOperands: true
-AlignTrailingComments: true
-AllowAllParametersOfDeclarationOnNextLine: true
-AllowShortBlocksOnASingleLine: false
-AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: All
-AllowShortIfStatementsOnASingleLine: true
-AllowShortLoopsOnASingleLine: true
-AlwaysBreakAfterDefinitionReturnType: None
-AlwaysBreakAfterReturnType: None
-AlwaysBreakBeforeMultilineStrings: true
-AlwaysBreakTemplateDeclarations: true
-BinPackArguments: true
-BinPackParameters: true
-BraceWrapping:
- AfterClass: false
- AfterControlStatement: false
- AfterEnum: false
- AfterFunction: false
- AfterNamespace: false
- AfterObjCDeclaration: false
- AfterStruct: false
- AfterUnion: false
- BeforeCatch: false
- BeforeElse: false
- IndentBraces: false
- SplitEmptyFunction: true
- SplitEmptyRecord: true
- SplitEmptyNamespace: true
-BreakBeforeBinaryOperators: None
-BreakBeforeBraces: Attach
-BreakBeforeInheritanceComma: false
-BreakBeforeTernaryOperators: true
-BreakConstructorInitializersBeforeComma: false
-BreakConstructorInitializers: BeforeColon
-BreakAfterJavaFieldAnnotations: false
-BreakStringLiterals: true
-ColumnLimit: 80
-CommentPragmas: '^ IWYU pragma:'
-CompactNamespaces: false
-ConstructorInitializerAllOnOneLineOrOnePerLine: true
-ConstructorInitializerIndentWidth: 4
-ContinuationIndentWidth: 4
-Cpp11BracedListStyle: true
-DerivePointerAlignment: true
-DisableFormat: false
-ExperimentalAutoDetectBinPacking: false
-FixNamespaceComments: true
-ForEachMacros:
- - foreach
- - Q_FOREACH
- - BOOST_FOREACH
-IncludeCategories:
- - Regex: '^<.*\.h>'
- Priority: 1
- - Regex: '^<.*'
- Priority: 2
- - Regex: '.*'
- Priority: 3
-IncludeIsMainRegex: '([-_](test|unittest))?$'
-IndentCaseLabels: true
-IndentWidth: 2
-IndentWrappedFunctionNames: false
-JavaScriptQuotes: Leave
-JavaScriptWrapImports: true
-KeepEmptyLinesAtTheStartOfBlocks: false
-MacroBlockBegin: ''
-MacroBlockEnd: ''
-MaxEmptyLinesToKeep: 1
-NamespaceIndentation: None
-ObjCBlockIndentWidth: 2
-ObjCSpaceAfterProperty: false
-ObjCSpaceBeforeProtocolList: false
-PenaltyBreakAssignment: 2
-PenaltyBreakBeforeFirstCallParameter: 1
-PenaltyBreakComment: 300
-PenaltyBreakFirstLessLess: 120
-PenaltyBreakString: 1000
-PenaltyExcessCharacter: 1000000
-PenaltyReturnTypeOnItsOwnLine: 200
-PointerAlignment: Left
-ReflowComments: true
-SortIncludes: true
-SortUsingDeclarations: true
-SpaceAfterCStyleCast: false
-SpaceAfterTemplateKeyword: true
-SpaceBeforeAssignmentOperators: true
-SpaceBeforeParens: ControlStatements
-SpaceInEmptyParentheses: false
-SpacesBeforeTrailingComments: 2
-SpacesInAngles: false
-SpacesInContainerLiterals: true
-SpacesInCStyleCastParentheses: false
-SpacesInParentheses: false
-SpacesInSquareBrackets: false
-Standard: Auto
-TabWidth: 2
-UseTab: Never
-...
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..378eac25
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1 @@
+build
diff --git a/.gitignore b/.gitignore
index de23aaab..a507d0fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,7 +11,6 @@ doc/*.html
Makefile
CMakeCache.txt
CMakeFiles
-*.cmake
data/convertconf.h
data/defconfig.h
lua/libcairo-orig.c
diff --git a/.travis.yml b/.travis.yml
index 14a911b5..c10efd13 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,9 +7,9 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-trusty-6.0
packages:
- - g++-7
+ - g++-8
- cmake
- libxdamage-dev
- libx11-dev
@@ -24,16 +24,19 @@ matrix:
- libimlib2-dev
- libxinerama-dev
- gawk
- - clang-5.0
- - clang-format-5.0
+ - clang-6.0
+ sonarcloud:
+ organization: "brndnmtthws-github"
+ token:
+ secure: "KikPusy+HXcEVLr0Dqb6mkrefDU5jm7EGQ5fwO4sBG7bRMcnHV3V14s5yB4Ol8btpUC0nkNn/41+f37lkG+oT4y9ZeIH2ZrhsSEHxOgH6DF9ZSVJwtpLrF9siWgfZ0m5c5V7U5rzVYL3jlO1hQfXKCfMNAcwlKcEUrfpk7jVEZc="
env:
- - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
+ - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-trusty-6.0
packages:
- cmake
- libxdamage-dev
@@ -49,28 +52,35 @@ matrix:
- libimlib2-dev
- libxinerama-dev
- gawk
- - clang-5.0
- - clang-format-5.0
+ - clang-6.0
+ sonarcloud:
+ organization: "brndnmtthws-github"
+ token:
+ secure: "KikPusy+HXcEVLr0Dqb6mkrefDU5jm7EGQ5fwO4sBG7bRMcnHV3V14s5yB4Ol8btpUC0nkNn/41+f37lkG+oT4y9ZeIH2ZrhsSEHxOgH6DF9ZSVJwtpLrF9siWgfZ0m5c5V7U5rzVYL3jlO1hQfXKCfMNAcwlKcEUrfpk7jVEZc="
env:
- - MATRIX_EVAL="CC=clang && CXX=clang++"
+ - MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0"
before_install:
- eval "${MATRIX_EVAL}"
before_script:
- mkdir build
- cd build
- - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout cmake -DCHECK_CODE_FORMAT=ON ..
- - travis_wait 30 make format-check
+ - cmake -DCHECK_CODE_QUALITY=ON ..
- cd ..
- mkdir build-no-x11
- cd build-no-x11
- - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout cmake -DCHECK_CODE_FORMAT=ON -DBUILD_X11=OFF ..
+ - cmake -DBUILD_X11=OFF ..
- cd ..
script:
- cd build
- - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout make -j4
+ - build-wrapper-linux-x86-64 --out-dir bw-output make -j4
- cd ../build-no-x11
- - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout make -j4
+ - make -j4
+ - cd ..
+ - sonar-scanner
branches:
only:
- master
sudo: false
+cache:
+ directories:
+ - '$HOME/.sonar/cache'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3910d33f..920b26bf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,7 @@
# along with this program. If not, see .
#
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.6)
project(conky)
@@ -38,13 +38,6 @@ include(ConkyPlatformChecks)
# CPack module for installation tasks
include(ConkyCPackSetup)
-if(CHECK_CODE_FORMAT)
- # Set up clang-format
- set(CLANG_FORMAT_BIN_NAME clang-format clang-format-5.0)
- set(CLANG_FORMAT_EXCLUDE_PATTERNS "build/" ${CMAKE_BINARY_DIR})
- find_package(ClangFormat)
-endif(CHECK_CODE_FORMAT)
-
# setup our configuration headers
configure_file(${CMAKE_MODULE_PATH}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
configure_file(${CMAKE_MODULE_PATH}/build.h.in ${CMAKE_BINARY_DIR}/build.h)
@@ -81,3 +74,15 @@ if(MAINTAINER_MODE)
install(FILES ${MAN_FILES}
DESTINATION ${MAN_PATH})
endif(MAINTAINER_MODE)
+
+if(CHECK_CODE_QUALITY)
+ # Set up clang-tidy
+ set(CLANG_TIDY_BIN_NAME
+ clang-tidy
+ clang-tidy-5.0
+ clang-tidy-6.0
+ clang-tidy-7.0
+ )
+ set(CLANG_TIDY_EXCLUDE_PATTERNS "build/" ${CMAKE_BINARY_DIR})
+ find_package(ClangTidy)
+endif(CHECK_CODE_QUALITY)
diff --git a/Dockerfile b/Dockerfile
index 2f5ec359..bb3ec60b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,10 +1,36 @@
-FROM debian:latest
-RUN apt-get update && apt-get install -y cmake git g++ libimlib2-dev liblua5.3-dev libxext-dev libxft-dev libxdamage-dev libxinerama-dev ncurses-dev
-COPY . /root/
-RUN mkdir /root/build
-WORKDIR /root/build
+FROM ubuntu:latest
+RUN apt-get update \
+ && apt-get install -y \
+ cmake \
+ git \
+ g++ \
+ libimlib2-dev \
+ liblua5.3-dev \
+ libxext-dev \
+ libxft-dev \
+ libxdamage-dev \
+ libxinerama-dev \
+ ncurses-dev
+
+COPY . /conky
+WORKDIR /conky/build
ARG X11=yes
-RUN sh -c 'if [ "$X11" = "yes" ] ; then cmake ../ ; else cmake -DBUILD_X11=OFF ../ ; fi'
-RUN make all
-RUN make install
+
+RUN sh -c 'if [ "$X11" = "yes" ] ; then cmake ../ ; else cmake -DBUILD_X11=OFF ../ ; fi' \
+ && make -j5 all \
+ && make -j5 install \
+ && apt-get remove -y \
+ cmake \
+ git \
+ g++ \
+ libimlib2-dev \
+ liblua5.3-dev \
+ libxext-dev \
+ libxft-dev \
+ libxdamage-dev \
+ libxinerama-dev \
+ ncurses-dev \
+ && rm -rf /var/lib/apt/lists/* \
+ && rm -rf /conky \
+
CMD conky
diff --git a/README.md b/README.md
index 9da3f487..0caf1d84 100755
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
## Conky
-[![Build Status](https://travis-ci.org/brndnmtthws/conky.png)](https://travis-ci.org/brndnmtthws/conky)
+[![Build Status](https://travis-ci.org/brndnmtthws/conky.png)](https://travis-ci.org/brndnmtthws/conky) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=conky&metric=alert_status)](https://sonarcloud.io/dashboard/index/conky)
**Conky** is a free, light-weight system monitor for X, that displays
any kind of information on your desktop.
diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake
index 5f17d966..9ba21f15 100644
--- a/cmake/ConkyBuildOptions.cmake
+++ b/cmake/ConkyBuildOptions.cmake
@@ -33,7 +33,9 @@ endif(NOT CMAKE_BUILD_TYPE)
# -std options for all build types
set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}" CACHE STRING "Flags used by the C compiler during all build types." FORCE)
-set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}" CACHE STRING "Flags used by the C++ compiler during all build types." FORCE)
+set(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}" CACHE STRING "Flags used by the C++ compiler during all build types." FORCE)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MAINTAINER_MODE)
# some extra debug flags when in 'maintainer mode'
@@ -41,7 +43,6 @@ if(MAINTAINER_MODE)
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -Wall -W -Wextra -Wunused -pedantic -Werror -Wno-format ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
endif(MAINTAINER_MODE)
-
option(RELEASE "Build release package" false)
mark_as_advanced(RELEASE)
@@ -179,4 +180,4 @@ option(BUILD_JOURNAL "Enable support for reading from the systemd journal" false
option(BUILD_PULSEAUDIO "Enable support for Pulseaudio's default sink and source" false)
-option(CHECK_CODE_FORMAT "Check code formatting with clang-format" false)
+option(CHECK_CODE_QUALITY "Check code formatting/quality with clang" false)
diff --git a/cmake/FindClangFormat.cmake b/cmake/FindClangFormat.cmake
deleted file mode 100644
index 036afd7a..00000000
--- a/cmake/FindClangFormat.cmake
+++ /dev/null
@@ -1,34 +0,0 @@
-# Find Clang format
-#
-#
-if(NOT CLANG_FORMAT_BIN_NAME)
- set(CLANG_FORMAT_BIN_NAME clang-format)
-endif()
-
-# if custom path check there first
-if(CLANG_FORMAT_ROOT_DIR)
- find_program(CLANG_FORMAT_BIN
- NAMES
- ${CLANG_FORMAT_BIN_NAME}
- PATHS
- "${CLANG_FORMAT_ROOT_DIR}"
- NO_DEFAULT_PATH)
-endif()
-
-find_program(CLANG_FORMAT_BIN NAMES ${CLANG_FORMAT_BIN_NAME})
-
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(
- CLANG_FORMAT
- DEFAULT_MSG
- CLANG_FORMAT_BIN)
-
-mark_as_advanced(
- CLANG_FORMAT_BIN)
-
-if(CLANG_FORMAT_FOUND)
- # A CMake script to find all source files and setup clang-format targets for them
- include(clang-format)
-else()
- message("clang-format not found. Not setting up format targets")
-endif()
diff --git a/cmake/FindClangTidy.cmake b/cmake/FindClangTidy.cmake
new file mode 100644
index 00000000..473c9fb6
--- /dev/null
+++ b/cmake/FindClangTidy.cmake
@@ -0,0 +1,35 @@
+# Find Clang tidy
+#
+
+if(NOT CLANG_TIDY_BIN_NAME)
+ set(CLANG_TIDY_BIN_NAME clang-tidy)
+endif()
+
+# if custom path check there first
+if(CLANG_TIDY_ROOT_DIR)
+ find_program(CLANG_TIDY_BIN
+ NAMES
+ ${CLANG_TIDY_BIN_NAME}
+ PATHS
+ "${CLANG_TIDY_ROOT_DIR}"
+ NO_DEFAULT_PATH)
+endif()
+
+find_program(CLANG_TIDY_BIN NAMES ${CLANG_TIDY_BIN_NAME})
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+ CLANG_TIDY
+ DEFAULT_MSG
+CLANG_TIDY_BIN)
+
+mark_as_advanced(
+ CLANG_TIDY_BIN
+)
+
+if(CLANG_TIDY_FOUND)
+ # A CMake script to find all source files and setup clang-tidy targets for them
+ include(clang-tidy)
+else()
+ message("clang-tidy not found. Not setting up tidy targets")
+endif()
diff --git a/cmake/clang-format.cmake b/cmake/clang-format.cmake
deleted file mode 100644
index 423d1ef6..00000000
--- a/cmake/clang-format.cmake
+++ /dev/null
@@ -1,62 +0,0 @@
-# A CMake script to find all source files and setup clang-format targets for them
-
-# Find all source files
-set(CLANG_FORMAT_CXX_FILE_EXTENSIONS ${CLANG_FORMAT_CXX_FILE_EXTENSIONS} *.cpp *.h *.cxx *.hxx *.hpp *.cc *.ipp)
-file(GLOB_RECURSE ALL_SOURCE_FILES ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
-
-# Don't include some common build folders
-set(CLANG_FORMAT_EXCLUDE_PATTERNS ${CLANG_FORMAT_EXCLUDE_PATTERNS} "/CMakeFiles/" "cmake")
-
-# get all project files file
-foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
- foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
- string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} EXCLUDE_FOUND)
- if (NOT ${EXCLUDE_FOUND} EQUAL -1)
- list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
- endif ()
- endforeach ()
-endforeach ()
-
-add_custom_target(format
- COMMENT "Running clang-format to change files"
- COMMAND ${CLANG_FORMAT_BIN}
- -style=file
- -i
- ${ALL_SOURCE_FILES}
-)
-
-
-add_custom_target(format-check
- COMMENT "Checking clang-format changes"
- # Use ! to negate the result for correct output
- COMMAND !
- ${CLANG_FORMAT_BIN}
- -style=file
- -output-replacements-xml
- ${ALL_SOURCE_FILES}
- | grep -q "replacement offset"
-)
-
-# Get the path to this file
-get_filename_component(_clangcheckpath ${CMAKE_CURRENT_LIST_FILE} PATH)
-# have at least one here by default
-set(CHANGED_FILE_EXTENSIONS ".cpp")
-foreach(EXTENSION ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
- set(CHANGED_FILE_EXTENSIONS "${CHANGED_FILE_EXTENSIONS},${EXTENSION}" )
-endforeach()
-
-set(EXCLUDE_PATTERN_ARGS)
-foreach(EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
- list(APPEND EXCLUDE_PATTERN_ARGS "--exclude=${EXCLUDE_PATTERN}")
-endforeach()
-
-# call the script to chech changed files in git
-add_custom_target(format-check-changed
- COMMENT "Checking changed files in git"
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
- COMMAND ${_clangcheckpath}/../scripts/clang-format-check-changed.py
- --file-extensions \"${CHANGED_FILE_EXTENSIONS}\"
- ${EXCLUDE_PATTERN_ARGS}
- --clang-format-bin ${CLANG_FORMAT_BIN}
-)
-
diff --git a/cmake/clang-tidy.cmake b/cmake/clang-tidy.cmake
new file mode 100644
index 00000000..6af7f387
--- /dev/null
+++ b/cmake/clang-tidy.cmake
@@ -0,0 +1,14 @@
+# Run clang-tidy
+
+set(DO_CLANG_TIDY
+ "${CLANG_TIDY_BIN}"
+ -format-style='{BasedOnStyle: google, IndentWidth: 2}'
+ -checks=*,-clang-analyzer-alpha.*
+)
+
+if(CLANG_TIDY_BIN)
+ set_target_properties(
+ conky PROPERTIES
+ CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
+ )
+endif()
diff --git a/sonar-project.properties b/sonar-project.properties
new file mode 100644
index 00000000..0c0821a1
--- /dev/null
+++ b/sonar-project.properties
@@ -0,0 +1,4 @@
+sonar.projectKey=conky
+sonar.projectName=Conky
+sonar.sources=src
+sonar.cfamily.build-wrapper-output=build/bw-output
diff --git a/src/algebra.cc b/src/algebra.cc
index 0617972f..31721854 100644
--- a/src/algebra.cc
+++ b/src/algebra.cc
@@ -27,10 +27,10 @@
*
*/
#include "algebra.h"
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
#include
#include "config.h"
#include "conky.h"
@@ -46,7 +46,9 @@ int find_match_op(const char *expr) {
switch (expr[idx]) {
case '=':
case '!':
- if (expr[idx + 1] != '=') return -1;
+ if (expr[idx + 1] != '=') {
+ return -1;
+ }
/* fall through */
case '<':
case '>':
@@ -61,18 +63,27 @@ int get_match_type(const char *expr) {
int idx;
const char *str;
- if ((idx = find_match_op(expr)) == -1) return -1;
+ if ((idx = find_match_op(expr)) == -1) {
+ return -1;
+ }
str = expr + idx;
- if (*str == '=' && *(str + 1) == '=')
+ if (*str == '=' && *(str + 1) == '=') {
return OP_EQ;
- else if (*str == '!' && *(str + 1) == '=')
+ }
+ if (*str == '!' && *(str + 1) == '=') {
return OP_NEQ;
- else if (*str == '>') {
- if (*(str + 1) == '=') return OP_GEQ;
+ }
+ if (*str == '>') {
+ if (*(str + 1) == '=') {
+ return OP_GEQ;
+ }
return OP_GT;
- } else if (*str == '<') {
- if (*(str + 1) == '=') return OP_LEQ;
+ }
+ if (*str == '<') {
+ if (*(str + 1) == '=') {
+ return OP_LEQ;
+ }
return OP_LT;
}
return -1;
@@ -84,21 +95,21 @@ int get_match_type(const char *expr) {
* this is equal to the output of str(n)cmp(). Use a macro here, as
* it's type-independent.
*/
-#define COMPARE(v, t) \
- switch (t) { \
- case OP_GT: \
- return (v > 0); \
- case OP_LT: \
- return (v < 0); \
- case OP_EQ: \
- return (v == 0); \
- case OP_GEQ: \
- return (v >= 0); \
- case OP_LEQ: \
- return (v <= 0); \
- case OP_NEQ: \
- return (v != 0); \
- } \
+#define COMPARE(v, t) \
+ switch (t) { \
+ case OP_GT: \
+ return ((v) > 0); \
+ case OP_LT: \
+ return ((v) < 0); \
+ case OP_EQ: \
+ return ((v) == 0); \
+ case OP_GEQ: \
+ return ((v) >= 0); \
+ case OP_LEQ: \
+ return ((v) <= 0); \
+ case OP_NEQ: \
+ return ((v) != 0); \
+ } \
return 0
int lcompare(long a, enum match_type mtype, long b) {
@@ -121,22 +132,35 @@ enum arg_type get_arg_type(const char *arg) {
p = arg;
e = arg + strlen(arg) - 1;
- while (p != e && *e && *e == ' ') e--;
- while (p != e && *p == ' ') p++;
-
- if (*p == '"' && *e == '"') return ARG_STRING;
-
- if (*p == '-') // allow negative values
- p++;
- while (p <= e) {
- if (!isdigit(*p)) break;
+ while (p != e && (*e != 0) && *e == ' ') {
+ e--;
+ }
+ while (p != e && *p == ' ') {
p++;
}
- if (p == e + 1) return ARG_LONG;
+
+ if (*p == '"' && *e == '"') {
+ return ARG_STRING;
+ }
+
+ if (*p == '-') { // allow negative values
+ p++;
+ }
+ while (p <= e) {
+ if (isdigit(*p) == 0) {
+ break;
+ }
+ p++;
+ }
+ if (p == e + 1) {
+ return ARG_LONG;
+ }
if (*p == '.') {
p++;
while (p <= e) {
- if (!isdigit(*p)) return ARG_BAD;
+ if (isdigit(*p) == 0) {
+ return ARG_BAD;
+ }
p++;
}
return ARG_DOUBLE;
@@ -150,9 +174,15 @@ char *arg_to_string(const char *arg) {
start = arg;
len = 0;
- while (*start && *start == ' ') start++;
- if (!(*(start++) == '"')) return NULL;
- while (start[len] != '"') len++;
+ while ((*start != 0) && *start == ' ') {
+ start++;
+ }
+ if (!(*(start++) == '"')) {
+ return nullptr;
+ }
+ while (start[len] != '"') {
+ len++;
+ }
return strndup(start, len);
}
double arg_to_double(const char *arg) {
@@ -181,14 +211,16 @@ int compare(const char *expr) {
idx = find_match_op(expr);
mtype = get_match_type(expr);
- if (!idx || mtype == -1) {
+ if ((idx == 0) || mtype == -1) {
NORM_ERR("failed to parse compare string '%s'", expr);
return -2;
}
expr_dup = strdup(expr);
expr_dup[idx] = '\0';
- if (expr_dup[idx + 1] == '=') expr_dup[++idx] = '\0';
+ if (expr_dup[idx + 1] == '=') {
+ expr_dup[++idx] = '\0';
+ }
type1 = get_arg_type(expr_dup);
type2 = get_arg_type(expr_dup + idx + 1);
@@ -197,8 +229,12 @@ int compare(const char *expr) {
free(expr_dup);
return -2;
}
- if (type1 == ARG_LONG && type2 == ARG_DOUBLE) type1 = ARG_DOUBLE;
- if (type1 == ARG_DOUBLE && type2 == ARG_LONG) type2 = ARG_DOUBLE;
+ if (type1 == ARG_LONG && type2 == ARG_DOUBLE) {
+ type1 = ARG_DOUBLE;
+ }
+ if (type1 == ARG_DOUBLE && type2 == ARG_LONG) {
+ type2 = ARG_DOUBLE;
+ }
if (type1 != type2) {
NORM_ERR("trying to compare args '%s' and '%s' of different type", expr_dup,
(expr_dup + idx + 1));
@@ -210,7 +246,7 @@ int compare(const char *expr) {
char *a, *b;
a = arg_to_string(expr_dup);
b = arg_to_string(expr_dup + idx + 1);
- idx = scompare(a, (enum match_type)mtype, b);
+ idx = scompare(a, static_cast(mtype), b);
free(a);
free(b);
free(expr_dup);
@@ -220,12 +256,12 @@ int compare(const char *expr) {
lng_a = arg_to_long(expr_dup);
lng_b = arg_to_long(expr_dup + idx + 1);
free(expr_dup);
- return lcompare(lng_a, (enum match_type)mtype, lng_b);
+ return lcompare(lng_a, static_cast(mtype), lng_b);
case ARG_DOUBLE:
dbl_a = arg_to_double(expr_dup);
dbl_b = arg_to_double(expr_dup + idx + 1);
free(expr_dup);
- return dcompare(dbl_a, (enum match_type)mtype, dbl_b);
+ return dcompare(dbl_a, static_cast(mtype), dbl_b);
case ARG_BAD: /* make_gcc_happy() */;
}
/* not reached */
@@ -245,7 +281,7 @@ int check_if_match(struct text_object *obj) {
val = compare(expression.get());
if (val == -2) {
NORM_ERR("compare failed for expression '%s'", expression.get());
- } else if (!val) {
+ } else if (val == 0) {
result = 0;
}
return result;
diff --git a/src/apcupsd.cc b/src/apcupsd.cc
index 7e2c7de8..8734e44b 100644
--- a/src/apcupsd.cc
+++ b/src/apcupsd.cc
@@ -26,7 +26,7 @@
#include "logging.h"
#include "text_object.h"
-#include
+#include
#include
#include
#include
@@ -70,9 +70,11 @@ static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv) {
errno = 0;
FD_ZERO(&fds);
FD_SET(sock, &fds);
- res = select(sock + 1, &fds, NULL, NULL, tv);
+ res = select(sock + 1, &fds, nullptr, nullptr, tv);
} while (res < 0 && errno == EINTR);
- if (res < 0) return 0;
+ if (res < 0) {
+ return 0;
+ }
if (res == 0) {
// timeout
errno = ETIMEDOUT; // select was succesfull, errno is now 0
@@ -82,9 +84,11 @@ static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv) {
// socket ready, read the data
do {
errno = 0;
- res = recv(sock, (char *)buf, size, 0);
+ res = recv(sock, static_cast(buf), size, 0);
} while (res < 0 && errno == EINTR);
- if (res < 0) return 0;
+ if (res < 0) {
+ return 0;
+ }
if (res == 0) {
// orderly shutdown
errno = ENOTCONN;
@@ -103,9 +107,11 @@ static int net_recv(int sock, void *buf, int size) {
int len;
struct timeval tv = {0, 250000};
- while (todo) {
- len = net_recv_ex(sock, (char *)buf + off, todo, &tv);
- if (!len) return 0;
+ while (todo != 0) {
+ len = net_recv_ex(sock, static_cast(buf) + off, todo, &tv);
+ if (len == 0) {
+ return 0;
+ }
todo -= len;
off += len;
}
@@ -118,9 +124,13 @@ static int net_recv(int sock, void *buf, int size) {
static int get_line(int sock, char line[], short linesize) {
// get the line length
short sz;
- if (!net_recv(sock, &sz, sizeof(sz))) return -1;
+ if (net_recv(sock, &sz, sizeof(sz)) == 0) {
+ return -1;
+ }
sz = ntohs(sz);
- if (!sz) return 0;
+ if (sz == 0) {
+ return 0;
+ }
// get the line
while (sz >= linesize) {
@@ -128,7 +138,9 @@ static int get_line(int sock, char line[], short linesize) {
net_recv(sock, line, linesize);
sz -= linesize;
}
- if (!net_recv(sock, line, sz)) return 0;
+ if (net_recv(sock, line, sz) == 0) {
+ return 0;
+ }
line[sz] = 0;
return sz;
}
@@ -155,7 +167,7 @@ static int get_line(int sock, char line[], short linesize) {
static int fill_items(int sock, PAPCUPSD_S apc) {
char line[512];
int len;
- while ((len = get_line(sock, line, sizeof(line)))) {
+ while ((len = get_line(sock, line, sizeof(line))) != 0) {
// fill the right types in
FILL("UPSNAME", APCUPSD_NAME, FALSE);
FILL("MODEL", APCUPSD_MODEL, FALSE);
@@ -170,22 +182,23 @@ static int fill_items(int sock, PAPCUPSD_S apc) {
FILL("LASTXFER", APCUPSD_LASTXFER, FALSE);
}
- return len == 0;
+ return static_cast(len == 0);
}
//
// Conky update function for apcupsd data
//
-int update_apcupsd(void) {
+int update_apcupsd() {
int i;
APCUPSD_S apc;
int sock;
- for (i = 0; i < _APCUPSD_COUNT; ++i)
+ for (i = 0; i < _APCUPSD_COUNT; ++i) {
memcpy(apc.items[i], "N/A", 4); // including \0
+ }
do {
- struct addrinfo hints;
+ struct addrinfo hints {};
struct addrinfo *ai, *rp;
int res;
short sz = 0;
@@ -204,7 +217,7 @@ int update_apcupsd(void) {
NORM_ERR("APCUPSD getaddrinfo: %s", gai_strerror(res));
break;
}
- for (rp = ai; rp != NULL; rp = rp->ai_next) {
+ for (rp = ai; rp != nullptr; rp = rp->ai_next) {
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock == -1) {
continue;
@@ -215,7 +228,7 @@ int update_apcupsd(void) {
close(sock);
}
freeaddrinfo(ai);
- if (rp == NULL) {
+ if (rp == nullptr) {
// no error reporting, the daemon is probably not running
break;
}
@@ -234,7 +247,9 @@ int update_apcupsd(void) {
//
// read the lines of output and put them into the info structure
//
- if (!fill_items(sock, &apc)) break;
+ if (fill_items(sock, &apc) == 0) {
+ break;
+ }
} while (0);
@@ -250,7 +265,9 @@ int update_apcupsd(void) {
int apcupsd_scan_arg(const char *arg) {
char host[64];
int port;
- if (sscanf(arg, "%63s %d", host, &port) != 2) return 1;
+ if (sscanf(arg, "%63s %d", host, &port) != 2) {
+ return 1;
+ }
apcupsd.port = port;
strncpy(apcupsd.host, host, sizeof(apcupsd.host));
diff --git a/src/audacious.cc b/src/audacious.cc
index 4c38ebea..416a9cf9 100644
--- a/src/audacious.cc
+++ b/src/audacious.cc
@@ -101,7 +101,7 @@ class audacious_cb : public conky::callback {
audacious_cb(uint32_t period) : Base(period, false, Tuple()) {
#ifdef NEW_AUDACIOUS_FOUND
g_type_init();
- DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+ DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, nullptr);
if (!connection)
throw std::runtime_error("unable to establish dbus connection");
@@ -128,8 +128,8 @@ class audacious_cb : public conky::callback {
void audacious_cb::work() {
aud_result tmp;
gchar *psong, *pfilename;
- psong = NULL;
- pfilename = NULL;
+ psong = nullptr;
+ pfilename = nullptr;
do {
if (!audacious_remote_is_running(session)) {
diff --git a/src/bmpx.cc b/src/bmpx.cc
index b23f3d81..5c088a58 100644
--- a/src/bmpx.cc
+++ b/src/bmpx.cc
@@ -44,7 +44,7 @@ static char *unknown = "unknown";
void fail(GError *error, struct information *);
void update_bmpx() {
- GError *error = NULL;
+ GError *error = nullptr;
struct information *current_info = &info;
gint current_track;
GHashTable *metadata;
@@ -54,7 +54,7 @@ void update_bmpx() {
dbus_g_type_specialized_init();
bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (bus == NULL) {
+ if (bus == nullptr) {
NORM_ERR("BMPx error 1: %s\n", error->message);
fail(error, current_info);
return;
diff --git a/src/c++wrap.cc b/src/c++wrap.cc
index 14f9788e..eb46b147 100644
--- a/src/c++wrap.cc
+++ b/src/c++wrap.cc
@@ -24,14 +24,14 @@
#include "c++wrap.hh"
-#include
+#include
#include
/* force use of POSIX strerror_r instead of non-portable GNU specific */
#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
-#include
+#include
#if __cplusplus <= 199711L
#define thread_local __thread
@@ -42,17 +42,23 @@
namespace {
int pipe2_emulate(int pipefd[2], int flags) {
- if (pipe(pipefd) == -1) return -1;
+ if (pipe(pipefd) == -1) {
+ return -1;
+ }
- if (flags & O_CLOEXEC) {
+ if ((flags & O_CLOEXEC) != 0) {
// we emulate O_CLOEXEC if the system does not have it
// not very thread-safe, but at least it works
for (int i = 0; i < 2; ++i) {
int r = fcntl(pipefd[i], F_GETFD);
- if (r == -1) return -1;
+ if (r == -1) {
+ return -1;
+ }
- if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) return -1;
+ if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) {
+ return -1;
+ }
}
}
@@ -67,15 +73,16 @@ int (*const pipe2_ptr)(int[2], int) = &pipe2;
std::string strerror_r(int errnum) {
static thread_local char buf[100];
- if (strerror_r(errnum, buf, sizeof buf) != 0)
+ if (strerror_r(errnum, buf, sizeof buf) != 0) {
snprintf(buf, sizeof buf, "Unknown error %i", errnum);
+ }
return buf;
}
std::pair pipe2(int flags) {
int fd[2];
- if (pipe2_ptr(fd, flags) == -1)
+ if (pipe2_ptr(fd, flags) == -1) {
throw errno_error("pipe2");
- else
- return std::pair(fd[0], fd[1]);
+ }
+ { return std::pair(fd[0], fd[1]); }
}
diff --git a/src/ccurl_thread.cc b/src/ccurl_thread.cc
index 8c771568..4dd1f078 100644
--- a/src/ccurl_thread.cc
+++ b/src/ccurl_thread.cc
@@ -99,7 +99,7 @@ void curl_internal::do_work() {
struct headers_ {
struct curl_slist *h;
- headers_() : h(NULL) {}
+ headers_() : h(nullptr) {}
~headers_() { curl_slist_free_all(h); }
} headers;
diff --git a/src/colours.cc b/src/colours.cc
index a8fa4e22..f40befd4 100644
--- a/src/colours.cc
+++ b/src/colours.cc
@@ -39,7 +39,7 @@
static short colour_depth = 0;
static long redmask, greenmask, bluemask;
-static void set_up_gradient(void) {
+static void set_up_gradient() {
int i;
#ifdef BUILD_X11
if (out_to_x.get(*state)) {
@@ -81,9 +81,9 @@ unsigned int adjust_colours(unsigned int colour) {
r = (colour & 0xff0000) >> 16;
g = (colour & 0xff00) >> 8;
b = colour & 0xff;
- colour = (int)(r * CONST_8_TO_5_BITS) << 11;
- colour |= (int)(g * CONST_8_TO_6_BITS) << 5;
- colour |= (int)(b * CONST_8_TO_5_BITS);
+ colour = static_cast(r * CONST_8_TO_5_BITS) << 11;
+ colour |= static_cast(g * CONST_8_TO_6_BITS) << 5;
+ colour |= static_cast(b * CONST_8_TO_5_BITS);
}
return colour;
}
@@ -96,8 +96,8 @@ unsigned long *do_gradient(int width, unsigned long first_colour,
int reddiff, greendiff, bluediff; // difference
short redshift = (2 * colour_depth / 3 + colour_depth % 3);
short greenshift = (colour_depth / 3);
- unsigned long *colours =
- (unsigned long *)malloc(width * sizeof(unsigned long));
+ auto *colours =
+ static_cast(malloc(width * sizeof(unsigned long)));
int i;
if (colour_depth == 0) {
@@ -118,7 +118,7 @@ unsigned long *do_gradient(int width, unsigned long first_colour,
for (i = 0; i < width; i++) {
int red3 = 0, green3 = 0, blue3 = 0; // colour components
- float factor = ((float)i / (width - 1));
+ float factor = (static_cast(i) / (width - 1));
/* the '+ 0.5' bit rounds our floats to ints properly */
if (red1 >= red2) {
@@ -167,7 +167,8 @@ long get_x11_color(const char *name) {
XColor color;
color.pixel = 0;
- if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) {
+ if (XParseColor(display, DefaultColormap(display, screen), name, &color) ==
+ 0) {
/* lets check if it's a hex colour with the # missing in front
* if yes, then do something about it */
char newname[DEFAULT_TEXT_BUFFER_SIZE];
@@ -175,17 +176,17 @@ long get_x11_color(const char *name) {
newname[0] = '#';
strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1);
/* now lets try again */
- if (!XParseColor(display, DefaultColormap(display, screen), &newname[0],
- &color)) {
+ if (XParseColor(display, DefaultColormap(display, screen), &newname[0],
+ &color) == 0) {
NORM_ERR("can't parse X color '%s'", name);
return 0xFF00FF;
}
}
- if (!XAllocColor(display, DefaultColormap(display, screen), &color)) {
+ if (XAllocColor(display, DefaultColormap(display, screen), &color) == 0) {
NORM_ERR("can't allocate X color '%s'", name);
}
- return (long)color.pixel;
+ return static_cast(color.pixel);
}
long get_x11_color(const std::string &colour) {
diff --git a/src/combine.cc b/src/combine.cc
index 9edff96d..2fdfd5e3 100644
--- a/src/combine.cc
+++ b/src/combine.cc
@@ -68,12 +68,13 @@ void parse_combine_arg(struct text_object *obj, const char *arg) {
}
if (startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 &&
endvar[1] >= 0) {
- cd = (struct combine_data *)malloc(sizeof(struct combine_data));
+ cd =
+ static_cast(malloc(sizeof(struct combine_data)));
memset(cd, 0, sizeof(struct combine_data));
- cd->left = (char *)malloc(endvar[0] - startvar[0] + 1);
- cd->seperation = (char *)malloc(startvar[1] - endvar[0] + 1);
- cd->right = (char *)malloc(endvar[1] - startvar[1] + 1);
+ cd->left = static_cast(malloc(endvar[0] - startvar[0] + 1));
+ cd->seperation = static_cast(malloc(startvar[1] - endvar[0] + 1));
+ cd->right = static_cast(malloc(endvar[1] - startvar[1] + 1));
strncpy(cd->left, arg + startvar[0], endvar[0] - startvar[0]);
cd->left[endvar[0] - startvar[0]] = 0;
@@ -84,9 +85,11 @@ void parse_combine_arg(struct text_object *obj, const char *arg) {
strncpy(cd->right, arg + startvar[1], endvar[1] - startvar[1]);
cd->right[endvar[1] - startvar[1]] = 0;
- obj->sub = (struct text_object *)malloc(sizeof(struct text_object));
+ obj->sub =
+ static_cast(malloc(sizeof(struct text_object)));
extract_variable_text_internal(obj->sub, cd->left);
- obj->sub->sub = (struct text_object *)malloc(sizeof(struct text_object));
+ obj->sub->sub =
+ static_cast(malloc(sizeof(struct text_object)));
extract_variable_text_internal(obj->sub->sub, cd->right);
obj->data.opaque = cd;
} else {
@@ -95,7 +98,7 @@ void parse_combine_arg(struct text_object *obj, const char *arg) {
}
void print_combine(struct text_object *obj, char *p, int p_max_size) {
- struct combine_data *cd = (struct combine_data *)obj->data.opaque;
+ auto *cd = static_cast(obj->data.opaque);
std::vector> buf;
buf.resize(2);
buf[0].resize(max_user_text.get(*state));
@@ -111,49 +114,60 @@ void print_combine(struct text_object *obj, char *p, int p_max_size) {
struct llrows *ll_rows[2], *current[2];
struct text_object *objsub = obj->sub;
- if (!cd || !p_max_size) return;
+ if ((cd == nullptr) || (p_max_size == 0)) {
+ return;
+ }
p[0] = 0;
for (i = 0; i < 2; i++) {
nr_rows[i] = 1;
nextstart = 0;
- ll_rows[i] = (struct llrows *)malloc(sizeof(struct llrows));
+ ll_rows[i] = static_cast(malloc(sizeof(struct llrows)));
current[i] = ll_rows[i];
- for (j = 0; j < i; j++) objsub = objsub->sub;
+ for (j = 0; j < i; j++) {
+ objsub = objsub->sub;
+ }
generate_text_internal(&(buf[i][0]), max_user_text.get(*state), *objsub);
for (j = 0; buf[i][j] != 0; j++) {
- if (buf[i][j] == '\t') buf[i][j] = ' ';
- if (buf[i][j] == '\n')
+ if (buf[i][j] == '\t') {
+ buf[i][j] = ' ';
+ }
+ if (buf[i][j] == '\n') {
buf[i][j] = 0; // the vars inside combine may not have a \n at the end
+ }
if (buf[i][j] ==
2) { // \002 is used instead of \n to separate lines inside a var
buf[i][j] = 0;
current[i]->row = strdup(&(buf[i][0]) + nextstart);
- if (i == 0 && (long)strlen(current[i]->row) > longest)
- longest = (long)strlen(current[i]->row);
- current[i]->next = (struct llrows *)malloc(sizeof(struct llrows));
+ if (i == 0 && static_cast(strlen(current[i]->row)) > longest) {
+ longest = static_cast(strlen(current[i]->row));
+ }
+ current[i]->next =
+ static_cast(malloc(sizeof(struct llrows)));
current[i] = current[i]->next;
nextstart = j + 1;
nr_rows[i]++;
}
}
current[i]->row = strdup(&(buf[i][0]) + nextstart);
- if (i == 0 && (long)strlen(current[i]->row) > longest)
- longest = (long)strlen(current[i]->row);
- current[i]->next = NULL;
+ if (i == 0 && static_cast(strlen(current[i]->row)) > longest) {
+ longest = static_cast(strlen(current[i]->row));
+ }
+ current[i]->next = nullptr;
current[i] = ll_rows[i];
}
for (j = 0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1]); j++) {
- if (current[0]) {
+ if (current[0] != nullptr) {
strcat(p, current[0]->row);
i = strlen(current[0]->row);
- } else
+ } else {
i = 0;
+ }
while (i < longest) {
strcat(p, " ");
i++;
}
- if (current[1]) {
+ if (current[1] != nullptr) {
strcat(p, cd->seperation);
strcat(p, current[1]->row);
}
@@ -161,14 +175,17 @@ void print_combine(struct text_object *obj, char *p, int p_max_size) {
#ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic, 10)
#endif /* HAVE_OPENMP */
- for (i = 0; i < 2; i++)
- if (current[i]) current[i] = current[i]->next;
+ for (i = 0; i < 2; i++) {
+ if (current[i] != nullptr) {
+ current[i] = current[i]->next;
+ }
+ }
}
#ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic, 10)
#endif /* HAVE_OPENMP */
for (i = 0; i < 2; i++) {
- while (ll_rows[i] != NULL) {
+ while (ll_rows[i] != nullptr) {
current[i] = ll_rows[i];
free(current[i]->row);
ll_rows[i] = current[i]->next;
@@ -178,9 +195,11 @@ void print_combine(struct text_object *obj, char *p, int p_max_size) {
}
void free_combine(struct text_object *obj) {
- struct combine_data *cd = (struct combine_data *)obj->data.opaque;
+ auto *cd = static_cast(obj->data.opaque);
- if (!cd) return;
+ if (cd == nullptr) {
+ return;
+ }
free(cd->left);
free(cd->seperation);
free(cd->right);
diff --git a/src/common.cc b/src/common.cc
index 4f1db15f..6dc51cf3 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -27,16 +27,16 @@
*
*/
-#include
-#include
#include
#include
#include
#include
#include
#include
-#include
#include
+#include
+#include
+#include
#include
#include "config.h"
#include "conky.h"
@@ -94,7 +94,7 @@ char *strndup(const char *s, size_t n) {
}
#endif /* HAVE_STRNDUP */
-int update_uname(void) {
+int update_uname() {
uname(&info.uname_s);
#if defined(__DragonFly__)
@@ -102,8 +102,8 @@ int update_uname(void) {
size_t desc_n;
char desc[256];
- if (sysctlbyname("kern.version", NULL, &desc_n, NULL, 0) == -1 ||
- sysctlbyname("kern.version", desc, &desc_n, NULL, 0) == -1)
+ if (sysctlbyname("kern.version", nullptr, &desc_n, NULL, 0) == -1 ||
+ sysctlbyname("kern.version", desc, &desc_n, nullptr, 0) == -1)
perror("kern.version");
else {
char *start = desc;
@@ -118,8 +118,8 @@ int update_uname(void) {
return 0;
}
-double get_time(void) {
- struct timespec tv;
+double get_time() {
+ struct timespec tv {};
#ifdef _POSIX_MONOTONIC_CLOCK
clock_gettime(CLOCK_MONOTONIC, &tv);
#else
@@ -132,24 +132,25 @@ double get_time(void) {
* variable_substitute, except only cheques for $HOME and ~/ in
* path. If HOME is unset it uses an empty string for substitution */
std::string to_real_path(const std::string &source) {
- const char *homedir = getenv("HOME") ?: "";
- if (source.find("~/") == 0)
+ const char *homedir = getenv("HOME") != nullptr ? getenv("HOME") : "";
+ if (source.find("~/") == 0) {
return homedir + source.substr(1);
- else if (source.find("$HOME/") == 0)
+ }
+ if (source.find("$HOME/") == 0) {
return homedir + source.substr(5);
- else
+ }
return source;
}
int open_fifo(const char *file, int *reported) {
int fd = 0;
- fd = open(file, O_RDONLY | O_NONBLOCK);
+ fd = open(file, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (fd == -1) {
- if (!reported || *reported == 0) {
+ if ((reported == nullptr) || *reported == 0) {
NORM_ERR("can't open %s: %s", file, strerror(errno));
- if (reported) {
+ if (reported != nullptr) {
*reported = 1;
}
}
@@ -160,18 +161,18 @@ int open_fifo(const char *file, int *reported) {
}
FILE *open_file(const char *file, int *reported) {
- FILE *fp = 0;
+ FILE *fp = nullptr;
- fp = fopen(file, "r");
+ fp = fopen(file, "re");
- if (!fp) {
- if (!reported || *reported == 0) {
+ if (fp == nullptr) {
+ if ((reported == nullptr) || *reported == 0) {
NORM_ERR("can't open %s: %s", file, strerror(errno));
- if (reported) {
+ if (reported != nullptr) {
*reported = 1;
}
}
- return NULL;
+ return nullptr;
}
return fp;
@@ -180,7 +181,9 @@ FILE *open_file(const char *file, int *reported) {
std::string variable_substitute(std::string s) {
std::string::size_type pos = 0;
while ((pos = s.find('$', pos)) != std::string::npos) {
- if (pos + 1 >= s.size()) break;
+ if (pos + 1 >= s.size()) {
+ break;
+ }
if (s[pos + 1] == '$') {
s.erase(pos, 1);
@@ -189,22 +192,27 @@ std::string variable_substitute(std::string s) {
std::string var;
std::string::size_type l = 0;
- if (isalpha(s[pos + 1])) {
+ if (isalpha(s[pos + 1]) != 0) {
l = 1;
- while (pos + l < s.size() && isalnum(s[pos + l])) ++l;
+ while (pos + l < s.size() && (isalnum(s[pos + l]) != 0)) {
+ ++l;
+ }
var = s.substr(pos + 1, l - 1);
} else if (s[pos + 1] == '{') {
l = s.find('}', pos);
- if (l == std::string::npos) break;
+ if (l == std::string::npos) {
+ break;
+ }
l -= pos - 1;
var = s.substr(pos + 2, l - 3);
- } else
+ } else {
++pos;
+ }
- if (l) {
+ if (l != 0u) {
s.erase(pos, l);
const char *val = getenv(var.c_str());
- if (val) {
+ if (val != nullptr) {
s.insert(pos, val);
pos += strlen(val);
}
@@ -265,7 +273,7 @@ void format_seconds_short(char *buf, unsigned int n, long seconds) {
conky::simple_config_setting no_buffers("no_buffers", true, true);
-void update_stuff(void) {
+void update_stuff() {
/* clear speeds, addresses and up status in case device was removed and
* doesn't get updated */
@@ -273,7 +281,7 @@ void update_stuff(void) {
#pragma omp parallel for schedule(dynamic, 10)
#endif /* HAVE_OPENMP */
for (int i = 0; i < MAX_NET_INTERFACES; ++i) {
- if (netstats[i].dev) {
+ if (netstats[i].dev != nullptr) {
netstats[i].up = 0;
netstats[i].recv_speed = 0.0;
netstats[i].trans_speed = 0.0;
@@ -300,24 +308,22 @@ void update_stuff(void) {
/* Ohkie to return negative values for temperatures */
int round_to_int_temp(float f) {
if (f >= 0.0) {
- return (int)(f + 0.5);
- } else {
- return (int)(f - 0.5);
+ return static_cast(f + 0.5);
}
+ return static_cast(f - 0.5);
}
/* Don't return negative values for cpugraph, bar, gauge, percentage.
* Causes unreasonable numbers to show */
unsigned int round_to_int(float f) {
if (f >= 0.0) {
- return (int)(f + 0.5);
- } else {
- return 0;
+ return static_cast(f + 0.5);
}
+ return 0;
}
void scan_loadavg_arg(struct text_object *obj, const char *arg) {
obj->data.i = 0;
- if (arg && !arg[1] && isdigit(arg[0])) {
+ if ((arg != nullptr) && (arg[1] == 0) && (isdigit(arg[0]) != 0)) {
obj->data.i = atoi(arg);
if (obj->data.i > 3 || obj->data.i < 1) {
NORM_ERR("loadavg arg needs to be in range (1,3)");
@@ -339,9 +345,10 @@ void print_loadavg(struct text_object *obj, char *p, int p_max_size) {
}
void scan_no_update(struct text_object *obj, const char *arg) {
- obj->data.s = (char *)malloc(text_buffer_size.get(*state));
+ obj->data.s = static_cast(malloc(text_buffer_size.get(*state)));
evaluate(arg, obj->data.s, text_buffer_size.get(*state));
- obj->data.s = (char *)realloc(obj->data.s, strlen(obj->data.s) + 1);
+ obj->data.s =
+ static_cast(realloc(obj->data.s, strlen(obj->data.s) + 1));
}
void free_no_update(struct text_object *obj) { free(obj->data.s); }
@@ -352,7 +359,7 @@ void print_no_update(struct text_object *obj, char *p, int p_max_size) {
#ifdef BUILD_X11
void scan_loadgraph_arg(struct text_object *obj, const char *arg) {
- char *buf = 0;
+ char *buf = nullptr;
buf = scan_graph(obj, arg, 0);
free_and_zero(buf);
@@ -368,21 +375,19 @@ double loadgraphval(struct text_object *obj) {
uint8_t cpu_percentage(struct text_object *obj) {
if (obj->data.i > info.cpu_count) {
NORM_ERR("obj->data.i %i info.cpu_count %i", obj->data.i, info.cpu_count);
- CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
+ CRIT_ERR(nullptr, nullptr, "attempting to use more CPUs than you have!");
}
- if (info.cpu_usage) {
+ if (info.cpu_usage != nullptr) {
return round_to_int(info.cpu_usage[obj->data.i] * 100.0);
- } else {
- return 0;
}
+ return 0;
}
double cpu_barval(struct text_object *obj) {
- if (info.cpu_usage) {
+ if (info.cpu_usage != nullptr) {
return info.cpu_usage[obj->data.i];
- } else {
- return 0.;
}
+ return 0.;
}
#define PRINT_HR_GENERATOR(name) \
@@ -404,31 +409,35 @@ PRINT_HR_GENERATOR(swapmax)
uint8_t mem_percentage(struct text_object *obj) {
(void)obj;
- return (info.memmax ? round_to_int(info.mem * 100 / info.memmax) : 0);
+ return (info.memmax != 0u ? round_to_int(info.mem * 100 / info.memmax) : 0);
}
double mem_barval(struct text_object *obj) {
(void)obj;
- return info.memmax ? ((double)info.mem / info.memmax) : 0;
+ return info.memmax != 0u ? (static_cast(info.mem) / info.memmax) : 0;
}
double mem_with_buffers_barval(struct text_object *obj) {
(void)obj;
- return info.memmax ? ((double)info.memwithbuffers / info.memmax) : 0;
+ return info.memmax != 0u
+ ? (static_cast(info.memwithbuffers) / info.memmax)
+ : 0;
}
uint8_t swap_percentage(struct text_object *obj) {
(void)obj;
- return (info.swapmax ? round_to_int(info.swap * 100 / info.swapmax) : 0);
+ return (info.swapmax != 0u ? round_to_int(info.swap * 100 / info.swapmax)
+ : 0);
}
double swap_barval(struct text_object *obj) {
(void)obj;
- return info.swapmax ? ((double)info.swap / info.swapmax) : 0;
+ return info.swapmax != 0u ? (static_cast(info.swap) / info.swapmax)
+ : 0;
}
void print_kernel(struct text_object *obj, char *p, int p_max_size) {
@@ -471,12 +480,12 @@ void print_version(struct text_object *obj, char *p, int p_max_size) {
void print_uptime(struct text_object *obj, char *p, int p_max_size) {
(void)obj;
- format_seconds(p, p_max_size, (int)info.uptime);
+ format_seconds(p, p_max_size, static_cast(info.uptime));
}
void print_uptime_short(struct text_object *obj, char *p, int p_max_size) {
(void)obj;
- format_seconds_short(p, p_max_size, (int)info.uptime);
+ format_seconds_short(p, p_max_size, static_cast(info.uptime));
}
void print_processes(struct text_object *obj, char *p, int p_max_size) {
@@ -529,13 +538,13 @@ int if_empty_iftest(struct text_object *obj) {
static int check_contains(char *f, char *s) {
int ret = 0;
- FILE *where = open_file(f, 0);
+ FILE *where = open_file(f, nullptr);
- if (where) {
+ if (where != nullptr) {
char buf1[256];
- while (fgets(buf1, 256, where)) {
- if (strstr(buf1, s)) {
+ while (fgets(buf1, 256, where) != nullptr) {
+ if (strstr(buf1, s) != nullptr) {
ret = 1;
break;
}
@@ -552,11 +561,17 @@ int if_existing_iftest(struct text_object *obj) {
int result = 0;
spc = strchr(obj->data.s, ' ');
- if (spc != NULL) *spc = 0;
- if (access(obj->data.s, F_OK) == 0) {
- if (spc == NULL || check_contains(obj->data.s, spc + 1)) result = 1;
+ if (spc != nullptr) {
+ *spc = 0;
+ }
+ if (access(obj->data.s, F_OK) == 0) {
+ if (spc == nullptr || (check_contains(obj->data.s, spc + 1) != 0)) {
+ result = 1;
+ }
+ }
+ if (spc != nullptr) {
+ *spc = ' ';
}
- if (spc != NULL) *spc = ' ';
return result;
}
@@ -564,7 +579,7 @@ int if_running_iftest(struct text_object *obj) {
#ifdef __linux__
if (!get_process_by_name(obj->data.s)) {
#else
- if ((obj->data.s) && system(obj->data.s)) {
+ if (((obj->data.s) != nullptr) && (system(obj->data.s) != 0)) {
#endif
return 0;
}
@@ -581,14 +596,14 @@ void free_acpitemp(struct text_object *obj) { close(obj->data.i); }
void print_freq(struct text_object *obj, char *p, int p_max_size) {
static int ok = 1;
- if (ok) {
+ if (ok != 0) {
ok = get_freq(p, p_max_size, "%.0f", 1, obj->data.i);
}
}
void print_freq_g(struct text_object *obj, char *p, int p_max_size) {
static int ok = 1;
- if (ok) {
+ if (ok != 0) {
#ifndef __OpenBSD__
ok = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.i);
#else
@@ -605,7 +620,8 @@ void print_acpifan(struct text_object *obj, char *p, int p_max_size) {
}
void print_acpiacadapter(struct text_object *obj, char *p, int p_max_size) {
- get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque);
+ get_acpi_ac_adapter(p, p_max_size,
+ static_cast(obj->data.opaque));
}
void print_battery(struct text_object *obj, char *p, int p_max_size) {
@@ -633,21 +649,25 @@ void print_blink(struct text_object *obj, char *p, int p_max_size) {
static int last_len = 0;
int i;
- if (visible) {
+ if (visible != 0) {
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
last_len = strlen(&(buf[0]));
} else {
- for (i = 0; i < last_len; i++) buf[i] = ' ';
+ for (i = 0; i < last_len; i++) {
+ buf[i] = ' ';
+ }
}
snprintf(p, p_max_size, "%s", &(buf[0]));
- visible = !visible;
+ visible = static_cast(static_cast(visible) == 0);
}
void print_include(struct text_object *obj, char *p, int p_max_size) {
std::vector buf(max_user_text.get(*state));
- if (!obj->sub) return;
+ if (obj->sub == nullptr) {
+ return;
+ }
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
snprintf(p, p_max_size, "%s", &(buf[0]));
@@ -672,19 +692,20 @@ void print_to_bytes(struct text_object *obj, char *p, int p_max_size) {
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
if (sscanf(&(buf[0]), "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16) {
- if (strncasecmp("b", unit, 1) == 0)
+ if (strncasecmp("b", unit, 1) == 0) {
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes);
- else if (strncasecmp("k", unit, 1) == 0)
+ } else if (strncasecmp("k", unit, 1) == 0) {
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024);
- else if (strncasecmp("m", unit, 1) == 0)
+ } else if (strncasecmp("m", unit, 1) == 0) {
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
bytes * 1024 * 1024);
- else if (strncasecmp("g", unit, 1) == 0)
+ } else if (strncasecmp("g", unit, 1) == 0) {
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
bytes * 1024 * 1024 * 1024);
- else if (strncasecmp("t", unit, 1) == 0)
+ } else if (strncasecmp("t", unit, 1) == 0) {
snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
bytes * 1024 * 1024 * 1024 * 1024);
+ }
}
snprintf(p, p_max_size, "%s", &(buf[0]));
}
@@ -695,6 +716,8 @@ void print_updates(struct text_object *obj, char *p, int p_max_size) {
}
int updatenr_iftest(struct text_object *obj) {
- if (get_total_updates() % get_updatereset() != obj->data.i - 1) return 0;
+ if (get_total_updates() % get_updatereset() != obj->data.i - 1) {
+ return 0;
+ }
return 1;
}
diff --git a/src/common.h b/src/common.h
index 3f4f6511..8b6407ec 100644
--- a/src/common.h
+++ b/src/common.h
@@ -66,8 +66,8 @@ FILE *open_file(const char *file, int *reported);
int open_fifo(const char *file, int *reported);
std::string variable_substitute(std::string s);
-void format_seconds(char *buf, unsigned int n, long t);
-void format_seconds_short(char *buf, unsigned int n, long t);
+void format_seconds(char *buf, unsigned int n, long seconds);
+void format_seconds_short(char *buf, unsigned int n, long seconds);
int round_to_int_temp(float);
diff --git a/src/conky.cc b/src/conky.cc
index 2e3d6df8..00e52554 100644
--- a/src/conky.cc
+++ b/src/conky.cc
@@ -28,15 +28,16 @@
*/
#include "conky.h"
-#include
-#include
-#include
-#include
-#include
#include
+#include
+#include
+#include
#include
+#include
+#include
#include
#include
+#include
#include
#include
#include "common.h"
@@ -51,8 +52,8 @@
#include
#endif /* HAVE_SYS_INOTIFY_H */
#ifdef BUILD_X11
-#include
#include "x11.h"
+#include
#ifdef BUILD_XDAMAGE
#include
#endif
@@ -140,7 +141,7 @@
namespace {
const char builtin_config_magic[] = "==builtin==";
-}
+} // namespace
#endif
#ifdef BUILD_OLD_CONFIG
@@ -236,7 +237,7 @@ void music_player_interval_setting::lua_setter(lua::state &l, bool init) {
music_player_interval_setting music_player_interval;
-void *global_cpu = NULL;
+void *global_cpu = nullptr;
static conky::range_config_setting max_text_width(
"max_text_width", 0, std::numeric_limits::max(), 0, true);
@@ -248,10 +249,10 @@ int argc_copy;
char **argv_copy;
/* prototypes for internally used functions */
-static void signal_handler(int);
-static void reload_config(void);
+static void signal_handler(int /*sig*/);
+static void reload_config();
-static void print_version(void) {
+static void print_version() {
std::cout << _(PACKAGE_NAME " " VERSION " compiled " BUILD_DATE
" for " BUILD_ARCH
"\n"
@@ -424,7 +425,7 @@ static const char *suffixes[] = {_nop("B"), _nop("KiB"), _nop("MiB"),
#ifdef BUILD_X11
-static void X11_create_window(void);
+static void X11_create_window();
struct _x11_stuff_s {
Region region;
@@ -477,11 +478,11 @@ conky::range_config_setting diskio_avg_samples("diskio_avg_samples", 1, 14,
/* filenames for output */
static conky::simple_config_setting overwrite_file(
"overwrite_file", std::string(), true);
-static FILE *overwrite_fpointer = NULL;
+static FILE *overwrite_fpointer = nullptr;
static conky::simple_config_setting append_file("append_file",
std::string(),
true);
-static FILE *append_fpointer = NULL;
+static FILE *append_fpointer = nullptr;
#ifdef BUILD_HTTP
std::string webpage;
@@ -512,8 +513,8 @@ class out_to_http_setting : public conky::simple_config_setting {
Base::lua_setter(l, init);
if (init && do_convert(l, -1).first) {
- httpd = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, HTTPPORT, NULL, NULL,
- &sendanswer, NULL, MHD_OPTION_END);
+ httpd = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, HTTPPORT, nullptr, NULL,
+ &sendanswer, nullptr, MHD_OPTION_END);
}
++s;
@@ -524,7 +525,7 @@ class out_to_http_setting : public conky::simple_config_setting {
if (do_convert(l, -1).first) {
MHD_stop_daemon(httpd);
- httpd = NULL;
+ httpd = nullptr;
}
l.pop();
@@ -575,7 +576,7 @@ static conky::range_config_setting maximum_width(
static bool isutf8(const char *envvar) {
char *s = getenv(envvar);
- if (s) {
+ if (s != nullptr) {
std::string temp = s;
std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
if ((temp.find("utf-8") != std::string::npos) ||
@@ -608,9 +609,9 @@ conky::range_config_setting text_buffer_size(
/* pad percentages to decimals? */
static conky::simple_config_setting pad_percents("pad_percents", 0, false);
-static char *global_text = 0;
+static char *global_text = nullptr;
-char *get_global_text(void) { return global_text; }
+char *get_global_text() { return global_text; }
long global_text_lines;
@@ -621,9 +622,9 @@ std::unique_ptr state;
void set_updatereset(int i) { updatereset = i; }
-int get_updatereset(void) { return updatereset; }
+int get_updatereset() { return updatereset; }
-int get_total_updates(void) { return total_updates; }
+int get_total_updates() { return total_updates; }
int calc_text_width(const char *s) {
size_t slen = strlen(s);
@@ -640,17 +641,17 @@ int calc_text_width(const char *s) {
if (utf8_mode.get(*state)) {
XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
- (const FcChar8 *)s, slen, &gi);
+ reinterpret_cast(s), slen, &gi);
} else {
- XftTextExtents8(display, fonts[selected_font].xftfont, (const FcChar8 *)s,
- slen, &gi);
+ XftTextExtents8(display, fonts[selected_font].xftfont,
+ reinterpret_cast(s), slen, &gi);
}
return gi.xOff;
- } else
-#endif /* BUILD_XFT */
- {
- return XTextWidth(fonts[selected_font].font, s, slen);
}
+#endif /* BUILD_XFT */
+
+ return XTextWidth(fonts[selected_font].font, s, slen);
+
#endif /* BUILD_X11 */
}
@@ -665,8 +666,10 @@ static inline void for_each_line(char *b, int f(char *, int)) {
char *ps, *pe;
int special_index = 0; /* specials index */
- if (!b) return;
- for (ps = b, pe = b; *pe; pe++) {
+ if (b == nullptr) {
+ return;
+ }
+ for (ps = b, pe = b; *pe != 0; pe++) {
if (*pe == '\n') {
*pe = '\0';
special_index = f(ps, special_index);
@@ -683,7 +686,7 @@ static inline void for_each_line(char *b, int f(char *, int)) {
static void convert_escapes(char *buf) {
char *p = buf, *s = buf;
- while (*s) {
+ while (*s != 0) {
if (*s == '\\') {
s++;
if (*s == 'n') {
@@ -710,7 +713,7 @@ int spaced_print(char *buf, int size, const char *format, int width, ...) {
if (size < 1) {
return 0;
}
- tempbuf = (char *)malloc(size * sizeof(char));
+ tempbuf = static_cast(malloc(size * sizeof(char)));
// Passes the varargs along to vsnprintf
va_start(argp, width);
@@ -766,11 +769,12 @@ void human_readable(long long num, char *buf, int size) {
}
if (llabs(num) < 1000LL) {
- spaced_print(buf, size, format, width, 0, (float)num, _(*suffix));
+ spaced_print(buf, size, format, width, 0, static_cast(num),
+ _(*suffix));
return;
}
- while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
+ while (llabs(num / 1024) >= 1000LL && (**(suffix + 2) != 0)) {
num /= 1024;
suffix++;
}
@@ -796,8 +800,12 @@ void human_readable(long long num, char *buf, int size) {
* printed with a precision of 0. Yay. */
precision = 0; /* print 100-999 without decimal part */
- if (fnum < 99.95) precision = 1; /* print 10-99 with one decimal place */
- if (fnum < 9.995) precision = 2; /* print 0-9 with two decimal places */
+ if (fnum < 99.95) {
+ precision = 1; /* print 10-99 with one decimal place */
+ }
+ if (fnum < 9.995) {
+ precision = 2; /* print 0-9 with two decimal places */
+ }
spaced_print(buf, size, format, width, precision, fnum, _(*suffix));
}
@@ -809,7 +817,7 @@ static long current_text_color;
void set_current_text_color(long colour) { current_text_color = colour; }
-long get_current_text_color(void) { return current_text_color; }
+long get_current_text_color() { return current_text_color; }
static void extract_variable_text(const char *p) {
free_text_objects(&global_root_object);
@@ -848,7 +856,9 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root) {
struct text_object *obj;
size_t a;
- if (!p) return;
+ if (p == nullptr) {
+ return;
+ }
#ifdef BUILD_ICONV
char *buff_in;
@@ -859,24 +869,26 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root) {
p[0] = 0;
obj = root.next;
- while (obj && p_max_size > 0) {
+ while ((obj != nullptr) && p_max_size > 0) {
/* check callbacks for existence and act accordingly */
- if (obj->callbacks.print) {
+ if (obj->callbacks.print != nullptr) {
(*obj->callbacks.print)(obj, p, p_max_size);
- } else if (obj->callbacks.iftest) {
- if (!(*obj->callbacks.iftest)(obj)) {
+ } else if (obj->callbacks.iftest != nullptr) {
+ if ((*obj->callbacks.iftest)(obj) == 0) {
DBGP2("jumping");
- if (obj->ifblock_next) obj = obj->ifblock_next;
+ if (obj->ifblock_next != nullptr) {
+ obj = obj->ifblock_next;
+ }
}
- } else if (obj->callbacks.barval) {
+ } else if (obj->callbacks.barval != nullptr) {
new_bar(obj, p, p_max_size, (*obj->callbacks.barval)(obj));
- } else if (obj->callbacks.gaugeval) {
+ } else if (obj->callbacks.gaugeval != nullptr) {
new_gauge(obj, p, p_max_size, (*obj->callbacks.gaugeval)(obj));
#ifdef BUILD_X11
- } else if (obj->callbacks.graphval) {
+ } else if (obj->callbacks.graphval != nullptr) {
new_graph(obj, p, p_max_size, (*obj->callbacks.graphval)(obj));
#endif /* BUILD_X11 */
- } else if (obj->callbacks.percentage) {
+ } else if (obj->callbacks.percentage != nullptr) {
percent_print(p, p_max_size, (*obj->callbacks.percentage)(obj));
}
@@ -900,7 +912,7 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root) {
}
void evaluate(const char *text, char *p, int p_max_size) {
- struct text_object subroot;
+ struct text_object subroot {};
parse_conky_vars(&subroot, text, p, p_max_size);
DBGP2("evaluated '%s' to '%s'", text, p);
@@ -910,7 +922,7 @@ void evaluate(const char *text, char *p, int p_max_size) {
double current_update_time, next_update_time, last_update_time;
-static void generate_text(void) {
+static void generate_text() {
char *p;
unsigned int i, j, k;
special_count = 0;
@@ -931,9 +943,9 @@ static void generate_text(void) {
unsigned int tbs = text_buffer_size.get(*state);
if (mw > 0) {
for (i = 0, j = 0; p[i] != 0; i++) {
- if (p[i] == '\n')
+ if (p[i] == '\n') {
j = 0;
- else if (j == mw) {
+ } else if (j == mw) {
k = i + strlen(p + i) + 1;
if (k < tbs) {
while (k != i) {
@@ -942,12 +954,14 @@ static void generate_text(void) {
}
p[k] = '\n';
j = 0;
- } else
+ } else {
NORM_ERR(
"The end of the text_buffer is reached, increase "
"\"text_buffer_size\"");
- } else
+ }
+ } else {
j++;
+ }
}
}
@@ -955,7 +969,7 @@ static void generate_text(void) {
char *tmp_p;
tmp_p = text_buffer;
- while (*tmp_p) {
+ while (*tmp_p != 0) {
*tmp_p = toupper(*tmp_p);
tmp_p++;
}
@@ -964,13 +978,14 @@ static void generate_text(void) {
double ui = active_update_interval();
double time = get_time();
next_update_time += ui;
- if (next_update_time < time || next_update_time > time + ui)
+ if (next_update_time < time || next_update_time > time + ui) {
next_update_time = time - fmod(time, ui) + ui;
+ }
last_update_time = current_update_time;
total_updates++;
}
-int get_string_width(const char *s) { return *s ? calc_text_width(s) : 0; }
+int get_string_width(const char *s) { return *s != 0 ? calc_text_width(s) : 0; }
#ifdef BUILD_X11
static inline int get_border_total() {
@@ -985,21 +1000,29 @@ static int get_string_width_special(char *s, int special_index) {
int width = 0;
long i;
- if (!s) return 0;
+ if (s == nullptr) {
+ return 0;
+ }
- if (not out_to_x.get(*state)) return strlen(s);
+ if (not out_to_x.get(*state)) {
+ return strlen(s);
+ }
p = strndup(s, text_buffer_size.get(*state));
final = p;
- for (i = 0; i < special_index; i++) current = current->next;
- for (i = 0; i < idx; i++) current = current->next;
+ for (i = 0; i < special_index; i++) {
+ current = current->next;
+ }
+ for (i = 0; i < idx; i++) {
+ current = current->next;
+ }
- while (*p) {
+ while (*p != 0) {
if (*p == SPECIAL_CHAR) {
/* shift everything over by 1 so that the special char
* doesn't mess up the size calculation */
- for (i = 0; i < (long)strlen(p); i++) {
+ for (i = 0; i < static_cast(strlen(p)); i++) {
*(p + i) = *(p + i + 1);
}
if (current->type == GRAPH || current->type == GAUGE ||
@@ -1018,9 +1041,11 @@ static int get_string_width_special(char *s, int special_index) {
if (current_after_font->type == FONT) {
influenced_by_font[i] = 0;
break;
- } else
+ }
+ {
memmove(&influenced_by_font[i], &influenced_by_font[i + 1],
strlen(&influenced_by_font[i + 1]) + 1);
+ }
}
}
// add the length of influenced_by_font in the new font to width
@@ -1033,11 +1058,12 @@ static int get_string_width_special(char *s, int special_index) {
// in the old font
int specials_skipped = 0;
while (i > 0) {
- if (p[specials_skipped] != 1)
+ if (p[specials_skipped] != 1) {
memmove(&p[specials_skipped], &p[specials_skipped + 1],
strlen(&p[specials_skipped + 1]) + 1);
- else
+ } else {
specials_skipped++;
+ }
i--;
}
}
@@ -1057,13 +1083,15 @@ static int get_string_width_special(char *s, int special_index) {
static int text_size_updater(char *s, int special_index);
int last_font_height;
-static void update_text_area(void) {
+static void update_text_area() {
int x = 0, y = 0;
- if (not out_to_x.get(*state)) return;
- /* update text size if it isn't fixed */
+ if (not out_to_x.get(*state)) {
+ return;
+ }
+ /* update text size if it isn't fixed */
#ifdef OWN_WINDOW
- if (!fixed_size)
+ if (fixed_size == 0)
#endif
{
text_width = minimum_width.get(*state);
@@ -1133,7 +1161,7 @@ static void update_text_area(void) {
#endif /* OWN_WINDOW */
#ifdef OWN_WINDOW
- if (own_window.get(*state) && !fixed_pos) {
+ if (own_window.get(*state) && (fixed_pos == 0)) {
x += workarea[0];
y += workarea[1];
@@ -1174,12 +1202,16 @@ static int text_size_updater(char *s, int special_index) {
char *p;
special_t *current = specials;
- for (int i = 0; i < special_index; i++) current = current->next;
+ for (int i = 0; i < special_index; i++) {
+ current = current->next;
+ }
- if (not out_to_x.get(*state)) return 0;
+ if (not out_to_x.get(*state)) {
+ return 0;
+ }
/* get string widths and skip specials */
p = s;
- while (*p) {
+ while (*p != 0) {
if (*p == SPECIAL_CHAR) {
*p = '\0';
w += get_string_width(s);
@@ -1200,13 +1232,13 @@ static int text_size_updater(char *s, int special_index) {
last_font_height += current->arg;
} else if (current->type == GOTO) {
if (current->arg > cur_x) {
- w = (int)current->arg;
+ w = static_cast(current->arg);
}
} else if (current->type == TAB) {
int start = current->arg;
int step = current->width;
- if (!step || step < 0) {
+ if ((step == 0) || step < 0) {
step = 10;
}
w += step - (cur_x - text_start_x - start) % step;
@@ -1261,17 +1293,18 @@ static inline void set_foreground_color(long c) {
}
#endif /* BUILD_NCURSES */
UNUSED(c);
- return;
}
-std::string string_replace_all(std::string original, std::string oldpart,
- std::string newpart,
+std::string string_replace_all(std::string original, const std::string &oldpart,
+ const std::string &newpart,
std::string::size_type start) {
std::string::size_type i = start;
int oldpartlen = oldpart.length();
while (1) {
i = original.find(oldpart, i);
- if (i == std::string::npos) break;
+ if (i == std::string::npos) {
+ break;
+ }
original.replace(i, oldpartlen, newpart);
}
return original;
@@ -1289,17 +1322,19 @@ static void draw_string(const char *s) {
width_of_s = get_string_width(s);
if (out_to_stdout.get(*state) && draw_mode == FG) {
printf("%s\n", s);
- if (extra_newline.get(*state)) fputc('\n', stdout);
+ if (extra_newline.get(*state)) {
+ fputc('\n', stdout);
+ }
fflush(stdout); /* output immediately, don't buffer */
}
if (out_to_stderr.get(*state) && draw_mode == FG) {
fprintf(stderr, "%s\n", s);
fflush(stderr); /* output immediately, don't buffer */
}
- if (draw_mode == FG && overwrite_fpointer) {
+ if (draw_mode == FG && (overwrite_fpointer != nullptr)) {
fprintf(overwrite_fpointer, "%s\n", s);
}
- if (draw_mode == FG && append_fpointer) {
+ if (draw_mode == FG && (append_fpointer != nullptr)) {
fprintf(append_fpointer, "%s\n", s);
}
#ifdef BUILD_NCURSES
@@ -1380,11 +1415,11 @@ static void draw_string(const char *s) {
if (utf8_mode.get(*state)) {
XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
text_offset_x + cur_x, text_offset_y + cur_y,
- (const XftChar8 *)s, strlen(s));
+ reinterpret_cast(s), strlen(s));
} else {
XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
text_offset_x + cur_x, text_offset_y + cur_y,
- (const XftChar8 *)s, strlen(s));
+ reinterpret_cast(s), strlen(s));
}
} else
#endif
@@ -1424,7 +1459,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
cur_x = text_start_x;
#endif /* BUILD_X11 */
- while (*p) {
+ while (*p != 0) {
if (*p == SPECIAL_CHAR || last_special_applied > -1) {
#ifdef BUILD_X11
int w = 0;
@@ -1442,7 +1477,9 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
/* draw special */
special_t *current = specials;
- for (int i = 0; i < special_index; i++) current = current->next;
+ for (int i = 0; i < special_index; i++) {
+ current = current->next;
+ }
switch (current->type) {
#ifdef BUILD_X11
case HORIZONTAL_LINE: {
@@ -1548,12 +1585,15 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
usage = current->arg;
scale = current->scale;
angle = M_PI * usage / scale;
- px = (float)(cur_x + (w / 2.)) - (float)(w / 2.) * cos(angle);
- py = (float)(by + (h)) - (float)(h)*sin(angle);
+ px = static_cast(cur_x + (w / 2.)) -
+ static_cast(w / 2.) * cos(angle);
+ py =
+ static_cast(by + (h)) - static_cast(h) * sin(angle);
XDrawLine(display, window.drawable, window.gc,
text_offset_x + cur_x + (w / 2.), text_offset_y + by + (h),
- text_offset_x + (int)(px), text_offset_y + (int)(py));
+ text_offset_x + static_cast(px),
+ text_offset_y + static_cast(py));
#endif /* BUILD_MATH */
if (h > cur_y_add && h > font_h) {
@@ -1599,8 +1639,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
JoinMiter);
/* in case we don't have a graph yet */
- if (current->graph) {
- unsigned long *tmpcolour = 0;
+ if (current->graph != nullptr) {
+ unsigned long *tmpcolour = nullptr;
if (current->last_colour != 0 || current->first_colour != 0) {
tmpcolour = do_gradient(w - 1, current->last_colour,
@@ -1609,7 +1649,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
colour_idx = 0;
for (i = w - 2; i > -1; i--) {
if (current->last_colour != 0 || current->first_colour != 0) {
- if (current->tempgrad) {
+ if (current->tempgrad != 0) {
#ifdef DEBUG_lol
assert((int)((float)(w - 2) - current->graph[j] * (w - 2) /
(float)current->scale) <
@@ -1623,10 +1663,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
0);
}
#endif /* DEBUG_lol */
- set_foreground_color(tmpcolour[(
- int)((float)(w - 2) -
- current->graph[j] * (w - 2) /
- std::max((float)current->scale, 1.0f))]);
+ set_foreground_color(tmpcolour[static_cast(
+ static_cast(w - 2) -
+ current->graph[j] * (w - 2) /
+ std::max(static_cast(current->scale), 1.0f))]);
} else {
set_foreground_color(tmpcolour[colour_idx++]);
}
@@ -1636,7 +1676,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
display, window.drawable, window.gc,
text_offset_x + cur_x + i + 1, text_offset_y + by + h,
text_offset_x + cur_x + i + 1,
- text_offset_y + round_to_int((double)by + h -
+ text_offset_y + round_to_int(static_cast(by) + h -
current->graph[j] * (h - 1) /
current->scale));
++j;
@@ -1680,8 +1720,9 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
tmp_sec_str = strdup("");
}
if (asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str,
- tmp_min_str, tmp_sec_str) == -1)
+ tmp_min_str, tmp_sec_str) == -1) {
tmp_str = strdup("");
+ }
free(tmp_day_str);
free(tmp_hour_str);
free(tmp_min_str);
@@ -1706,7 +1747,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
cur_x += font_ascent() / 2;
cur_y += font_h / 2;
const int tmp_str_len = 64;
- tmp_str = (char *)calloc(tmp_str_len, sizeof(char));
+ tmp_str = static_cast(calloc(tmp_str_len, sizeof(char)));
sprintf(tmp_str, "%.1f", current->scale);
draw_string(tmp_str);
free(tmp_str);
@@ -1764,7 +1805,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
int start = current->arg;
int step = current->width;
- if (!step || step < 0) {
+ if ((step == 0) || step < 0) {
step = 10;
}
w = step - (cur_x - text_start_x - start) % step;
@@ -1811,9 +1852,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
case GOTO:
if (current->arg >= 0) {
#ifdef BUILD_X11
- cur_x = (int)current->arg;
+ cur_x = static_cast(current->arg);
// make sure shades are 1 pixel to the right of the text
- if (draw_mode == BG) cur_x++;
+ if (draw_mode == BG) {
+ cur_x++;
+ }
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (out_to_ncurses.get(*state)) {
@@ -1850,7 +1893,9 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
#endif /* BUILD_NCURSES */
#ifdef BUILD_X11
- if (out_to_x.get(*state)) cur_y += font_descent();
+ if (out_to_x.get(*state)) {
+ cur_y += font_descent();
+ }
#endif /* BUILD_X11 */
return special_index;
}
@@ -1871,7 +1916,7 @@ static int draw_line(char *s, int special_index) {
return 0;
}
-static void draw_text(void) {
+static void draw_text() {
#ifdef BUILD_HTTP
#define WEBPAGE_START1 \
" 0) {
- if (stippled_borders.get(*state)) {
+ if (stippled_borders.get(*state) != 0) {
char ss[2] = {stippled_borders.get(*state),
stippled_borders.get(*state)};
XSetLineAttributes(display, window.gc, bw, LineOnOffDash, CapButt,
@@ -1934,7 +1979,7 @@ static void draw_text(void) {
#endif
}
-static void draw_stuff(void) {
+static void draw_stuff() {
#ifndef BUILD_X11
static int text_offset_x, text_offset_y; /* offset for start position */
#endif
@@ -1942,15 +1987,17 @@ static void draw_stuff(void) {
#ifdef BUILD_IMLIB2
cimlib_render(text_start_x, text_start_y, window.width, window.height);
#endif /* BUILD_IMLIB2 */
- if (overwrite_file.get(*state).size()) {
- overwrite_fpointer = fopen(overwrite_file.get(*state).c_str(), "w");
- if (!overwrite_fpointer)
+ if (static_cast(!overwrite_file.get(*state).empty()) != 0u) {
+ overwrite_fpointer = fopen(overwrite_file.get(*state).c_str(), "we");
+ if (overwrite_fpointer == nullptr) {
NORM_ERR("Cannot overwrite '%s'", overwrite_file.get(*state).c_str());
+ }
}
- if (append_file.get(*state).size()) {
- append_fpointer = fopen(append_file.get(*state).c_str(), "a");
- if (!append_fpointer)
+ if (static_cast(!append_file.get(*state).empty()) != 0u) {
+ append_fpointer = fopen(append_file.get(*state).c_str(), "ae");
+ if (append_fpointer == nullptr) {
NORM_ERR("Cannot append to '%s'", append_file.get(*state).c_str());
+ }
}
#ifdef BUILD_X11
llua_draw_pre_hook();
@@ -1998,13 +2045,13 @@ static void draw_stuff(void) {
}
#endif
#endif /* BUILD_X11 && BUILD_XDBE */
- if (overwrite_fpointer) {
+ if (overwrite_fpointer != nullptr) {
fclose(overwrite_fpointer);
- overwrite_fpointer = 0;
+ overwrite_fpointer = nullptr;
}
- if (append_fpointer) {
+ if (append_fpointer != nullptr) {
fclose(append_fpointer);
- append_fpointer = 0;
+ append_fpointer = nullptr;
}
}
@@ -2014,19 +2061,20 @@ static void clear_text(int exposures) {
if (use_xdbe.get(*state)) {
/* The swap action is XdbeBackground, which clears */
return;
- } else
+ }
#else
if (use_xpmdb.get(*state)) {
return;
} else
#endif
- if (display && window.window) { // make sure these are !null
+ if ((display != nullptr) &&
+ (window.window != 0u)) { // make sure these are !null
/* there is some extra space for borders and outlines */
int border_total = get_border_total();
XClearArea(display, window.window, text_start_x - border_total,
text_start_y - border_total, text_width + 2 * border_total,
- text_height + 2 * border_total, exposures ? True : 0);
+ text_height + 2 * border_total, exposures != 0 ? True : 0);
}
}
#endif /* BUILD_X11 */
@@ -2034,13 +2082,15 @@ static void clear_text(int exposures) {
static int need_to_update;
/* update_text() generates new text and clears old text area */
-static void update_text(void) {
+static void update_text() {
#ifdef BUILD_IMLIB2
cimlib_cleanup();
#endif /* BUILD_IMLIB2 */
generate_text();
#ifdef BUILD_X11
- if (out_to_x.get(*state)) clear_text(1);
+ if (out_to_x.get(*state)) {
+ clear_text(1);
+ }
#endif /* BUILD_X11 */
need_to_update = 1;
llua_update_info(&info, active_update_interval());
@@ -2054,24 +2104,26 @@ bool is_on_battery() { // checks if at least one battery specified in
// "detect_battery" is discharging
char buf[64];
std::string detect_battery_str;
- std::string str_buf = {""};
+ std::string str_buf = str_buf;
detect_battery_str.assign(detect_battery.get(*state));
detect_battery_str += ',';
- for (std::string::size_type i = 0; i < detect_battery_str.size();
- i++) { // parse using ',' as delimiter
- if ((detect_battery_str[i] != ',') && (detect_battery_str[i] != ' '))
- str_buf += detect_battery_str[i];
- if ((detect_battery_str[i] == ',') && !str_buf.empty()) {
+ for (char i : detect_battery_str) { // parse using ',' as delimiter
+ if ((i != ',') && (i != ' ')) {
+ str_buf += i;
+ }
+ if ((i == ',') && !str_buf.empty()) {
get_battery_short_status(buf, 64, str_buf.c_str());
- if (buf[0] == 'D') return true;
+ if (buf[0] == 'D') {
+ return true;
+ }
str_buf = "";
}
}
return false;
}
-static void main_loop(void) {
+static void main_loop() {
int terminate = 0;
#ifdef SIGNAL_BLOCKING
sigset_t newmask, oldmask;
@@ -2096,14 +2148,15 @@ static void main_loop(void) {
if (out_to_x.get(*state)) {
/* allow only decorated windows to be given mouse input */
int major_version, minor_version;
- if (!XShapeQueryVersion(display, &major_version, &minor_version)) {
+ if (XShapeQueryVersion(display, &major_version, &minor_version) == 0) {
NORM_ERR("Input shapes are not supported");
} else {
if (own_window.get(*state) &&
(own_window_type.get(*state) != TYPE_NORMAL ||
- (TEST_HINT(own_window_hints.get(*state), HINT_UNDECORATED)))) {
- XShapeCombineRectangles(display, window.window, ShapeInput, 0, 0, NULL,
- 0, ShapeSet, Unsorted);
+ ((TEST_HINT(own_window_hints.get(*state), HINT_UNDECORATED)) !=
+ 0))) {
+ XShapeCombineRectangles(display, window.window, ShapeInput, 0, 0,
+ nullptr, 0, ShapeSet, Unsorted);
}
}
}
@@ -2115,14 +2168,15 @@ static void main_loop(void) {
info.looped = 0;
while (terminate == 0 && (total_run_times.get(*state) == 0 ||
info.looped < total_run_times.get(*state))) {
- if ((update_interval_on_battery.get(*state) != NOBATTERY))
+ if ((update_interval_on_battery.get(*state) != NOBATTERY)) {
on_battery = is_on_battery();
+ }
info.looped++;
#ifdef SIGNAL_BLOCKING
/* block signals. we will inspect for pending signals later */
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
- CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
+ CRIT_ERR(nullptr, NULL, "unable to sigprocmask()");
}
#endif
@@ -2132,20 +2186,20 @@ static void main_loop(void) {
/* wait for X event or timeout */
- if (!XPending(display)) {
+ if (XPending(display) == 0) {
fd_set fdsr;
- struct timeval tv;
+ struct timeval tv {};
int s;
t = next_update_time - get_time();
t = std::min(std::max(t, 0.0), active_update_interval());
- tv.tv_sec = (long)t;
- tv.tv_usec = (long)(t * 1000000) % 1000000;
+ tv.tv_sec = static_cast(t);
+ tv.tv_usec = static_cast(t * 1000000) % 1000000;
FD_ZERO(&fdsr);
FD_SET(ConnectionNumber(display), &fdsr);
- s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
+ s = select(ConnectionNumber(display) + 1, &fdsr, nullptr, nullptr, &tv);
if (s == -1) {
if (errno != EINTR) {
NORM_ERR("can't select(): %s", strerror(errno));
@@ -2158,7 +2212,7 @@ static void main_loop(void) {
}
}
- if (need_to_update) {
+ if (need_to_update != 0) {
#ifdef OWN_WINDOW
int wx = window.x, wy = window.y;
#endif
@@ -2173,7 +2227,7 @@ static void main_loop(void) {
int border_total = get_border_total();
/* resize window if it isn't right size */
- if (!fixed_size &&
+ if ((fixed_size == 0) &&
(text_width + 2 * border_total != window.width ||
text_height + 2 * border_total != window.height)) {
window.width = text_width + 2 * border_total;
@@ -2211,16 +2265,16 @@ static void main_loop(void) {
}
/* move window if it isn't in right position */
- if (!fixed_pos && (window.x != wx || window.y != wy)) {
+ if ((fixed_pos == 0) && (window.x != wx || window.y != wy)) {
XMoveWindow(display, window.window, window.x, window.y);
changed++;
}
/* update struts */
- if (changed && own_window_type.get(*state) == TYPE_PANEL) {
+ if ((changed != 0) && own_window_type.get(*state) == TYPE_PANEL) {
int sidenum = -1;
- fprintf(stderr, _(PACKAGE_NAME ": defining struts\n"));
+ fprintf(stderr, "%s", _(PACKAGE_NAME ": defining struts\n"));
fflush(stderr);
switch (text_alignment.get(*state)) {
@@ -2273,7 +2327,7 @@ static void main_loop(void) {
}
/* handle X events */
- while (XPending(display)) {
+ while (XPending(display) != 0) {
XEvent ev;
XNextEvent(display, &ev);
@@ -2330,7 +2384,8 @@ static void main_loop(void) {
{
XWindowAttributes attrs;
- if (XGetWindowAttributes(display, window.window, &attrs)) {
+ if (XGetWindowAttributes(display, window.window, &attrs) !=
+ 0) {
window.width = attrs.width;
window.height = attrs.height;
}
@@ -2369,7 +2424,7 @@ static void main_loop(void) {
own_window_type.get(*state) == TYPE_DESKTOP) {
/* allow conky to hold input focus. */
break;
- } else {
+ }
/* forward the click to the desktop window */
XUngrabPointer(display, ev.xbutton.time);
ev.xbutton.window = window.desktop;
@@ -2379,7 +2434,6 @@ static void main_loop(void) {
&ev);
XSetInputFocus(display, ev.xbutton.window, RevertToParent,
ev.xbutton.time);
- }
}
break;
@@ -2391,14 +2445,13 @@ static void main_loop(void) {
HINT_UNDECORATED)) {
/* allow conky to hold input focus. */
break;
- } else {
+ }
/* forward the release to the desktop window */
ev.xbutton.window = window.desktop;
ev.xbutton.x = ev.xbutton.x_root;
ev.xbutton.y = ev.xbutton.y_root;
XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask,
&ev);
- }
}
break;
@@ -2407,7 +2460,7 @@ static void main_loop(void) {
default:
#ifdef BUILD_XDAMAGE
if (ev.type == x11_stuff.event_base + XDamageNotify) {
- XDamageNotifyEvent *dev = (XDamageNotifyEvent *)&ev;
+ auto *dev = reinterpret_cast(&ev);
XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2,
@@ -2420,7 +2473,7 @@ static void main_loop(void) {
#ifdef BUILD_XDAMAGE
XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
- XFixesSetRegion(display, x11_stuff.region2, 0, 0);
+ XFixesSetRegion(display, x11_stuff.region2, nullptr, 0);
#endif /* BUILD_XDAMAGE */
/* XDBE doesn't seem to provide a way to clear the back buffer
@@ -2430,7 +2483,7 @@ static void main_loop(void) {
* the exposed area. OTOH, if we're not going to call draw_stuff at
* all, then no swap happens and we can safely do nothing. */
- if (!XEmptyRegion(x11_stuff.region)) {
+ if (XEmptyRegion(x11_stuff.region) == 0) {
#if defined(BUILD_XDBE)
if (use_xdbe.get(*state)) {
#else
@@ -2458,7 +2511,9 @@ static void main_loop(void) {
} else {
#endif /* BUILD_X11 */
t = (next_update_time - get_time()) * 1000000;
- if (t > 0) usleep((useconds_t)t);
+ if (t > 0) {
+ usleep(static_cast(t));
+ }
update_text();
draw_stuff();
#ifdef BUILD_NCURSES
@@ -2473,20 +2528,20 @@ static void main_loop(void) {
#ifdef SIGNAL_BLOCKING
/* unblock signals of interest and let handler fly */
- if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
- CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
+ if (sigprocmask(SIG_SETMASK, &oldmask, nullptr) < 0) {
+ CRIT_ERR(nullptr, NULL, "unable to sigprocmask()");
}
#endif
- if (g_sighup_pending) {
- g_sighup_pending = false;
+ if (g_sighup_pending != 0) {
+ g_sighup_pending = 0;
NORM_ERR("received SIGHUP or SIGUSR1. reloading the config file.");
reload_config();
}
- if (g_sigusr2_pending) {
- g_sigusr2_pending = false;
+ if (g_sigusr2_pending != 0) {
+ g_sigusr2_pending = 0;
// refresh view;
NORM_ERR("recieved SIGUSR2. refreshing.");
update_text();
@@ -2499,14 +2554,14 @@ static void main_loop(void) {
#endif
}
- if (g_sigterm_pending) {
- g_sigterm_pending = false;
+ if (g_sigterm_pending != 0) {
+ g_sigterm_pending = 0;
NORM_ERR("received SIGINT or SIGTERM to terminate. bye!");
terminate = 1;
#ifdef BUILD_X11
if (out_to_x.get(*state)) {
XDestroyRegion(x11_stuff.region);
- x11_stuff.region = NULL;
+ x11_stuff.region = nullptr;
#ifdef BUILD_XDAMAGE
XDamageDestroy(display, x11_stuff.damage);
XFixesDestroyRegion(display, x11_stuff.region2);
@@ -2532,7 +2587,7 @@ static void main_loop(void) {
time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
- select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
+ select(inotify_fd + 1, &descriptors, nullptr, NULL, &time_to_wait);
if (FD_ISSET(inotify_fd, &descriptors)) {
/* process inotify events */
len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN - 1);
@@ -2566,7 +2621,7 @@ static void main_loop(void) {
llua_update_info(&info, active_update_interval());
}
- clean_up(NULL, NULL);
+ clean_up(nullptr, nullptr);
#ifdef HAVE_SYS_INOTIFY_H
if (inotify_fd != -1) {
@@ -2580,9 +2635,9 @@ static void main_loop(void) {
void initialisation(int argc, char **argv);
/* reload the config file */
-static void reload_config(void) {
- struct stat sb;
- if (stat(current_config.c_str(), &sb) ||
+static void reload_config() {
+ struct stat sb {};
+ if ((stat(current_config.c_str(), &sb) != 0) ||
(!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
NORM_ERR(_("Config file '%s' is gone, continuing with config from "
"memory.\nIf you recreate this file sent me a SIGUSR1 to tell "
@@ -2590,15 +2645,15 @@ static void reload_config(void) {
current_config.c_str(), getpid());
return;
}
- clean_up(NULL, NULL);
- state.reset(new lua::state);
+ clean_up(nullptr, nullptr);
+ state = std::make_unique();
conky::export_symbols(*state);
sleep(1); /* slight pause */
initialisation(argc_copy, argv_copy);
}
#ifdef BUILD_X11
-void clean_up_x11(void) {
+void clean_up_x11() {
if (window_created == 1) {
int border_total = get_border_total();
@@ -2608,19 +2663,21 @@ void clean_up_x11(void) {
}
destroy_window();
free_fonts(utf8_mode.get(*state));
- if (x11_stuff.region) {
+ if (x11_stuff.region != nullptr) {
XDestroyRegion(x11_stuff.region);
- x11_stuff.region = NULL;
+ x11_stuff.region = nullptr;
}
}
#endif
void free_specials(special_t *¤t) {
- if (current) {
+ if (current != nullptr) {
free_specials(current->next);
- if (current->type == GRAPH) free(current->graph);
+ if (current->type == GRAPH) {
+ free(current->graph);
+ }
delete current;
- current = NULL;
+ current = nullptr;
}
}
@@ -2630,16 +2687,17 @@ void clean_up_without_threads(void *memtofree1, void *memtofree2) {
free_and_zero(info.cpu_usage);
#ifdef BUILD_X11
- if (out_to_x.get(*state))
+ if (out_to_x.get(*state)) {
clean_up_x11();
- else
+ } else {
fonts.clear(); // in set_default_configurations a font is set but not
- // loaded
+ }
+ // loaded
#endif /* BUILD_X11 */
- if (info.first_process) {
+ if (info.first_process != nullptr) {
free_all_processes();
- info.first_process = NULL;
+ info.first_process = nullptr;
}
free_text_objects(&global_root_object);
@@ -2672,7 +2730,7 @@ void clean_up(void *memtofree1, void *memtofree2) {
clean_up_without_threads(memtofree1, memtofree2);
}
-static void set_default_configurations(void) {
+static void set_default_configurations() {
update_uname();
info.memmax = 0;
top_cpu = 0;
@@ -2683,14 +2741,14 @@ static void set_default_configurations(void) {
#endif
top_running = 0;
#ifdef BUILD_XMMS2
- info.xmms2.artist = NULL;
- info.xmms2.album = NULL;
- info.xmms2.title = NULL;
- info.xmms2.genre = NULL;
- info.xmms2.comment = NULL;
- info.xmms2.url = NULL;
- info.xmms2.status = NULL;
- info.xmms2.playlist = NULL;
+ info.xmms2.artist = nullptr;
+ info.xmms2.album = nullptr;
+ info.xmms2.title = nullptr;
+ info.xmms2.genre = nullptr;
+ info.xmms2.comment = nullptr;
+ info.xmms2.url = nullptr;
+ info.xmms2.status = nullptr;
+ info.xmms2.playlist = nullptr;
#endif /* BUILD_XMMS2 */
state->pushboolean(true);
#ifdef BUILD_X11
@@ -2703,7 +2761,7 @@ static void set_default_configurations(void) {
}
#ifdef BUILD_X11
-static void X11_create_window(void) {
+static void X11_create_window() {
if (out_to_x.get(*state)) {
setup_fonts();
load_fonts(utf8_mode.get(*state));
@@ -2711,8 +2769,9 @@ static void X11_create_window(void) {
#ifdef OWN_WINDOW
if (own_window.get(*state)) {
- if (not fixed_pos)
+ if (fixed_pos == 0) {
XMoveWindow(display, window.window, window.x, window.y);
+ }
set_transparent_background(window.window);
}
@@ -2724,8 +2783,8 @@ static void X11_create_window(void) {
x11_stuff.region = XCreateRegion();
#ifdef BUILD_XDAMAGE
- if (!XDamageQueryExtension(display, &x11_stuff.event_base,
- &x11_stuff.error_base)) {
+ if (XDamageQueryExtension(display, &x11_stuff.event_base,
+ &x11_stuff.error_base) == 0) {
NORM_ERR("Xdamage extension unavailable");
}
x11_stuff.damage =
@@ -2751,11 +2810,12 @@ void load_config_file() {
try {
#ifdef BUILD_BUILTIN_CONFIG
- if (current_config == builtin_config_magic)
+ if (current_config == builtin_config_magic) {
l.loadstring(defconfig);
- else
+ } else {
#endif
l.loadfile(current_config.c_str());
+ }
} catch (lua::syntax_error &e) {
#define SYNTAX_ERR_READ_CONF "Syntax error (%s) while reading config file. "
#ifdef BUILD_OLD_CONFIG
@@ -2778,8 +2838,9 @@ void load_config_file() {
l.getglobal("conky");
l.getfield(-1, "text");
l.replace(-2);
- if (l.type(-1) != lua::TSTRING)
+ if (l.type(-1) != lua::TSTRING) {
throw conky::error(_("missing text block in configuration"));
+ }
/* Remove \\-\n. */
l.gsub(l.tocstring(-1), "\\\n", "");
@@ -2880,43 +2941,48 @@ static const char *getopt_string =
;
static const struct option longopts[] = {
- {"help", 0, NULL, 'h'}, {"version", 0, NULL, 'V'},
- {"quiet", 0, NULL, 'q'}, {"debug", 0, NULL, 'D'},
- {"config", 1, NULL, 'c'},
+ {"help", 0, nullptr, 'h'}, {"version", 0, nullptr, 'V'},
+ {"quiet", 0, nullptr, 'q'}, {"debug", 0, nullptr, 'D'},
+ {"config", 1, nullptr, 'c'},
#ifdef BUILD_BUILTIN_CONFIG
- {"print-config", 0, NULL, 'C'},
+ {"print-config", 0, nullptr, 'C'},
#endif
- {"daemonize", 0, NULL, 'd'},
+ {"daemonize", 0, nullptr, 'd'},
#ifdef BUILD_X11
- {"alignment", 1, NULL, 'a'}, {"font", 1, NULL, 'f'},
- {"display", 1, NULL, 'X'},
+ {"alignment", 1, nullptr, 'a'}, {"font", 1, nullptr, 'f'},
+ {"display", 1, nullptr, 'X'},
#ifdef OWN_WINDOW
- {"own-window", 0, NULL, 'o'},
+ {"own-window", 0, nullptr, 'o'},
#endif
- {"double-buffer", 0, NULL, 'b'}, {"window-id", 1, NULL, 'w'},
+ {"double-buffer", 0, nullptr, 'b'}, {"window-id", 1, nullptr, 'w'},
#endif /* BUILD_X11 */
- {"text", 1, NULL, 't'}, {"interval", 1, NULL, 'u'},
- {"pause", 1, NULL, 'p'}, {0, 0, 0, 0}};
+ {"text", 1, nullptr, 't'}, {"interval", 1, nullptr, 'u'},
+ {"pause", 1, nullptr, 'p'}, {nullptr, 0, nullptr, 0}};
void set_current_config() {
/* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
- struct stat s;
+ struct stat s {};
if (current_config.empty()) {
/* Try to use personal config file first */
std::string buf = to_real_path(XDG_CONFIG_FILE);
- if (stat(buf.c_str(), &s) == 0) current_config = buf;
+ if (stat(buf.c_str(), &s) == 0) {
+ current_config = buf;
+ }
}
if (current_config.empty()) {
/* Try to use personal config file first */
std::string buf = to_real_path(CONFIG_FILE);
- if (stat(buf.c_str(), &s) == 0) current_config = buf;
+ if (stat(buf.c_str(), &s) == 0) {
+ current_config = buf;
+ }
}
/* Try to use system config file if personal config does not exist */
- if (current_config.empty() && (stat(SYSTEM_CONFIG_FILE, &s) == 0))
+ if (current_config.empty() && (stat(SYSTEM_CONFIG_FILE, &s) == 0)) {
current_config = SYSTEM_CONFIG_FILE;
+ }
/* No readable config found */
if (current_config.empty()) {
@@ -2930,11 +2996,14 @@ void set_current_config() {
}
// "-" stands for "read from stdin"
- if (current_config == "-") current_config = "/dev/stdin";
+ if (current_config == "-") {
+ current_config = "/dev/stdin";
+ }
}
void initialisation(int argc, char **argv) {
- struct sigaction act, oact;
+ struct sigaction act {
+ }, oact{};
clear_net_stats();
set_default_configurations();
@@ -2948,13 +3017,13 @@ void initialisation(int argc, char **argv) {
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
- "kvm_open")) == NULL) {
- CRIT_ERR(NULL, NULL, "cannot read kvm");
+ "kvm_open")) == nullptr) {
+ CRIT_ERR(nullptr, NULL, "cannot read kvm");
}
#endif
while (1) {
- int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
+ int c = getopt_long(argc, argv, getopt_string, longopts, nullptr);
int startup_pause;
char *conv_end;
@@ -3008,7 +3077,7 @@ void initialisation(int argc, char **argv) {
case 'u':
state->pushinteger(strtol(optarg, &conv_end, 10));
if (*conv_end != 0) {
- CRIT_ERR(NULL, NULL, "'%s' is a wrong update-interval", optarg);
+ CRIT_ERR(nullptr, nullptr, "'%s' is a wrong update-interval", optarg);
}
update_interval.lua_set(*state);
break;
@@ -3016,7 +3085,7 @@ void initialisation(int argc, char **argv) {
case 'i':
state->pushinteger(strtol(optarg, &conv_end, 10));
if (*conv_end != 0) {
- CRIT_ERR(NULL, NULL, "'%s' is a wrong number of update-times",
+ CRIT_ERR(nullptr, nullptr, "'%s' is a wrong number of update-times",
optarg);
}
total_run_times.lua_set(*state);
@@ -3025,7 +3094,7 @@ void initialisation(int argc, char **argv) {
case 'x':
state->pushinteger(strtol(optarg, &conv_end, 10));
if (*conv_end != 0) {
- CRIT_ERR(NULL, NULL, "'%s' is a wrong value for the X-position",
+ CRIT_ERR(nullptr, nullptr, "'%s' is a wrong value for the X-position",
optarg);
}
gap_x.lua_set(*state);
@@ -3034,14 +3103,14 @@ void initialisation(int argc, char **argv) {
case 'y':
state->pushinteger(strtol(optarg, &conv_end, 10));
if (*conv_end != 0) {
- CRIT_ERR(NULL, NULL, "'%s' is a wrong value for the Y-position",
+ CRIT_ERR(nullptr, nullptr, "'%s' is a wrong value for the Y-position",
optarg);
}
gap_y.lua_set(*state);
break;
#endif /* BUILD_X11 */
case 'p':
- if (first_pass) {
+ if (first_pass != 0) {
startup_pause = atoi(optarg);
sleep(startup_pause);
}
@@ -3064,7 +3133,7 @@ void initialisation(int argc, char **argv) {
extract_variable_text(global_text);
free_and_zero(global_text);
/* fork */
- if (fork_to_background.get(*state) && first_pass) {
+ if (fork_to_background.get(*state) && (first_pass != 0)) {
int pid = fork();
switch (pid) {
@@ -3089,11 +3158,11 @@ void initialisation(int argc, char **argv) {
}
}
- text_buffer = (char *)malloc(max_user_text.get(*state));
+ text_buffer = static_cast(malloc(max_user_text.get(*state)));
memset(text_buffer, 0, max_user_text.get(*state));
- tmpstring1 = (char *)malloc(text_buffer_size.get(*state));
+ tmpstring1 = static_cast(malloc(text_buffer_size.get(*state)));
memset(tmpstring1, 0, text_buffer_size.get(*state));
- tmpstring2 = (char *)malloc(text_buffer_size.get(*state));
+ tmpstring2 = static_cast(malloc(text_buffer_size.get(*state)));
memset(tmpstring2, 0, text_buffer_size.get(*state));
#ifdef BUILD_X11
@@ -3132,9 +3201,9 @@ int main(int argc, char **argv) {
#endif
argc_copy = argc;
argv_copy = argv;
- g_sigterm_pending = false;
- g_sighup_pending = false;
- g_sigusr2_pending = false;
+ g_sigterm_pending = 0;
+ g_sighup_pending = 0;
+ g_sigusr2_pending = 0;
#ifdef BUILD_CURL
struct curl_global_initializer {
@@ -3156,7 +3225,7 @@ int main(int argc, char **argv) {
}
#endif /* BUILD_X11 */
while (1) {
- int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
+ int c = getopt_long(argc, argv, getopt_string, longopts, nullptr);
if (c == -1) {
break;
@@ -3174,8 +3243,8 @@ int main(int argc, char **argv) {
current_config = optarg;
break;
case 'q':
- if (!freopen("/dev/null", "w", stderr))
- CRIT_ERR(0, 0, "could not open /dev/null as stderr!");
+ if (freopen("/dev/null", "w", stderr) == nullptr)
+ CRIT_ERR(nullptr, nullptr, "could not open /dev/null as stderr!");
break;
case 'h':
print_help(argv[0]);
@@ -3187,7 +3256,7 @@ int main(int argc, char **argv) {
#endif
#ifdef BUILD_X11
case 'w':
- window.window = strtol(optarg, 0, 0);
+ window.window = strtol(optarg, nullptr, 0);
break;
#endif /* BUILD_X11 */
@@ -3199,7 +3268,7 @@ int main(int argc, char **argv) {
try {
set_current_config();
- state.reset(new lua::state);
+ state = std::make_unique();
conky::export_symbols(*state);
@@ -3229,7 +3298,7 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
} catch (obj_create_error &e) {
std::cerr << e.what() << std::endl;
- clean_up(NULL, NULL);
+ clean_up(nullptr, nullptr);
return EXIT_FAILURE;
} catch (std::exception &e) {
std::cerr << PACKAGE_NAME ": " << e.what() << std::endl;
@@ -3254,14 +3323,14 @@ static void signal_handler(int sig) {
switch (sig) {
case SIGINT:
case SIGTERM:
- g_sigterm_pending = true;
+ g_sigterm_pending = 1;
break;
case SIGHUP:
case SIGUSR1:
- g_sighup_pending = true;
+ g_sighup_pending = 1;
break;
case SIGUSR2:
- g_sigusr2_pending = true;
+ g_sigusr2_pending = 1;
default:
/* Reaching here means someone set a signal
* (SIGXXXX, signal_handler), but didn't write any code
diff --git a/src/conky.h b/src/conky.h
index 4db04e96..a51a2351 100644
--- a/src/conky.h
+++ b/src/conky.h
@@ -360,7 +360,7 @@ template
void free_and_zero(T *&ptr) {
if (ptr) {
free(ptr);
- ptr = NULL;
+ ptr = nullptr;
}
}
diff --git a/src/core.cc b/src/core.cc
index 762c6227..db19e86a 100644
--- a/src/core.cc
+++ b/src/core.cc
@@ -118,8 +118,8 @@
#include "darwin.h"
#endif
-#include
-#include
+#include
+#include
/* strip a leading /dev/ if any, following symlinks first
*
@@ -130,17 +130,21 @@
const char *dev_name(const char *path) {
static char buf[PATH_MAX];
- if (!path) return NULL;
+ if (path == nullptr) {
+ return nullptr;
+ }
#define DEV_NAME(x) \
- x != NULL &&strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
- if (realpath(path, buf) == NULL) return DEV_NAME(path);
+ ((x) != nullptr && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? (x) + 5 : (x))
+ if (realpath(path, buf) == nullptr) {
+ return DEV_NAME(path);
+ }
return DEV_NAME(buf);
#undef DEV_NAME
}
-static struct text_object *new_text_object_internal(void) {
- struct text_object *obj = (text_object *)malloc(sizeof(struct text_object));
+static struct text_object *new_text_object_internal() {
+ auto *obj = static_cast(malloc(sizeof(struct text_object)));
memset(obj, 0, sizeof(struct text_object));
return obj;
}
@@ -148,8 +152,8 @@ static struct text_object *new_text_object_internal(void) {
static struct text_object *create_plain_text(const char *s) {
struct text_object *obj;
- if (s == NULL || *s == '\0') {
- return NULL;
+ if (s == nullptr || *s == '\0') {
+ return nullptr;
}
obj = new_text_object_internal();
@@ -163,7 +167,7 @@ void stock_parse_arg(struct text_object *obj, const char *arg) {
char stock[8];
char data[16];
- obj->data.s = NULL;
+ obj->data.s = nullptr;
if (sscanf(arg, "%7s %15s", stock, data) != 2) {
NORM_ERR("wrong number of arguments for $stock");
return;
@@ -356,10 +360,10 @@ void stock_parse_arg(struct text_object *obj, const char *arg) {
#endif /* BUILD_CURL */
legacy_cb_handle *create_cb_handle(int (*fn)()) {
- if (fn)
+ if (fn != nullptr) {
return new legacy_cb_handle(conky::register_cb(1, fn));
- else
- return NULL;
+ }
+ { return nullptr; }
}
/* construct_text_object() creates a new text_object */
@@ -403,13 +407,13 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
} else
#endif /* BUILD_X11 */
#ifndef __OpenBSD__
- OBJ(acpitemp, 0)
+ OBJ(acpitemp, nullptr)
obj->data.i = open_acpi_temperature(arg);
obj->callbacks.print = &print_acpitemp;
obj->callbacks.free = &free_acpitemp;
- END OBJ(acpiacadapter, 0) if (arg) {
+ END OBJ(acpiacadapter, nullptr) if (arg != nullptr) {
#ifdef __linux__
- if (strpbrk(arg, "/.") != NULL) {
+ if (strpbrk(arg, "/.") != nullptr) {
/*
* a bit of paranoia. screen out funky paths
* i hope no device will have a '.' in its name
@@ -424,9 +428,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.print = &print_acpiacadapter;
obj->callbacks.free = &gen_free_opaque;
#endif /* !__OpenBSD__ */
- END OBJ(freq, 0) get_cpu_count();
- if (!arg || !isdigit(arg[0]) || strlen(arg) >= 3 || atoi(&arg[0]) == 0 ||
- atoi(&arg[0]) > info.cpu_count) {
+ END OBJ(freq, nullptr) get_cpu_count();
+ if ((arg == nullptr) || (isdigit(arg[0]) == 0) || strlen(arg) >= 3 ||
+ atoi(&arg[0]) == 0 || atoi(&arg[0]) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
"Displaying the clock for CPU 1."); */
@@ -434,9 +438,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.i = atoi(&arg[0]);
}
obj->callbacks.print = &print_freq;
- END OBJ(freq_g, 0) get_cpu_count();
- if (!arg || !isdigit(arg[0]) || strlen(arg) >= 3 || atoi(&arg[0]) == 0 ||
- atoi(&arg[0]) > info.cpu_count) {
+ END OBJ(freq_g, nullptr) get_cpu_count();
+ if ((arg == nullptr) || (isdigit(arg[0]) == 0) || strlen(arg) >= 3 ||
+ atoi(&arg[0]) == 0 || atoi(&arg[0]) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
"CPUs! Displaying the clock for CPU 1."); */
@@ -444,15 +448,18 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.i = atoi(&arg[0]);
}
obj->callbacks.print = &print_freq_g;
- END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
+ END OBJ_ARG(read_tcp, nullptr,
+ "read_tcp: Needs \"(host) port\" as argument(s)")
parse_read_tcpip_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_read_tcp;
obj->callbacks.free = &free_read_tcpip;
- END OBJ_ARG(read_udp, 0, "read_udp: Needs \"(host) port\" as argument(s)")
+ END OBJ_ARG(read_udp, nullptr,
+ "read_udp: Needs \"(host) port\" as argument(s)")
parse_read_tcpip_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_read_udp;
obj->callbacks.free = &free_read_tcpip;
- END OBJ_ARG(tcp_ping, 0, "tcp_ping: Needs \"host (port)\" as argument(s)")
+ END OBJ_ARG(tcp_ping, nullptr,
+ "tcp_ping: Needs \"host (port)\" as argument(s)")
parse_tcp_ping_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_tcp_ping;
obj->callbacks.free = &free_tcp_ping;
@@ -514,10 +521,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#endif /* __linux__ */
#ifndef __OpenBSD__
- END OBJ(acpifan, 0) obj->callbacks.print = &print_acpifan;
- END OBJ(battery, 0) char bat[64];
+ END OBJ(acpifan, nullptr) obj->callbacks.print = &print_acpifan;
+ END OBJ(battery, nullptr) char bat[64];
- if (arg) {
+ if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strcpy(bat, "BAT0");
@@ -525,9 +532,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.print = &print_battery;
obj->callbacks.free = &gen_free_opaque;
- END OBJ(battery_short, 0) char bat[64];
+ END OBJ(battery_short, nullptr) char bat[64];
- if (arg) {
+ if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strcpy(bat, "BAT0");
@@ -535,9 +542,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.print = &print_battery_short;
obj->callbacks.free = &gen_free_opaque;
- END OBJ(battery_time, 0) char bat[64];
+ END OBJ(battery_time, nullptr) char bat[64];
- if (arg) {
+ if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strcpy(bat, "BAT0");
@@ -545,9 +552,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.print = &print_battery_time;
obj->callbacks.free = &gen_free_opaque;
- END OBJ(battery_percent, 0) char bat[64];
+ END OBJ(battery_percent, nullptr) char bat[64];
- if (arg) {
+ if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strcpy(bat, "BAT0");
@@ -555,10 +562,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.percentage = &battery_percentage;
obj->callbacks.free = &gen_free_opaque;
- END OBJ(battery_bar, 0) char bat[64];
+ END OBJ(battery_bar, nullptr) char bat[64];
arg = scan_bar(obj, arg, 100);
- if (arg && strlen(arg) > 0) {
+ if ((arg != nullptr) && strlen(arg) > 0) {
sscanf(arg, "%63s", bat);
} else {
strcpy(bat, "BAT0");
@@ -633,7 +640,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#endif /* __linux__ */
#if (defined(__FreeBSD__) || defined(__linux__) || defined(__DragonFly__) || \
(defined(__APPLE__) && defined(__MACH__)))
- END OBJ_IF_ARG(if_up, 0, "if_up needs an argument") parse_if_up_arg(obj, arg);
+ END OBJ_IF_ARG(if_up, nullptr, "if_up needs an argument")
+ parse_if_up_arg(obj, arg);
obj->callbacks.iftest = &interface_up;
obj->callbacks.free = &free_if_up;
#endif
@@ -654,13 +662,13 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#endif /* __OpenBSD__ */
END OBJ(buffers, &update_meminfo) obj->callbacks.print = &print_buffers;
END OBJ(cached, &update_meminfo) obj->callbacks.print = &print_cached;
-#define SCAN_CPU(__arg, __var) \
- { \
- int __offset = 0; \
- if (__arg && sscanf(__arg, " cpu%d %n", &__var, &__offset) > 0) \
- __arg += __offset; \
- else \
- __var = 0; \
+#define SCAN_CPU(__arg, __var) \
+ { \
+ int __offset = 0; \
+ if ((__arg) && sscanf(__arg, " cpu%d %n", &(__var), &__offset) > 0) \
+ (__arg) += __offset; \
+ else \
+ (__var) = 0; \
}
END OBJ(cpu, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
@@ -680,7 +688,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
DBGP2("Adding $cpubar for CPU %d", obj->data.i);
#ifdef BUILD_X11
END OBJ(cpugraph, &update_cpu_usage) get_cpu_count();
- char *buf = 0;
+ char *buf = nullptr;
SCAN_CPU(arg, obj->data.i);
buf = scan_graph(obj, arg, 1);
DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
@@ -703,17 +711,18 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(diskiograph_write, &update_diskio) parse_diskiograph_arg(obj, arg);
obj->callbacks.graphval = &diskiographval_write;
#endif /* BUILD_X11 */
- END OBJ(color, 0)
+ END OBJ(color, nullptr)
#ifdef BUILD_X11
if (out_to_x.get(*state)) {
- obj->data.l = arg ? get_x11_color(arg) : default_color.get(*state);
+ obj->data.l =
+ arg != nullptr ? get_x11_color(arg) : default_color.get(*state);
set_current_text_color(obj->data.l);
}
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (out_to_ncurses.get(*state)) {
obj->data.l = COLOR_WHITE;
- if (arg) {
+ if (arg != nullptr) {
if (strcasecmp(arg, "red") == 0) {
obj->data.l = COLOR_RED;
} else if (strcasecmp(arg, "green") == 0) {
@@ -736,43 +745,43 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#endif /* BUILD_NCURSES */
obj->callbacks.print = &new_fg;
#ifdef BUILD_X11
- END OBJ(color0, 0) obj->data.l = color[0].get(*state);
+ END OBJ(color0, nullptr) obj->data.l = color[0].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color1, 0) obj->data.l = color[1].get(*state);
+ END OBJ(color1, nullptr) obj->data.l = color[1].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color2, 0) obj->data.l = color[2].get(*state);
+ END OBJ(color2, nullptr) obj->data.l = color[2].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color3, 0) obj->data.l = color[3].get(*state);
+ END OBJ(color3, nullptr) obj->data.l = color[3].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color4, 0) obj->data.l = color[4].get(*state);
+ END OBJ(color4, nullptr) obj->data.l = color[4].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color5, 0) obj->data.l = color[5].get(*state);
+ END OBJ(color5, nullptr) obj->data.l = color[5].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color6, 0) obj->data.l = color[6].get(*state);
+ END OBJ(color6, nullptr) obj->data.l = color[6].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color7, 0) obj->data.l = color[7].get(*state);
+ END OBJ(color7, nullptr) obj->data.l = color[7].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color8, 0) obj->data.l = color[8].get(*state);
+ END OBJ(color8, nullptr) obj->data.l = color[8].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(color9, 0) obj->data.l = color[9].get(*state);
+ END OBJ(color9, nullptr) obj->data.l = color[9].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
- END OBJ(font, 0) scan_font(obj, arg);
+ END OBJ(font, nullptr) scan_font(obj, arg);
obj->callbacks.print = &new_font;
obj->callbacks.free = &gen_free_opaque;
#endif /* BUILD_X11 */
- END OBJ(conky_version, 0) obj_be_plain_text(obj, VERSION);
- END OBJ(conky_build_date, 0) obj_be_plain_text(obj, BUILD_DATE);
- END OBJ(conky_build_arch, 0) obj_be_plain_text(obj, BUILD_ARCH);
+ END OBJ(conky_version, nullptr) obj_be_plain_text(obj, VERSION);
+ END OBJ(conky_build_date, nullptr) obj_be_plain_text(obj, BUILD_DATE);
+ END OBJ(conky_build_arch, nullptr) obj_be_plain_text(obj, BUILD_ARCH);
END OBJ(downspeed, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_downspeed;
@@ -784,17 +793,17 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
parse_net_stat_graph_arg(obj, arg, free_at_crash);
obj->callbacks.graphval = &downspeedgraphval;
#endif /* BUILD_X11 */
- END OBJ(else, 0) obj_be_ifblock_else(ifblock_opaque, obj);
+ END OBJ(else, nullptr) obj_be_ifblock_else(ifblock_opaque, obj);
obj->callbacks.iftest = &gen_false_iftest;
- END OBJ(endif, 0) obj_be_ifblock_endif(ifblock_opaque, obj);
+ END OBJ(endif, nullptr) obj_be_ifblock_endif(ifblock_opaque, obj);
obj->callbacks.print = &gen_print_nothing;
- END OBJ(eval, 0) obj->data.s =
- strndup(arg ? arg : "", text_buffer_size.get(*state));
+ END OBJ(eval, nullptr) obj->data.s =
+ strndup(arg != nullptr ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_evaluate;
obj->callbacks.free = &gen_free_opaque;
#if defined(BUILD_IMLIB2) && defined(BUILD_X11)
- END OBJ(image, 0) obj->data.s =
- strndup(arg ? arg : "", text_buffer_size.get(*state));
+ END OBJ(image, nullptr) obj->data.s =
+ strndup(arg != nullptr ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_image_callback;
obj->callbacks.free = &gen_free_opaque;
#endif /* BUILD_IMLIB2 */
@@ -802,71 +811,72 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ_ARG(mysql, 0, "mysql needs a query") obj->data.s = strdup(arg);
obj->callbacks.print = &print_mysql;
#endif /* BUILD_MYSQL */
- END OBJ_ARG(no_update, 0, "no_update needs arguments")
+ END OBJ_ARG(no_update, nullptr, "no_update needs arguments")
scan_no_update(obj, arg);
obj->callbacks.print = &print_no_update;
obj->callbacks.free = &free_no_update;
- END OBJ_ARG(exec, 0, "exec needs arguments: ")
+ END OBJ_ARG(exec, nullptr, "exec needs arguments: ")
scan_exec_arg(obj, arg, EF_EXEC);
obj->parse = false;
obj->thread = false;
register_exec(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_exec;
- END OBJ_ARG(execi, 0, "execi needs arguments: ")
+ END OBJ_ARG(execi, nullptr, "execi needs arguments: ")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = false;
obj->thread = false;
register_execi(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_execi;
- END OBJ_ARG(execp, 0, "execp needs arguments: ")
+ END OBJ_ARG(execp, nullptr, "execp needs arguments: ")
scan_exec_arg(obj, arg, EF_EXEC);
obj->parse = true;
obj->thread = false;
register_exec(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_exec;
- END OBJ_ARG(execpi, 0, "execpi needs arguments: ")
+ END OBJ_ARG(execpi, nullptr, "execpi needs arguments: ")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = true;
obj->thread = false;
register_execi(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_execi;
- END OBJ_ARG(execbar, 0, "execbar needs arguments: [height],[width] ")
+ END OBJ_ARG(execbar, nullptr,
+ "execbar needs arguments: [height],[width] ")
scan_exec_arg(obj, arg, EF_EXEC | EF_BAR);
register_exec(obj);
obj->callbacks.barval = &execbarval;
obj->callbacks.free = &free_exec;
- END OBJ_ARG(execibar, 0,
+ END OBJ_ARG(execibar, nullptr,
"execibar needs arguments: [height],[width] ")
scan_exec_arg(obj, arg, EF_EXECI | EF_BAR);
register_execi(obj);
obj->callbacks.barval = &execbarval;
obj->callbacks.free = &free_execi;
#ifdef BUILD_X11
- END OBJ_ARG(execgauge, 0,
+ END OBJ_ARG(execgauge, nullptr,
"execgauge needs arguments: [height],[width] ")
scan_exec_arg(obj, arg, EF_EXEC | EF_GAUGE);
register_exec(obj);
obj->callbacks.gaugeval = &execbarval;
obj->callbacks.free = &free_exec;
END OBJ_ARG(
- execigauge, 0,
+ execigauge, nullptr,
"execigauge needs arguments: [height],[width] ")
scan_exec_arg(obj, arg, EF_EXECI | EF_GAUGE);
register_execi(obj);
obj->callbacks.gaugeval = &execbarval;
obj->callbacks.free = &free_execi;
- END OBJ_ARG(execgraph, 0,
+ END OBJ_ARG(execgraph, nullptr,
"execgraph needs arguments: [height],[width] [color1] "
"[color2] [scale] [-t|-l]")
scan_exec_arg(obj, arg, EF_EXEC | EF_GRAPH);
register_exec(obj);
obj->callbacks.graphval = &execbarval;
obj->callbacks.free = &free_exec;
- END OBJ_ARG(execigraph, 0,
+ END OBJ_ARG(execigraph, nullptr,
"execigraph needs arguments: "
"[height],[width] [color1] [color2] [scale] [-t|-l]")
scan_exec_arg(obj, arg, EF_EXECI | EF_GRAPH);
@@ -874,14 +884,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.graphval = &execbarval;
obj->callbacks.free = &free_execi;
#endif /* BUILD_X11 */
- END OBJ_ARG(texeci, 0, "texeci needs arguments: ")
+ END OBJ_ARG(texeci, nullptr, "texeci needs arguments: ")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = false;
obj->thread = true;
register_execi(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_execi;
- END OBJ_ARG(texecpi, 0, "texecpi needs arguments: ")
+ END OBJ_ARG(texecpi, nullptr, "texecpi needs arguments: ")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = true;
obj->thread = true;
@@ -905,20 +915,20 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(fs_used, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.print = &print_fs_used;
#ifdef BUILD_X11
- END OBJ(hr, 0) obj->data.l = arg ? atoi(arg) : 1;
+ END OBJ(hr, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
obj->callbacks.print = &new_hr;
#endif /* BUILD_X11 */
END OBJ(nameserver, &update_dns_data) parse_nameserver_arg(obj, arg);
obj->callbacks.print = &print_nameserver;
obj->callbacks.free = &free_dns_data;
- END OBJ(offset, 0) obj->data.l = arg ? atoi(arg) : 1;
+ END OBJ(offset, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
obj->callbacks.print = &new_offset;
- END OBJ(voffset, 0) obj->data.l = arg ? atoi(arg) : 1;
+ END OBJ(voffset, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
obj->callbacks.print = &new_voffset;
- END OBJ_ARG(goto, 0, "goto needs arguments") obj->data.l = atoi(arg);
+ END OBJ_ARG(goto, nullptr, "goto needs arguments") obj->data.l = atoi(arg);
obj->callbacks.print = &new_goto;
#ifdef BUILD_X11
- END OBJ(tab, 0) scan_tab(obj, arg);
+ END OBJ(tab, nullptr) scan_tab(obj, arg);
obj->callbacks.print = &new_tab;
#endif /* BUILD_X11 */
#ifdef __linux__
@@ -940,14 +950,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
/* XXX: maybe fiddle them apart later, as print_top() does
* nothing else than just that, using an ugly switch(). */
if (strncmp(s, "top", 3) == EQUAL) {
- if (parse_top_args(s, arg, obj)) {
+ if (parse_top_args(s, arg, obj) != 0) {
#ifdef __linux__
determine_longstat_file();
#endif
obj->cb_handle = create_cb_handle(update_top);
} else {
free(obj);
- return NULL;
+ return nullptr;
}
}
else OBJ(addr, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash);
@@ -963,33 +973,33 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#endif /* BUILD_IPV6 */
END
#endif /* __linux__ */
- OBJ_ARG(tail, 0, "tail needs arguments")
+ OBJ_ARG(tail, nullptr, "tail needs arguments")
init_tailhead("tail", arg, obj, free_at_crash);
obj->callbacks.print = &print_tail;
obj->callbacks.free = &free_tailhead;
- END OBJ_ARG(head, 0, "head needs arguments")
+ END OBJ_ARG(head, nullptr, "head needs arguments")
init_tailhead("head", arg, obj, free_at_crash);
obj->callbacks.print = &print_head;
obj->callbacks.free = &free_tailhead;
- END OBJ_ARG(lines, 0, "lines needs an argument") obj->data.s =
+ END OBJ_ARG(lines, nullptr, "lines needs an argument") obj->data.s =
strndup(arg, text_buffer_size.get(*state));
obj->callbacks.print = &print_lines;
obj->callbacks.free = &gen_free_opaque;
- END OBJ_ARG(words, 0, "words needs a argument") obj->data.s =
+ END OBJ_ARG(words, nullptr, "words needs a argument") obj->data.s =
strndup(arg, text_buffer_size.get(*state));
obj->callbacks.print = &print_words;
obj->callbacks.free = &gen_free_opaque;
END OBJ(loadavg, &update_load_average) scan_loadavg_arg(obj, arg);
obj->callbacks.print = &print_loadavg;
- END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument") obj->sub =
- (text_object *)malloc(sizeof(struct text_object));
+ END OBJ_IF_ARG(if_empty, nullptr, "if_empty needs an argument") obj->sub =
+ static_cast(malloc(sizeof(struct text_object)));
extract_variable_text_internal(obj->sub, arg);
obj->callbacks.iftest = &if_empty_iftest;
- END OBJ_IF_ARG(if_match, 0, "if_match needs arguments") obj->sub =
- (text_object *)malloc(sizeof(struct text_object));
+ END OBJ_IF_ARG(if_match, nullptr, "if_match needs arguments") obj->sub =
+ static_cast(malloc(sizeof(struct text_object)));
extract_variable_text_internal(obj->sub, arg);
obj->callbacks.iftest = &check_if_match;
- END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
+ END OBJ_IF_ARG(if_existing, nullptr, "if_existing needs an argument or two")
obj->data.s = strndup(arg, text_buffer_size.get(*state));
obj->callbacks.iftest = &if_existing_iftest;
obj->callbacks.free = &gen_free_opaque;
@@ -1004,14 +1014,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.iftest = &if_running_iftest;
obj->callbacks.free = &gen_free_opaque;
#elif defined(__APPLE__) && defined(__MACH__)
- END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument") obj->data.s =
- strndup(arg, text_buffer_size.get(*state));
+ END OBJ_IF_ARG(if_mounted, nullptr, "if_mounted needs an argument")
+ obj->data.s = strndup(arg, text_buffer_size.get(*state));
obj->callbacks.iftest = &check_mount;
obj->callbacks.free = &gen_free_opaque;
/* System Integrity Protection */
END OBJ(sip_status, &get_sip_status) obj->data.s =
- strndup(arg ? arg : "", text_buffer_size.get(*state));
+ strndup(arg != nullptr ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_sip_status;
obj->callbacks.free = &gen_free_opaque;
#else
@@ -1024,48 +1034,48 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
/* XXX: maybe use a different callback here */
obj->callbacks.iftest = &if_running_iftest;
#endif
- END OBJ(kernel, 0) obj->callbacks.print = &print_kernel;
- END OBJ(machine, 0) obj->callbacks.print = &print_machine;
+ END OBJ(kernel, nullptr) obj->callbacks.print = &print_kernel;
+ END OBJ(machine, nullptr) obj->callbacks.print = &print_machine;
#if defined(__DragonFly__)
END OBJ(version, 0) obj->callbacks.print = &print_version;
#endif
- END OBJ(mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(new_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(new_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_new_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(seen_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(seen_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_seen_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(unseen_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(unseen_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_unseen_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(flagged_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(flagged_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_flagged_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(unflagged_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(unflagged_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_unflagged_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(forwarded_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(forwarded_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_forwarded_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(unforwarded_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(unforwarded_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_unforwarded_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(replied_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(replied_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_replied_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(unreplied_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(unreplied_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_unreplied_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(draft_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(draft_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_draft_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(trashed_mails, 0) parse_local_mail_args(obj, arg);
+ END OBJ(trashed_mails, nullptr) parse_local_mail_args(obj, arg);
obj->callbacks.print = &print_trashed_mails;
obj->callbacks.free = &free_local_mails;
- END OBJ(mboxscan, 0) parse_mboxscan_arg(obj, arg);
+ END OBJ(mboxscan, nullptr) parse_mboxscan_arg(obj, arg);
obj->callbacks.print = &print_mboxscan;
obj->callbacks.free = &free_mboxscan;
END OBJ(mem, &update_meminfo) obj->callbacks.print = &print_mem;
@@ -1088,7 +1098,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(memwithbuffersbar, &update_meminfo) scan_bar(obj, arg, 1);
obj->callbacks.barval = &mem_with_buffers_barval;
#ifdef BUILD_X11
- END OBJ(memgraph, &update_meminfo) char *buf = 0;
+ END OBJ(memgraph, &update_meminfo) char *buf = nullptr;
buf = scan_graph(obj, arg, 1);
free_and_zero(buf);
@@ -1111,148 +1121,152 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.iftest = &check_mixer_muted;
#endif
#ifdef BUILD_X11
- END OBJ(monitor, 0) obj->callbacks.print = &print_monitor;
- END OBJ(monitor_number, 0) obj->callbacks.print = &print_monitor_number;
- END OBJ(desktop, 0) obj->callbacks.print = &print_desktop;
- END OBJ(desktop_number, 0) obj->callbacks.print = &print_desktop_number;
- END OBJ(desktop_name, 0) obj->callbacks.print = &print_desktop_name;
+ END OBJ(monitor, nullptr) obj->callbacks.print = &print_monitor;
+ END OBJ(monitor_number, nullptr) obj->callbacks.print = &print_monitor_number;
+ END OBJ(desktop, nullptr) obj->callbacks.print = &print_desktop;
+ END OBJ(desktop_number, nullptr) obj->callbacks.print = &print_desktop_number;
+ END OBJ(desktop_name, nullptr) obj->callbacks.print = &print_desktop_name;
#endif /* BUILD_X11 */
- END OBJ_ARG(format_time, 0, "format_time needs a pid as argument") obj->sub =
- (text_object *)malloc(sizeof(struct text_object));
+ END OBJ_ARG(format_time, nullptr, "format_time needs a pid as argument")
+ obj->sub = static_cast(malloc(sizeof(struct text_object)));
extract_variable_text_internal(obj->sub, arg);
obj->callbacks.print = &print_format_time;
- END OBJ(nodename, 0) obj->callbacks.print = &print_nodename;
- END OBJ(nodename_short, 0) obj->callbacks.print = &print_nodename_short;
- END OBJ_ARG(cmdline_to_pid, 0,
+ END OBJ(nodename, nullptr) obj->callbacks.print = &print_nodename;
+ END OBJ(nodename_short, nullptr) obj->callbacks.print = &print_nodename_short;
+ END OBJ_ARG(cmdline_to_pid, nullptr,
"cmdline_to_pid needs a command line as argument")
scan_cmdline_to_pid_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_cmdline_to_pid;
obj->callbacks.free = &gen_free_opaque;
- END OBJ_ARG(pid_chroot, 0, "pid_chroot needs a pid as argument")
+ END OBJ_ARG(pid_chroot, nullptr, "pid_chroot needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_chroot;
- END OBJ_ARG(pid_cmdline, 0, "pid_cmdline needs a pid as argument")
+ END OBJ_ARG(pid_cmdline, nullptr, "pid_cmdline needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_cmdline;
- END OBJ_ARG(pid_cwd, 0, "pid_cwd needs a pid as argument")
+ END OBJ_ARG(pid_cwd, nullptr, "pid_cwd needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_cwd;
- END OBJ_ARG(pid_environ, 0, "pid_environ needs arguments")
+ END OBJ_ARG(pid_environ, nullptr, "pid_environ needs arguments")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_environ;
- END OBJ_ARG(pid_environ_list, 0, "pid_environ_list needs a pid as argument")
+ END OBJ_ARG(pid_environ_list, nullptr,
+ "pid_environ_list needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_environ_list;
- END OBJ_ARG(pid_exe, 0, "pid_exe needs a pid as argument")
+ END OBJ_ARG(pid_exe, nullptr, "pid_exe needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_exe;
- END OBJ_ARG(pid_nice, 0, "pid_nice needs a pid as argument")
+ END OBJ_ARG(pid_nice, nullptr, "pid_nice needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_nice;
- END OBJ_ARG(pid_openfiles, 0, "pid_openfiles needs a pid as argument")
+ END OBJ_ARG(pid_openfiles, nullptr, "pid_openfiles needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_openfiles;
- END OBJ_ARG(pid_parent, 0, "pid_parent needs a pid as argument")
+ END OBJ_ARG(pid_parent, nullptr, "pid_parent needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_parent;
- END OBJ_ARG(pid_priority, 0, "pid_priority needs a pid as argument")
+ END OBJ_ARG(pid_priority, nullptr, "pid_priority needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_priority;
- END OBJ_ARG(pid_state, 0, "pid_state needs a pid as argument")
+ END OBJ_ARG(pid_state, nullptr, "pid_state needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_state;
- END OBJ_ARG(pid_state_short, 0, "pid_state_short needs a pid as argument")
+ END OBJ_ARG(pid_state_short, nullptr,
+ "pid_state_short needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_state_short;
- END OBJ_ARG(pid_stderr, 0, "pid_stderr needs a pid as argument")
+ END OBJ_ARG(pid_stderr, nullptr, "pid_stderr needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_stderr;
- END OBJ_ARG(pid_stdin, 0, "pid_stdin needs a pid as argument")
+ END OBJ_ARG(pid_stdin, nullptr, "pid_stdin needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_stdin;
- END OBJ_ARG(pid_stdout, 0, "pid_stdout needs a pid as argument")
+ END OBJ_ARG(pid_stdout, nullptr, "pid_stdout needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_stdout;
- END OBJ_ARG(pid_threads, 0, "pid_threads needs a pid as argument")
+ END OBJ_ARG(pid_threads, nullptr, "pid_threads needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_threads;
- END OBJ_ARG(pid_thread_list, 0, "pid_thread_list needs a pid as argument")
+ END OBJ_ARG(pid_thread_list, nullptr,
+ "pid_thread_list needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_thread_list;
- END OBJ_ARG(pid_time_kernelmode, 0,
+ END OBJ_ARG(pid_time_kernelmode, nullptr,
"pid_time_kernelmode needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_time_kernelmode;
- END OBJ_ARG(pid_time_usermode, 0, "pid_time_usermode needs a pid as argument")
+ END OBJ_ARG(pid_time_usermode, nullptr,
+ "pid_time_usermode needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_time_usermode;
- END OBJ_ARG(pid_time, 0, "pid_time needs a pid as argument")
+ END OBJ_ARG(pid_time, nullptr, "pid_time needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_time;
- END OBJ_ARG(pid_uid, 0, "pid_uid needs a pid as argument")
+ END OBJ_ARG(pid_uid, nullptr, "pid_uid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_uid;
- END OBJ_ARG(pid_euid, 0, "pid_euid needs a pid as argument")
+ END OBJ_ARG(pid_euid, nullptr, "pid_euid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_euid;
- END OBJ_ARG(pid_suid, 0, "pid_suid needs a pid as argument")
+ END OBJ_ARG(pid_suid, nullptr, "pid_suid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_suid;
- END OBJ_ARG(pid_fsuid, 0, "pid_fsuid needs a pid as argument")
+ END OBJ_ARG(pid_fsuid, nullptr, "pid_fsuid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_fsuid;
- END OBJ_ARG(pid_gid, 0, "pid_gid needs a pid as argument")
+ END OBJ_ARG(pid_gid, nullptr, "pid_gid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_gid;
- END OBJ_ARG(pid_egid, 0, "pid_egid needs a pid as argument")
+ END OBJ_ARG(pid_egid, nullptr, "pid_egid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_egid;
- END OBJ_ARG(pid_sgid, 0, "pid_sgid needs a pid as argument")
+ END OBJ_ARG(pid_sgid, nullptr, "pid_sgid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_sgid;
- END OBJ_ARG(pid_fsgid, 0, "pid_fsgid needs a pid as argument")
+ END OBJ_ARG(pid_fsgid, nullptr, "pid_fsgid needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_fsgid;
- END OBJ_ARG(gid_name, 0, "gid_name needs a gid as argument")
+ END OBJ_ARG(gid_name, nullptr, "gid_name needs a gid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_gid_name;
- END OBJ_ARG(uid_name, 0, "uid_name needs a uid as argument")
+ END OBJ_ARG(uid_name, nullptr, "uid_name needs a uid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_uid_name;
- END OBJ_ARG(pid_read, 0, "pid_read needs a pid as argument")
+ END OBJ_ARG(pid_read, nullptr, "pid_read needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_read;
- END OBJ_ARG(pid_vmpeak, 0, "pid_vmpeak needs a pid as argument")
+ END OBJ_ARG(pid_vmpeak, nullptr, "pid_vmpeak needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmpeak;
- END OBJ_ARG(pid_vmsize, 0, "pid_vmsize needs a pid as argument")
+ END OBJ_ARG(pid_vmsize, nullptr, "pid_vmsize needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmsize;
- END OBJ_ARG(pid_vmlck, 0, "pid_vmlck needs a pid as argument")
+ END OBJ_ARG(pid_vmlck, nullptr, "pid_vmlck needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmlck;
- END OBJ_ARG(pid_vmhwm, 0, "pid_vmhwm needs a pid as argument")
+ END OBJ_ARG(pid_vmhwm, nullptr, "pid_vmhwm needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmhwm;
- END OBJ_ARG(pid_vmrss, 0, "pid_vmrss needs a pid as argument")
+ END OBJ_ARG(pid_vmrss, nullptr, "pid_vmrss needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmrss;
- END OBJ_ARG(pid_vmdata, 0, "pid_vmdata needs a pid as argument")
+ END OBJ_ARG(pid_vmdata, nullptr, "pid_vmdata needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmdata;
- END OBJ_ARG(pid_vmstk, 0, "pid_vmstk needs a pid as argument")
+ END OBJ_ARG(pid_vmstk, nullptr, "pid_vmstk needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmstk;
- END OBJ_ARG(pid_vmexe, 0, "pid_vmexe needs a pid as argument")
+ END OBJ_ARG(pid_vmexe, nullptr, "pid_vmexe needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmexe;
- END OBJ_ARG(pid_vmlib, 0, "pid_vmlib needs a pid as argument")
+ END OBJ_ARG(pid_vmlib, nullptr, "pid_vmlib needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmlib;
- END OBJ_ARG(pid_vmpte, 0, "pid_vmpte needs a pid as argument")
+ END OBJ_ARG(pid_vmpte, nullptr, "pid_vmpte needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_vmpte;
- END OBJ_ARG(pid_write, 0, "pid_write needs a pid as argument")
+ END OBJ_ARG(pid_write, nullptr, "pid_write needs a pid as argument")
extract_object_args_to_sub(obj, arg);
obj->callbacks.print = &print_pid_write;
#ifdef __DragonFly__
@@ -1283,18 +1297,19 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
&print_running_processes;
#endif
#endif /* __linux__ */
- END OBJ(shadecolor, 0)
-#ifdef BUILD_X11
- obj->data.l = arg ? get_x11_color(arg) : default_shade_color.get(*state);
- obj->callbacks.print = &new_bg;
-#endif /* BUILD_X11 */
- END OBJ(outlinecolor, 0)
+ END OBJ(shadecolor, nullptr)
#ifdef BUILD_X11
obj->data.l =
- arg ? get_x11_color(arg) : default_outline_color.get(*state);
+ arg != nullptr ? get_x11_color(arg) : default_shade_color.get(*state);
+ obj->callbacks.print = &new_bg;
+#endif /* BUILD_X11 */
+ END OBJ(outlinecolor, nullptr)
+#ifdef BUILD_X11
+ obj->data.l =
+ arg != nullptr ? get_x11_color(arg) : default_outline_color.get(*state);
obj->callbacks.print = &new_outline;
#endif /* BUILD_X11 */
- END OBJ(stippled_hr, 0)
+ END OBJ(stippled_hr, nullptr)
#ifdef BUILD_X11
scan_stippled_hr(obj, arg);
obj->callbacks.print = &new_stippled_hr;
@@ -1307,14 +1322,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(swapbar, &update_meminfo) scan_bar(obj, arg, 1);
obj->callbacks.barval = &swap_barval;
/* XXX: swapgraph, swapgauge? */
- END OBJ(sysname, 0) obj->callbacks.print = &print_sysname;
- END OBJ(time, 0) scan_time(obj, arg);
+ END OBJ(sysname, nullptr) obj->callbacks.print = &print_sysname;
+ END OBJ(time, nullptr) scan_time(obj, arg);
obj->callbacks.print = &print_time;
obj->callbacks.free = &free_time;
- END OBJ(utime, 0) scan_time(obj, arg);
+ END OBJ(utime, nullptr) scan_time(obj, arg);
obj->callbacks.print = &print_utime;
obj->callbacks.free = &free_time;
- END OBJ(tztime, 0) scan_tztime(obj, arg);
+ END OBJ(tztime, nullptr) scan_tztime(obj, arg);
obj->callbacks.print = &print_tztime;
obj->callbacks.free = &free_tztime;
#ifdef BUILD_ICAL
@@ -1342,17 +1357,17 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(totalup, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_totalup;
- END OBJ(updates, 0) obj->callbacks.print = &print_updates;
- END OBJ_IF(if_updatenr, 0) obj->data.i = arg ? atoi(arg) : 0;
+ END OBJ(updates, nullptr) obj->callbacks.print = &print_updates;
+ END OBJ_IF(if_updatenr, nullptr) obj->data.i = arg != nullptr ? atoi(arg) : 0;
if (obj->data.i == 0)
CRIT_ERR(obj, free_at_crash,
"if_updatenr needs a number above 0 as argument");
set_updatereset(obj->data.i > get_updatereset() ? obj->data.i
: get_updatereset());
obj->callbacks.iftest = &updatenr_iftest;
- END OBJ(alignr, 0) obj->data.l = arg ? atoi(arg) : 1;
+ END OBJ(alignr, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
obj->callbacks.print = &new_alignr;
- END OBJ(alignc, 0) obj->data.l = arg ? atoi(arg) : 0;
+ END OBJ(alignc, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 0;
obj->callbacks.print = &new_alignc;
END OBJ(upspeed, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
@@ -1393,16 +1408,16 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(apm_battery_life, 0) obj->callbacks.print = &print_apm_battery_life;
END OBJ(apm_battery_time, 0) obj->callbacks.print = &print_apm_battery_time;
#endif /* __FreeBSD__ */
- END OBJ(imap_unseen, 0) parse_imap_mail_args(obj, arg);
+ END OBJ(imap_unseen, nullptr) parse_imap_mail_args(obj, arg);
obj->callbacks.print = &print_imap_unseen;
obj->callbacks.free = &free_mail_obj;
- END OBJ(imap_messages, 0) parse_imap_mail_args(obj, arg);
+ END OBJ(imap_messages, nullptr) parse_imap_mail_args(obj, arg);
obj->callbacks.print = &print_imap_messages;
obj->callbacks.free = &free_mail_obj;
- END OBJ(pop3_unseen, 0) parse_pop3_mail_args(obj, arg);
+ END OBJ(pop3_unseen, nullptr) parse_pop3_mail_args(obj, arg);
obj->callbacks.print = &print_pop3_unseen;
obj->callbacks.free = &free_mail_obj;
- END OBJ(pop3_used, 0) parse_pop3_mail_args(obj, arg);
+ END OBJ(pop3_used, nullptr) parse_pop3_mail_args(obj, arg);
obj->callbacks.print = &print_pop3_used;
obj->callbacks.free = &free_mail_obj;
#ifdef BUILD_IBM
@@ -1445,49 +1460,50 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
else \
NORM_ERR(#name ": invalid length argument"); \
}
- END OBJ(mpd_artist, 0) mpd_set_maxlen(mpd_artist);
+ END OBJ(mpd_artist, nullptr) mpd_set_maxlen(mpd_artist);
obj->callbacks.print = &print_mpd_artist;
- END OBJ(mpd_albumartist, 0) mpd_set_maxlen(mpd_albumartist);
+ END OBJ(mpd_albumartist, nullptr) mpd_set_maxlen(mpd_albumartist);
obj->callbacks.print = &print_mpd_albumartist;
- END OBJ(mpd_title, 0) mpd_set_maxlen(mpd_title);
+ END OBJ(mpd_title, nullptr) mpd_set_maxlen(mpd_title);
obj->callbacks.print = &print_mpd_title;
- END OBJ(mpd_date, 0) mpd_set_maxlen(mpd_date);
+ END OBJ(mpd_date, nullptr) mpd_set_maxlen(mpd_date);
obj->callbacks.print = &print_mpd_date;
- END OBJ(mpd_random, 0) obj->callbacks.print = &print_mpd_random;
- END OBJ(mpd_repeat, 0) obj->callbacks.print = &print_mpd_repeat;
- END OBJ(mpd_elapsed, 0) obj->callbacks.print = &print_mpd_elapsed;
- END OBJ(mpd_length, 0) obj->callbacks.print = &print_mpd_length;
- END OBJ(mpd_track, 0) mpd_set_maxlen(mpd_track);
+ END OBJ(mpd_random, nullptr) obj->callbacks.print = &print_mpd_random;
+ END OBJ(mpd_repeat, nullptr) obj->callbacks.print = &print_mpd_repeat;
+ END OBJ(mpd_elapsed, nullptr) obj->callbacks.print = &print_mpd_elapsed;
+ END OBJ(mpd_length, nullptr) obj->callbacks.print = &print_mpd_length;
+ END OBJ(mpd_track, nullptr) mpd_set_maxlen(mpd_track);
obj->callbacks.print = &print_mpd_track;
- END OBJ(mpd_name, 0) mpd_set_maxlen(mpd_name);
+ END OBJ(mpd_name, nullptr) mpd_set_maxlen(mpd_name);
obj->callbacks.print = &print_mpd_name;
- END OBJ(mpd_file, 0) mpd_set_maxlen(mpd_file);
+ END OBJ(mpd_file, nullptr) mpd_set_maxlen(mpd_file);
obj->callbacks.print = &print_mpd_file;
- END OBJ(mpd_percent, 0) obj->callbacks.percentage = &mpd_percentage;
- END OBJ(mpd_album, 0) mpd_set_maxlen(mpd_album);
+ END OBJ(mpd_percent, nullptr) obj->callbacks.percentage = &mpd_percentage;
+ END OBJ(mpd_album, nullptr) mpd_set_maxlen(mpd_album);
obj->callbacks.print = &print_mpd_album;
- END OBJ(mpd_vol, 0) obj->callbacks.print = &print_mpd_vol;
- END OBJ(mpd_bitrate, 0) obj->callbacks.print = &print_mpd_bitrate;
- END OBJ(mpd_status, 0) obj->callbacks.print = &print_mpd_status;
- END OBJ(mpd_bar, 0) scan_bar(obj, arg, 1);
+ END OBJ(mpd_vol, nullptr) obj->callbacks.print = &print_mpd_vol;
+ END OBJ(mpd_bitrate, nullptr) obj->callbacks.print = &print_mpd_bitrate;
+ END OBJ(mpd_status, nullptr) obj->callbacks.print = &print_mpd_status;
+ END OBJ(mpd_bar, nullptr) scan_bar(obj, arg, 1);
obj->callbacks.barval = &mpd_barval;
- END OBJ(mpd_smart, 0) mpd_set_maxlen(mpd_smart);
+ END OBJ(mpd_smart, nullptr) mpd_set_maxlen(mpd_smart);
obj->callbacks.print = &print_mpd_smart;
- END OBJ_IF(if_mpd_playing, 0) obj->callbacks.iftest = &check_mpd_playing;
+ END OBJ_IF(if_mpd_playing, nullptr) obj->callbacks.iftest =
+ &check_mpd_playing;
#undef mpd_set_maxlen
#endif /* BUILD_MPD */
#ifdef BUILD_MOC
- END OBJ(moc_state, 0) obj->callbacks.print = &print_moc_state;
- END OBJ(moc_file, 0) obj->callbacks.print = &print_moc_file;
- END OBJ(moc_title, 0) obj->callbacks.print = &print_moc_title;
- END OBJ(moc_artist, 0) obj->callbacks.print = &print_moc_artist;
- END OBJ(moc_song, 0) obj->callbacks.print = &print_moc_song;
- END OBJ(moc_album, 0) obj->callbacks.print = &print_moc_album;
- END OBJ(moc_totaltime, 0) obj->callbacks.print = &print_moc_totaltime;
- END OBJ(moc_timeleft, 0) obj->callbacks.print = &print_moc_timeleft;
- END OBJ(moc_curtime, 0) obj->callbacks.print = &print_moc_curtime;
- END OBJ(moc_bitrate, 0) obj->callbacks.print = &print_moc_bitrate;
- END OBJ(moc_rate, 0) obj->callbacks.print = &print_moc_rate;
+ END OBJ(moc_state, nullptr) obj->callbacks.print = &print_moc_state;
+ END OBJ(moc_file, nullptr) obj->callbacks.print = &print_moc_file;
+ END OBJ(moc_title, nullptr) obj->callbacks.print = &print_moc_title;
+ END OBJ(moc_artist, nullptr) obj->callbacks.print = &print_moc_artist;
+ END OBJ(moc_song, nullptr) obj->callbacks.print = &print_moc_song;
+ END OBJ(moc_album, nullptr) obj->callbacks.print = &print_moc_album;
+ END OBJ(moc_totaltime, nullptr) obj->callbacks.print = &print_moc_totaltime;
+ END OBJ(moc_timeleft, nullptr) obj->callbacks.print = &print_moc_timeleft;
+ END OBJ(moc_curtime, nullptr) obj->callbacks.print = &print_moc_curtime;
+ END OBJ(moc_bitrate, nullptr) obj->callbacks.print = &print_moc_bitrate;
+ END OBJ(moc_rate, nullptr) obj->callbacks.print = &print_moc_rate;
#endif /* BUILD_MOC */
#ifdef BUILD_CMUS
END OBJ(cmus_state, 0) obj->callbacks.print = &print_cmus_state;
@@ -1647,21 +1663,21 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.print = &print_weather_forecast;
obj->callbacks.free = &free_weather;
#endif /* BUILD_WEATHER_XOAP */
- END OBJ_ARG(lua, 0,
+ END OBJ_ARG(lua, nullptr,
"lua needs arguments: [function parameters]")
obj->data.s = strndup(arg, text_buffer_size.get(*state));
obj->callbacks.print = &print_lua;
obj->callbacks.free = &gen_free_opaque;
END OBJ_ARG(
- lua_parse, 0,
+ lua_parse, nullptr,
"lua_parse needs arguments: [function parameters]")
obj->data.s = strndup(arg, text_buffer_size.get(*state));
obj->callbacks.print = &print_lua_parse;
obj->callbacks.free = &gen_free_opaque;
- END OBJ_ARG(lua_bar, 0,
+ END OBJ_ARG(lua_bar, nullptr,
"lua_bar needs arguments: , "
"[function parameters]") arg = scan_bar(obj, arg, 100);
- if (arg) {
+ if (arg != nullptr) {
obj->data.s = strndup(arg, text_buffer_size.get(*state));
} else {
CRIT_ERR(obj, free_at_crash,
@@ -1672,11 +1688,11 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.free = &gen_free_opaque;
#ifdef BUILD_X11
END OBJ_ARG(
- lua_graph, 0,
+ lua_graph, nullptr,
"lua_graph needs arguments: [height],[width] [gradient "
- "colour 1] [gradient colour 2] [scale] [-t] [-l]") char *buf = 0;
+ "colour 1] [gradient colour 2] [scale] [-t] [-l]") char *buf = nullptr;
buf = scan_graph(obj, arg, 100);
- if (buf) {
+ if (buf != nullptr) {
obj->data.s = buf;
} else {
CRIT_ERR(obj, free_at_crash,
@@ -1685,10 +1701,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
}
obj->callbacks.graphval = &lua_barval;
obj->callbacks.free = &gen_free_opaque;
- END OBJ_ARG(lua_gauge, 0,
+ END OBJ_ARG(lua_gauge, nullptr,
"lua_gauge needs arguments: , "
"[function parameters]") arg = scan_gauge(obj, arg, 100);
- if (arg) {
+ if (arg != nullptr) {
obj->data.s = strndup(arg, text_buffer_size.get(*state));
} else {
CRIT_ERR(obj, free_at_crash,
@@ -1718,12 +1734,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
&print_entropy_poolsize;
END OBJ(entropy_bar, &update_entropy) scan_bar(obj, arg, 1);
obj->callbacks.barval = &entropy_barval;
- END OBJ_ARG(blink, 0, "blink needs a argument") obj->sub =
- (text_object *)malloc(sizeof(struct text_object));
+ END OBJ_ARG(blink, nullptr, "blink needs a argument") obj->sub =
+ static_cast(malloc(sizeof(struct text_object)));
extract_variable_text_internal(obj->sub, arg);
obj->callbacks.print = &print_blink;
- END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument") obj->sub =
- (text_object *)malloc(sizeof(struct text_object));
+ END OBJ_ARG(to_bytes, nullptr, "to_bytes needs a argument") obj->sub =
+ static_cast(malloc(sizeof(struct text_object)));
extract_variable_text_internal(obj->sub, arg);
obj->callbacks.print = &print_to_bytes;
#ifdef BUILD_CURL
@@ -1731,14 +1747,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.print = &print_stock;
obj->callbacks.free = &free_stock;
#endif /* BUILD_CURL */
- END OBJ(scroll, 0)
+ END OBJ(scroll, nullptr)
#ifdef BUILD_X11
/* allocate a follower to reset any color changes */
#endif /* BUILD_X11 */
parse_scroll_arg(obj, arg, free_at_crash, s);
obj->callbacks.print = &print_scroll;
obj->callbacks.free = &free_scroll;
- END OBJ(combine, 0) try {
+ END OBJ(combine, nullptr) try {
parse_combine_arg(obj, arg);
} catch (combine_needs_2_args_error &e) {
free(obj);
@@ -1791,7 +1807,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#ifdef BUILD_APCUPSD
END OBJ_ARG(
apcupsd, &update_apcupsd,
- "apcupsd needs arguments: ") if (apcupsd_scan_arg(arg)) {
+ "apcupsd needs arguments: ") if (apcupsd_scan_arg(arg) !=
+ 0) {
CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: ");
}
obj->callbacks.print = &gen_print_nothing;
@@ -1812,7 +1829,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(apcupsd_loadbar, &update_apcupsd) scan_bar(obj, arg, 100);
obj->callbacks.barval = &apcupsd_loadbarval;
#ifdef BUILD_X11
- END OBJ(apcupsd_loadgraph, &update_apcupsd) char *buf = 0;
+ END OBJ(apcupsd_loadgraph, &update_apcupsd) char *buf = nullptr;
buf = scan_graph(obj, arg, 100);
free_and_zero(buf);
obj->callbacks.graphval = &apcupsd_loadbarval;
@@ -1866,7 +1883,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
init_pulseaudio(obj);
#endif /* BUILD_PULSEAUDIO */
END {
- char *buf = (char *)malloc(text_buffer_size.get(*state));
+ auto *buf = static_cast(malloc(text_buffer_size.get(*state)));
NORM_ERR("unknown variable '$%s'", s);
snprintf(buf, text_buffer_size.get(*state), "${%s}", s);
@@ -1897,8 +1914,12 @@ static size_t remove_comment(char *string, char *last) {
while (*end != '\0' && *end != '\n') {
++end;
}
- if (last) *last = *end;
- if (*end == '\n') end++;
+ if (last != nullptr) {
+ *last = *end;
+ }
+ if (*end == '\n') {
+ end++;
+ }
strfold(string, end - string);
return end - string;
}
@@ -1912,7 +1933,7 @@ size_t remove_comments(char *string) {
strfold(curplace, 1);
folded += 1;
} else if (*curplace == '#') {
- folded += remove_comment(curplace, 0);
+ folded += remove_comment(curplace, nullptr);
}
}
return folded;
@@ -1923,13 +1944,13 @@ int extract_variable_text_internal(struct text_object *retval,
struct text_object *obj;
char *p, *s, *orig_p;
long line;
- void *ifblock_opaque = NULL;
+ void *ifblock_opaque = nullptr;
char *tmp_p;
- char *arg = 0;
+ char *arg = nullptr;
size_t len = 0;
p = strndup(const_p, max_user_text.get(*state) - 1);
- while (text_contains_templates(p)) {
+ while (text_contains_templates(p) != 0) {
char *tmp;
tmp = find_and_replace_templates(p);
free(p);
@@ -1937,7 +1958,7 @@ int extract_variable_text_internal(struct text_object *retval,
}
s = orig_p = p;
- if (strcmp(p, const_p)) {
+ if (static_cast(strcmp(p, const_p) != 0) != 0) {
DBGP2("replaced all templates in text: input is\n'%s'\noutput is\n'%s'",
const_p, p);
} else {
@@ -1948,14 +1969,14 @@ int extract_variable_text_internal(struct text_object *retval,
line = global_text_lines;
- while (*p) {
+ while (*p != 0) {
if (*p == '\n') {
line++;
}
if (*p == '$') {
*p = '\0';
obj = create_plain_text(s);
- if (obj != NULL) {
+ if (obj != nullptr) {
append_object(retval, obj);
}
*p = '$';
@@ -1963,7 +1984,7 @@ int extract_variable_text_internal(struct text_object *retval,
s = p;
if (*p != '$') {
- char *buf = (char *)malloc(text_buffer_size.get(*state));
+ auto *buf = static_cast(malloc(text_buffer_size.get(*state)));
const char *var;
/* variable is either $foo or ${foo} */
@@ -1972,7 +1993,7 @@ int extract_variable_text_internal(struct text_object *retval,
p++;
s = p;
- while (*p && brl != brr) {
+ while ((*p != 0) && brl != brr) {
if (*p == '{') {
brl++;
}
@@ -1987,14 +2008,15 @@ int extract_variable_text_internal(struct text_object *retval,
if (*p == '#') {
p++;
}
- while (*p && (isalnum((int)*p) || *p == '_')) {
+ while ((*p != 0) &&
+ ((isalnum(static_cast(*p)) != 0) || *p == '_')) {
p++;
}
}
/* copy variable to buffer */
- len = (p - s > (int)text_buffer_size.get(*state) - 1)
- ? (int)text_buffer_size.get(*state) - 1
+ len = (p - s > static_cast(text_buffer_size.get(*state)) - 1)
+ ? static_cast(text_buffer_size.get(*state)) - 1
: (p - s);
strncpy(buf, s, len);
buf[len] = '\0';
@@ -2007,9 +2029,9 @@ int extract_variable_text_internal(struct text_object *retval,
/* search for variable in environment */
var = getenv(buf);
- if (var) {
+ if (var != nullptr) {
obj = create_plain_text(var);
- if (obj) {
+ if (obj != nullptr) {
append_object(retval, obj);
}
free(buf);
@@ -2018,24 +2040,24 @@ int extract_variable_text_internal(struct text_object *retval,
/* if variable wasn't found in environment, use some special */
- arg = 0;
+ arg = nullptr;
/* split arg */
- if (strchr(buf, ' ')) {
+ if (strchr(buf, ' ') != nullptr) {
arg = strchr(buf, ' ');
*arg = '\0';
arg++;
- while (isspace((int)*arg)) {
+ while (isspace(static_cast(*arg)) != 0) {
arg++;
}
- if (!*arg) {
- arg = 0;
+ if (*arg == 0) {
+ arg = nullptr;
}
}
/* lowercase variable name */
tmp_p = buf;
- while (*tmp_p) {
+ while (*tmp_p != 0) {
*tmp_p = tolower(*tmp_p);
tmp_p++;
}
@@ -2047,23 +2069,23 @@ int extract_variable_text_internal(struct text_object *retval,
free(orig_p);
throw e;
}
- if (obj != NULL) {
+ if (obj != nullptr) {
append_object(retval, obj);
}
free(buf);
continue;
- } else {
+ }
obj = create_plain_text("$");
s = p + 1;
- if (obj != NULL) {
+ if (obj != nullptr) {
append_object(retval, obj);
}
- }
+
} else if (*p == '\\' && *(p + 1) == '#') {
strfold(p, 1);
} else if (*p == '#') {
char c;
- if (remove_comment(p, &c) && p >= orig_p && c == '\n') {
+ if ((remove_comment(p, &c) != 0u) && p >= orig_p && c == '\n') {
/* if remove_comment removed a newline, we need to 'back up' with p */
p--;
}
@@ -2071,11 +2093,11 @@ int extract_variable_text_internal(struct text_object *retval,
p++;
}
obj = create_plain_text(s);
- if (obj != NULL) {
+ if (obj != nullptr) {
append_object(retval, obj);
}
- if (!ifblock_stack_empty(&ifblock_opaque)) {
+ if (ifblock_stack_empty(&ifblock_opaque) == 0) {
NORM_ERR("one or more $endif's are missing");
}
@@ -2084,7 +2106,8 @@ int extract_variable_text_internal(struct text_object *retval,
}
void extract_object_args_to_sub(struct text_object *obj, const char *args) {
- obj->sub = (struct text_object *)malloc(sizeof(struct text_object));
+ obj->sub =
+ static_cast(malloc(sizeof(struct text_object)));
memset(obj->sub, 0, sizeof(struct text_object));
extract_variable_text_internal(obj->sub, args);
}
@@ -2093,10 +2116,10 @@ void extract_object_args_to_sub(struct text_object *obj, const char *args) {
void free_text_objects(struct text_object *root) {
struct text_object *obj;
- if (root && root->prev) {
- for (obj = root->prev; obj; obj = root->prev) {
+ if ((root != nullptr) && (root->prev != nullptr)) {
+ for (obj = root->prev; obj != nullptr; obj = root->prev) {
root->prev = obj->prev;
- if (obj->callbacks.free) {
+ if (obj->callbacks.free != nullptr) {
(*obj->callbacks.free)(obj);
}
free_text_objects(obj->sub);
diff --git a/src/darwin.cc b/src/darwin.cc
index b4f66c4b..678d3e49 100644
--- a/src/darwin.cc
+++ b/src/darwin.cc
@@ -53,7 +53,7 @@
#include
-#include
+#include
#include // statfs
#include
@@ -65,12 +65,12 @@
#include // update_total_processes
+#include "top.h" // get_top_info
#include // get_top_info
#include // get_top_info
-#include "top.h" // get_top_info
-#include // update_net_stats
#include "net_stat.h" // update_net_stats
+#include // update_net_stats
#include "darwin_sip.h" // sip status
@@ -88,7 +88,7 @@
/* (E)nhanced printf */
#ifdef DEBUG_MODE
-#include
+#include
void eprintf(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
@@ -110,7 +110,7 @@ static conky::simple_config_setting top_cpu_separate("top_cpu_separate",
static int getsysctl(const char *name, void *ptr, size_t len) {
size_t nlen = len;
- if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
+ if (sysctlbyname(name, ptr, &nlen, nullptr, 0) == -1) {
return -1;
}
@@ -166,7 +166,7 @@ int clock_gettime(int clock_id, struct timespec *ts) {
* Uses mach API to get load info ( task_count, thread_count )
*
*/
-static void helper_update_threads_processes(void) {
+static void helper_update_threads_processes() {
static host_name_port_t machHost;
static processor_set_name_port_t processorSet = 0;
static bool machStuffInitialised = false;
@@ -181,13 +181,15 @@ static void helper_update_threads_processes(void) {
}
/* get load info */
- struct processor_set_load_info loadInfo;
+ struct processor_set_load_info loadInfo {};
mach_msg_type_number_t count = PROCESSOR_SET_LOAD_INFO_COUNT;
- kern_return_t err =
- processor_set_statistics(processorSet, PROCESSOR_SET_LOAD_INFO,
- (processor_set_info_t)&loadInfo, &count);
+ kern_return_t err = processor_set_statistics(
+ processorSet, PROCESSOR_SET_LOAD_INFO,
+ reinterpret_cast(&loadInfo), &count);
- if (err != KERN_SUCCESS) return;
+ if (err != KERN_SUCCESS) {
+ return;
+ }
info.procs = loadInfo.task_count;
info.threads = loadInfo.thread_count;
@@ -228,13 +230,14 @@ static void get_cpu_sample(struct cpusample *sample) {
natural_t processorCount;
processor_cpu_load_info_t processorTickInfo;
mach_msg_type_number_t processorInfoCount;
- struct cpusample *samples = NULL;
+ struct cpusample *samples = nullptr;
machHost = mach_host_self();
kern_return_t err = host_processor_info(
machHost, PROCESSOR_CPU_LOAD_INFO, &processorCount,
- (processor_info_array_t *)&processorTickInfo, &processorInfoCount);
+ reinterpret_cast(&processorTickInfo),
+ &processorInfoCount);
if (err != KERN_SUCCESS) {
printf("host_statistics: %s\n", mach_error_string(err));
return;
@@ -279,10 +282,8 @@ static void get_cpu_sample(struct cpusample *sample) {
* Dealloc
*/
vm_deallocate(mach_task_self(), (vm_address_t)processorTickInfo,
- (vm_size_t)(processorInfoCount * sizeof(natural_t)));
+ static_cast(processorInfoCount * sizeof(natural_t)));
delete[] samples;
-
- return;
}
/*
@@ -296,31 +297,31 @@ static void get_cpu_sample(struct cpusample *sample) {
* ATTENTION: Do not forget to free the array once you are done with it,
* it is not freed automatically.
*/
-static int helper_get_proc_list(struct kinfo_proc **p = NULL) {
+static int helper_get_proc_list(struct kinfo_proc **p) {
int err = 0;
size_t length = 0;
static const int name[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
- /* Call sysctl with a NULL buffer to get proper length */
- err = sysctl((int *)name, (sizeof(name) / sizeof(*name)) - 1, NULL, &length,
- NULL, 0);
- if (err) {
- perror(NULL);
+ /* Call sysctl with a nullptr buffer to get proper length */
+ err = sysctl((int *)name, (sizeof(name) / sizeof(*name)) - 1, nullptr, &length,
+ nullptr, 0);
+ if (err != 0) {
+ perror(nullptr);
return (-1);
}
/* Allocate buffer */
- *p = (kinfo_proc *)malloc(length);
- if (!p) {
- perror(NULL);
+ *p = static_cast(malloc(length));
+ if (p == nullptr) {
+ perror(nullptr);
return (-1);
}
/* Get the actual process list */
err = sysctl((int *)name, (sizeof(name) / sizeof(*name)) - 1, *p, &length,
- NULL, 0);
- if (err) {
- perror(NULL);
+ nullptr, 0);
+ if (err != 0) {
+ perror(nullptr);
return (-1);
}
@@ -356,10 +357,10 @@ static int swapmode(unsigned long *retavail, unsigned long *retfree) {
*/
int swapMIB[] = {CTL_VM, 5};
- struct xsw_usage swapUsage;
+ struct xsw_usage swapUsage {};
size_t swapUsageSize = sizeof(swapUsage);
memset(&swapUsage, 0, sizeof(swapUsage));
- if (sysctl(swapMIB, 2, &swapUsage, &swapUsageSize, NULL, 0) == 0) {
+ if (sysctl(swapMIB, 2, &swapUsage, &swapUsageSize, nullptr, 0) == 0) {
*retfree = swapUsage.xsu_avail / 1024;
*retavail = swapUsage.xsu_total / 1024;
} else {
@@ -370,17 +371,17 @@ static int swapmode(unsigned long *retavail, unsigned long *retfree) {
return 1;
}
-void prepare_update(void) {
+void prepare_update() {
// in freebsd.cc this is empty so leaving it here too!
}
-int update_uptime(void) {
+int update_uptime() {
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
- struct timeval boottime;
+ struct timeval boottime {};
time_t now;
size_t size = sizeof(boottime);
- if ((sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) &&
+ if ((sysctl(mib, 2, &boottime, &size, nullptr, 0) != -1) &&
(boottime.tv_sec != 0)) {
time(&now);
info.uptime = now - boottime.tv_sec;
@@ -404,7 +405,9 @@ int check_mount(struct text_object *obj) {
int num_mounts = 0;
struct statfs *mounts;
- if (!obj->data.s) return 0;
+ if (obj->data.s == nullptr) {
+ return 0;
+ }
num_mounts = getmntinfo(&mounts, MNT_WAIT);
@@ -413,10 +416,11 @@ int check_mount(struct text_object *obj) {
return 0;
}
- for (int i = 0; i < num_mounts; i++)
+ for (int i = 0; i < num_mounts; i++) {
if (strcmp(mounts[i].f_mntonname, obj->data.s) == 0) {
return 1;
}
+ }
return 0;
}
@@ -496,16 +500,16 @@ static void update_pages_stolen(libtop_tsamp_t *tsamp) {
/* These are all declared as QUAD/uint64_t sysctls in the kernel. */
if (-1 == sysctl(mib_reserved, mib_reserved_len, &reserved, &reserved_len,
- NULL, 0)) {
+ nullptr, 0)) {
return;
}
if (-1 == sysctl(mib_unusable, mib_unusable_len, &unusable, &unusable_len,
- NULL, 0)) {
+ nullptr, 0)) {
return;
}
- if (-1 == sysctl(mib_other, mib_other_len, &other, &other_len, NULL, 0)) {
+ if (-1 == sysctl(mib_other, mib_other_len, &other, &other_len, nullptr, 0)) {
return;
}
@@ -535,7 +539,8 @@ static int libtop_tsamp_update_vm_stats(libtop_tsamp_t *tsamp) {
mach_msg_type_number_t count = sizeof(tsamp->vm_stat) / sizeof(natural_t);
kr = host_statistics64(mach_host_self(), HOST_VM_INFO64,
- (host_info64_t)&tsamp->vm_stat, &count);
+ reinterpret_cast(&tsamp->vm_stat),
+ &count);
if (kr != KERN_SUCCESS) {
return kr;
}
@@ -545,9 +550,9 @@ static int libtop_tsamp_update_vm_stats(libtop_tsamp_t *tsamp) {
}
// Check whether we got purgeable memory statistics
- tsamp->purgeable_is_valid =
- (count == (sizeof(tsamp->vm_stat) / sizeof(natural_t)));
- if (!tsamp->purgeable_is_valid) {
+ tsamp->purgeable_is_valid = static_cast(
+ count == (sizeof(tsamp->vm_stat) / sizeof(natural_t)));
+ if (tsamp->purgeable_is_valid == 0u) {
tsamp->vm_stat.purgeable_count = 0;
tsamp->vm_stat.purges = 0;
}
@@ -559,20 +564,20 @@ static int libtop_tsamp_update_vm_stats(libtop_tsamp_t *tsamp) {
* helper function for update_meminfo()
* return physical memory in bytes
*/
-uint64_t get_physical_memory(void) {
+uint64_t get_physical_memory() {
int mib[2] = {CTL_HW, HW_MEMSIZE};
int64_t physical_memory = 0;
size_t length = sizeof(int64_t);
- if (sysctl(mib, 2, &physical_memory, &length, NULL, 0) == -1) {
+ if (sysctl(mib, 2, &physical_memory, &length, nullptr, 0) == -1) {
physical_memory = 0;
}
return physical_memory;
}
-int update_meminfo(void) {
+int update_meminfo() {
/* XXX implement remaining memory-related variables (see conky.h) */
/* XXX conky breaks the values ... :( probably some rounding problem...
Though we get the right values (based on top) */
@@ -582,9 +587,11 @@ int update_meminfo(void) {
unsigned long swap_avail, swap_free;
static libtop_tsamp_t *tsamp = nullptr;
- if (!tsamp) {
+ if (tsamp == nullptr) {
tsamp = new libtop_tsamp_t;
- if (!tsamp) return 0;
+ if (tsamp == nullptr) {
+ return 0;
+ }
memset(tsamp, 0, sizeof(libtop_tsamp_t));
tsamp->pagesize = page_size;
@@ -599,7 +606,9 @@ int update_meminfo(void) {
* but first update pages stolen count
*/
update_pages_stolen(tsamp);
- if (libtop_tsamp_update_vm_stats(tsamp) == KERN_FAILURE) return 0;
+ if (libtop_tsamp_update_vm_stats(tsamp) == KERN_FAILURE) {
+ return 0;
+ }
/*
* This is actually a tricky part.
@@ -644,7 +653,7 @@ int update_meminfo(void) {
return 0;
}
-int update_net_stats(void) {
+int update_net_stats() {
struct net_stat *ns;
double delta;
long long r, t, last_recv, last_trans;
@@ -661,10 +670,10 @@ int update_net_stats(void) {
return 0;
}
- for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- ns = get_net_stat((const char *)ifa->ifa_name, NULL, NULL);
+ for (ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next) {
+ ns = get_net_stat((const char *)ifa->ifa_name, nullptr, nullptr);
- if (ifa->ifa_flags & IFF_UP) {
+ if ((ifa->ifa_flags & IFF_UP) != 0u) {
struct ifaddrs *iftmp;
ns->up = 1;
@@ -676,19 +685,20 @@ int update_net_stats(void) {
}
for (iftmp = ifa->ifa_next;
- iftmp != NULL && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0;
+ iftmp != nullptr && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0;
iftmp = iftmp->ifa_next) {
if (iftmp->ifa_addr->sa_family == AF_INET) {
memcpy(&(ns->addr), iftmp->ifa_addr, iftmp->ifa_addr->sa_len);
}
}
- ifd = (struct if_data *)ifa->ifa_data;
+ ifd = static_cast(ifa->ifa_data);
r = ifd->ifi_ibytes;
t = ifd->ifi_obytes;
if (r < ns->last_read_recv) {
- ns->recv += ((long long)4294967295U - ns->last_read_recv) + r;
+ ns->recv +=
+ (static_cast(4294967295U) - ns->last_read_recv) + r;
} else {
ns->recv += (r - ns->last_read_recv);
}
@@ -696,7 +706,8 @@ int update_net_stats(void) {
ns->last_read_recv = r;
if (t < ns->last_read_trans) {
- ns->trans += ((long long)4294967295U - ns->last_read_trans) + t;
+ ns->trans +=
+ (static_cast(4294967295U) - ns->last_read_trans) + t;
} else {
ns->trans += (t - ns->last_read_trans);
}
@@ -715,7 +726,7 @@ int update_net_stats(void) {
return 0;
}
-int update_threads(void) {
+int update_threads() {
helper_update_threads_processes();
return 0;
}
@@ -731,20 +742,22 @@ int update_threads(void) {
* Foreach pid and foreach pid's threads check their state and increment
* the run_threads counter acordingly.
*/
-int update_running_threads(void) {
- struct kinfo_proc *p = NULL;
+int update_running_threads() {
+ struct kinfo_proc *p = nullptr;
int proc_count = 0;
int run_threads = 0;
proc_count = helper_get_proc_list(&p);
- if (proc_count == -1) return 0;
+ if (proc_count == -1) {
+ return 0;
+ }
- for (int i = 0; i < proc_count; i++)
- if (p[i].kp_proc.p_stat & SRUN) {
+ for (int i = 0; i < proc_count; i++) {
+ if ((p[i].kp_proc.p_stat & SRUN) != 0) {
pid_t pid = 0;
- struct proc_taskinfo pti;
- struct proc_threadinfo pthi;
+ struct proc_taskinfo pti {};
+ struct proc_threadinfo pthi {};
int num_threads = 0;
pid = p[i].kp_proc.p_pid;
@@ -753,24 +766,30 @@ int update_running_threads(void) {
if (sizeof(pti) ==
proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
num_threads = pti.pti_threadnum;
- } else
+ } else {
continue;
+ }
/* foreach thread check its state */
- for (int i = 0; i < num_threads; i++)
+ for (int i = 0; i < num_threads; i++) {
if (sizeof(pthi) ==
proc_pidinfo(pid, PROC_PIDTHREADINFO, i, &pthi, sizeof(pthi))) {
- if (pthi.pth_run_state == TH_STATE_RUNNING) run_threads++;
- } else
+ if (pthi.pth_run_state == TH_STATE_RUNNING) {
+ run_threads++;
+ }
+ } else {
continue;
+ }
+ }
}
+ }
free(p);
info.run_threads = run_threads;
return 0;
}
-int update_total_processes(void) {
+int update_total_processes() {
helper_update_threads_processes();
return 0;
@@ -811,20 +830,23 @@ int update_total_processes(void) {
*/
}
-int update_running_processes(void) {
- struct kinfo_proc *p = NULL;
+int update_running_processes() {
+ struct kinfo_proc *p = nullptr;
int proc_count = 0;
int run_procs = 0;
proc_count = helper_get_proc_list(&p);
- if (proc_count == -1) return 0;
+ if (proc_count == -1) {
+ return 0;
+ }
for (int i = 0; i < proc_count; i++) {
int state = p[i].kp_proc.p_stat;
- if (state == SRUN) // XXX this check needs to be fixed...
+ if (state == SRUN) { // XXX this check needs to be fixed...
run_procs++;
+ }
}
free(p);
@@ -838,7 +860,7 @@ int update_running_processes(void) {
* The macOS implementation gets the number of active cpus
* in compliance with linux implementation.
*/
-void get_cpu_count(void) {
+void get_cpu_count() {
int cpu_count = 0;
if (GETSYSCTL("hw.activecpu", cpu_count) == 0) {
@@ -850,13 +872,14 @@ void get_cpu_count(void) {
/* XXX this can be moved to update_cpu_usage() but keep here to follow linux
* implementation */
- if (!info.cpu_usage) {
+ if (info.cpu_usage == nullptr) {
/*
* Allocate ncpus+1 slots because cpu_usage[0] is overall usage.
*/
- info.cpu_usage = (float *)malloc((info.cpu_count + 1) * sizeof(float));
- if (info.cpu_usage == NULL) {
- CRIT_ERR(NULL, NULL, "malloc");
+ info.cpu_usage =
+ static_cast(malloc((info.cpu_count + 1) * sizeof(float)));
+ if (info.cpu_usage == nullptr) {
+ CRIT_ERR(nullptr, nullptr, "malloc");
}
}
}
@@ -869,17 +892,17 @@ struct cpu_info {
long oldused;
};
-int update_cpu_usage(void) {
+int update_cpu_usage() {
/* XXX add support for multiple cpus (see linux.cc) */
static bool cpu_setup = 0;
long used, total;
- static struct cpu_info *cpu = NULL;
+ static struct cpu_info *cpu = nullptr;
unsigned int malloc_cpu_size = 0;
extern void *global_cpu;
- struct cpusample sample;
+ struct cpusample sample {};
static pthread_mutex_t last_stat_update_mutex = PTHREAD_MUTEX_INITIALIZER;
static double last_stat_update = 0.0;
@@ -896,17 +919,17 @@ int update_cpu_usage(void) {
pthread_mutex_unlock(&last_stat_update_mutex);
/* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */
- if ((cpu_setup == 0) || (!info.cpu_usage)) {
+ if ((static_cast(cpu_setup) == 0) || (info.cpu_usage == nullptr)) {
get_cpu_count();
cpu_setup = 1;
}
- if (!global_cpu) {
+ if (global_cpu == nullptr) {
/*
* Allocate ncpus+1 slots because cpu_usage[0] is overall usage.
*/
malloc_cpu_size = (info.cpu_count + 1) * sizeof(struct cpu_info);
- cpu = (cpu_info *)malloc(malloc_cpu_size);
+ cpu = static_cast(malloc(malloc_cpu_size));
memset(cpu, 0, malloc_cpu_size);
global_cpu = cpu;
}
@@ -916,8 +939,8 @@ int update_cpu_usage(void) {
used = total - sample.totalIdleTime;
if ((total - cpu[0].oldtotal) != 0) {
- info.cpu_usage[0] =
- ((double)(used - cpu[0].oldused)) / (double)(total - cpu[0].oldtotal);
+ info.cpu_usage[0] = (static_cast(used - cpu[0].oldused)) /
+ static_cast(total - cpu[0].oldtotal);
} else {
info.cpu_usage[0] = 0;
}
@@ -928,33 +951,34 @@ int update_cpu_usage(void) {
return 0;
}
-int update_load_average(void) {
+int update_load_average() {
double v[3];
getloadavg(v, 3);
- info.loadavg[0] = (double)v[0];
- info.loadavg[1] = (double)v[1];
- info.loadavg[2] = (double)v[2];
+ info.loadavg[0] = v[0];
+ info.loadavg[1] = v[1];
+ info.loadavg[2] = v[2];
return 0;
}
-double get_acpi_temperature(int fd) {
+double get_acpi_temperature(int /*fd*/) {
printf("get_acpi_temperature: STUB\n");
return 0.0;
}
-void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) {
+void get_battery_stuff(char * /*buf*/, unsigned int /*n*/, const char * /*bat*/,
+ int /*item*/) {
printf("get_battery_stuff: STUB\n");
}
-int get_battery_perct(const char *bat) {
+int get_battery_perct(const char * /*bat*/) {
printf("get_battery_perct: STUB\n");
return 1;
}
-double get_battery_perct_bar(struct text_object *obj) {
+double get_battery_perct_bar(struct text_object * /*obj*/) {
printf("get_battery_perct_bar: STUB\n");
return 0.0;
}
@@ -967,18 +991,19 @@ int open_acpi_temperature(const char *name) {
return 0;
}
-void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
- const char *adapter) {
+void get_acpi_ac_adapter(char * /*p_client_buffer*/,
+ size_t /*client_buffer_size*/,
+ const char * /*adapter*/) {
printf("get_acpi_ac_adapter: STUB\n");
}
-void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) {
+void get_acpi_fan(char * /*p_client_buffer*/, size_t /*client_buffer_size*/) {
printf("get_acpi_fan: STUB\n");
}
/* void */
char get_freq(char *p_client_buffer, size_t client_buffer_size,
- const char *p_format, int divisor, unsigned int cpu) {
+ const char *p_format, int divisor, unsigned int /*cpu*/) {
/*
* For now, we get the factory cpu frequency, not **current** cpu frequency
* (Also, it is always the same for every core, so ignore |cpu| argument)
@@ -990,8 +1015,8 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size,
unsigned int freq;
size_t len;
- if (!p_client_buffer || client_buffer_size <= 0 || !p_format ||
- divisor <= 0) {
+ if ((p_client_buffer == nullptr) || client_buffer_size <= 0 ||
+ (p_format == nullptr) || divisor <= 0) {
return 0;
}
@@ -999,14 +1024,14 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size,
mib[1] = HW_CPU_FREQ;
len = sizeof(freq);
- if (sysctl(mib, 2, &freq, &len, NULL, 0) == 0) {
+ if (sysctl(mib, 2, &freq, &len, nullptr, 0) == 0) {
/*
* convert to MHz
*/
divisor *= 1000000;
snprintf(p_client_buffer, client_buffer_size, p_format,
- (float)freq / divisor);
+ static_cast(freq) / divisor);
} else {
snprintf(p_client_buffer, client_buffer_size, p_format, 0.0f);
return 0;
@@ -1022,20 +1047,21 @@ void update_wifi_stats(void)
}
#endif
-int update_diskio(void) {
+int update_diskio() {
printf("update_diskio: STUB\n");
return 0;
}
-void get_battery_short_status(char *buffer, unsigned int n, const char *bat) {
+void get_battery_short_status(char * /*buffer*/, unsigned int /*n*/,
+ const char * /*bat*/) {
printf("get_battery_short_status: STUB\n");
}
-int get_entropy_avail(unsigned int *val) {
+int get_entropy_avail(const unsigned int *val) {
(void)val;
return 1;
}
-int get_entropy_poolsize(unsigned int *val) {
+int get_entropy_poolsize(const unsigned int *val) {
(void)val;
return 1;
}
@@ -1049,9 +1075,12 @@ int get_entropy_poolsize(unsigned int *val) {
*/
static void calc_cpu_usage_for_proc(struct process *proc, uint64_t total) {
float mul = 100.0;
- if (top_cpu_separate.get(*state)) mul *= info.cpu_count;
+ if (top_cpu_separate.get(*state)) {
+ mul *= info.cpu_count;
+ }
- proc->amount = mul * (proc->user_time + proc->kernel_time) / (float)total;
+ proc->amount =
+ mul * (proc->user_time + proc->kernel_time) / static_cast(total);
}
/*
@@ -1061,7 +1090,7 @@ static void calc_cpu_usage_for_proc(struct process *proc, uint64_t total) {
static void calc_cpu_total(struct process *proc, uint64_t *total) {
uint64_t current_total = 0; /* of current iteration */
// uint64_t total = 0; /* delta */
- struct cpusample sample;
+ struct cpusample sample {};
get_cpu_sample(&sample);
current_total =
@@ -1119,8 +1148,8 @@ static void calc_cpu_time_for_proc(struct process *process,
* process ) to implement get_top_info()
*/
static void get_top_info_for_kinfo_proc(struct kinfo_proc *p) {
- struct process *proc = NULL;
- struct proc_taskinfo pti;
+ struct process *proc = nullptr;
+ struct proc_taskinfo pti {};
pid_t pid;
pid = p->kp_proc.p_pid;
@@ -1164,8 +1193,9 @@ static void get_top_info_for_kinfo_proc(struct kinfo_proc *p) {
/*
* wait until done
*/
- while (!(calc_cpu_total_finished && calc_proc_total_finished))
+ while (!(calc_cpu_total_finished && calc_proc_total_finished)) {
;
+ }
/* calc the amount(%) of CPU the process used */
calc_cpu_usage_for_proc(proc, t);
@@ -1174,9 +1204,9 @@ static void get_top_info_for_kinfo_proc(struct kinfo_proc *p) {
/* While topless is obviously better, top is also not bad. */
-void get_top_info(void) {
+void get_top_info() {
int proc_count = 0;
- struct kinfo_proc *p = NULL;
+ struct kinfo_proc *p = nullptr;
/*
* QUICKFIX for #16
@@ -1199,13 +1229,16 @@ void get_top_info(void) {
*/
proc_count = helper_get_proc_list(&p);
- if (proc_count == -1) return;
+ if (proc_count == -1) {
+ return;
+ }
/*
* get top info for-each process
*/
for (int i = 0; i < proc_count; i++) {
- if (!((p[i].kp_proc.p_flag & P_SYSTEM)) && *p[i].kp_proc.p_comm != '\0') {
+ if ((((p[i].kp_proc.p_flag & P_SYSTEM)) == 0) &&
+ *p[i].kp_proc.p_comm != '\0') {
get_top_info_for_kinfo_proc(&p[i]);
}
}
@@ -1224,9 +1257,11 @@ void get_top_info(void) {
* Also, flip the result on occasion
*/
bool _csr_check(int aMask, bool aFlipflag) {
- bool bit = (info.csr_config & aMask);
+ bool bit = (info.csr_config & aMask) != 0u;
- if (aFlipflag) return !bit;
+ if (aFlipflag) {
+ return !bit;
+ }
return bit;
}
@@ -1234,7 +1269,7 @@ bool _csr_check(int aMask, bool aFlipflag) {
/*
* Extract info from the csr_config variable and set the flags struct
*/
-void fill_csr_config_flags_struct(void) {
+void fill_csr_config_flags_struct() {
info.csr_config_flags.csr_allow_apple_internal =
_csr_check(CSR_ALLOW_APPLE_INTERNAL, 0);
info.csr_config_flags.csr_allow_untrusted_kexts =
@@ -1260,7 +1295,7 @@ void fill_csr_config_flags_struct(void) {
/*
* Get SIP configuration ( sets csr_config and csr_config_flags )
*/
-int get_sip_status(void) {
+int get_sip_status() {
if (csr_get_active_config ==
nullptr) /* check if weakly linked symbol exists */
{
@@ -1315,7 +1350,9 @@ void print_sip_status(struct text_object *obj, char *p, int p_max_size) {
/* conky window output */
(void)obj;
- if (!obj->data.s) return;
+ if (obj->data.s == nullptr) {
+ return;
+ }
if (strlen(obj->data.s) == 0) {
snprintf(p, p_max_size, "%s",
@@ -1371,11 +1408,11 @@ void print_sip_status(struct text_object *obj, char *p, int p_max_size) {
info.csr_config_flags.csr_allow_user_approved_kexts ? "YES" : "NO");
break;
case 'a':
- snprintf(
- p, p_max_size, "%s",
- (info.csr_config && (info.csr_config != CSR_ALLOW_APPLE_INTERNAL))
- ? "unsupported configuration, beware!"
- : "configuration is ok");
+ snprintf(p, p_max_size, "%s",
+ ((info.csr_config != 0u) &&
+ (info.csr_config != CSR_ALLOW_APPLE_INTERNAL))
+ ? "unsupported configuration, beware!"
+ : "configuration is ok");
break;
default:
snprintf(p, p_max_size, "%s", "unsupported");
diff --git a/src/darwin.h b/src/darwin.h
index 83def954..55491228 100644
--- a/src/darwin.h
+++ b/src/darwin.h
@@ -49,8 +49,8 @@ int clock_gettime(int clock_id, struct timespec *ts);
int update_running_threads(void);
-int get_entropy_avail(unsigned int *);
-int get_entropy_poolsize(unsigned int *);
+int get_entropy_avail(const unsigned int *);
+int get_entropy_poolsize(const unsigned int *);
/* System Integrity Protection */
int get_sip_status(void);
diff --git a/src/data-source.cc b/src/data-source.cc
index aff56f02..461fcb07 100644
--- a/src/data-source.cc
+++ b/src/data-source.cc
@@ -49,11 +49,14 @@ typedef std::unordered_map data_sources_t;
data_sources_t *data_sources;
data_source_base &get_data_source(lua::state *l) {
- if (l->gettop() != 1) throw std::runtime_error("Wrong number of parameters");
+ if (l->gettop() != 1) {
+ throw std::runtime_error("Wrong number of parameters");
+ }
l->rawgetfield(lua::REGISTRYINDEX, priv::data_source_metatable);
- if (not l->getmetatable(-2) or not l->rawequal(-1, -2))
+ if (not l->getmetatable(-2) or not l->rawequal(-1, -2)) {
throw std::runtime_error("Invalid parameter");
+ }
return *static_cast(l->touserdata(1));
}
@@ -89,15 +92,16 @@ void do_register_data_source(const std::string &name,
data_source_constructor() { data_sources = new data_sources_t(); }
~data_source_constructor() {
delete data_sources;
- data_sources = NULL;
+ data_sources = nullptr;
}
};
static data_source_constructor constructor;
bool inserted = data_sources->insert({name, fn}).second;
- if (not inserted)
+ if (not inserted) {
throw std::logic_error("Data source with name '" + name +
"' already registered");
+ }
}
disabled_data_source::disabled_data_source(lua::state *l,
@@ -144,9 +148,9 @@ void export_data_sources(lua::state &l) {
l.newtable();
{
- for (auto i = data_sources->begin(); i != data_sources->end(); ++i) {
- l.pushfunction(i->second);
- l.rawsetfield(-2, i->first.c_str());
+ for (auto &data_source : *data_sources) {
+ l.pushfunction(data_source.second);
+ l.rawsetfield(-2, data_source.first.c_str());
}
}
l.rawsetfield(-2, "variables");
diff --git a/src/diskio.cc b/src/diskio.cc
index b511a309..19d9e483 100644
--- a/src/diskio.cc
+++ b/src/diskio.cc
@@ -28,8 +28,8 @@
*/
#include "diskio.h"
-#include
#include
+#include
#include
#include "common.h"
#include "config.h"
@@ -43,9 +43,9 @@
* also containing the totals. */
struct diskio_stat stats;
-void clear_diskio_stats(void) {
+void clear_diskio_stats() {
struct diskio_stat *cur;
- while (stats.next) {
+ while (stats.next != nullptr) {
cur = stats.next;
stats.next = stats.next->next;
free_and_zero(cur->dev);
@@ -54,26 +54,26 @@ void clear_diskio_stats(void) {
}
struct diskio_stat *prepare_diskio_stat(const char *s) {
- struct stat sb;
+ struct stat sb {};
std::vector stat_name(text_buffer_size.get(*state)),
device_name(text_buffer_size.get(*state)),
device_s(text_buffer_size.get(*state));
struct diskio_stat *cur = &stats;
char *rpbuf;
- if (!s) {
+ if (s == nullptr) {
return &stats;
}
if (strncmp(s, "label:", 6) == 0) {
snprintf(&(device_name[0]), text_buffer_size.get(*state),
"/dev/disk/by-label/%s", s + 6);
- rpbuf = realpath(&device_name[0], NULL);
+ rpbuf = realpath(&device_name[0], nullptr);
} else {
- rpbuf = realpath(s, NULL);
+ rpbuf = realpath(s, nullptr);
}
- if (rpbuf) {
+ if (rpbuf != nullptr) {
strncpy(&device_s[0], rpbuf, text_buffer_size.get(*state));
free(rpbuf);
} else {
@@ -95,15 +95,15 @@ struct diskio_stat *prepare_diskio_stat(const char *s) {
snprintf(&(stat_name[0]), text_buffer_size.get(*state), "/dev/%s",
&(device_name[0]));
- if (stat(&(stat_name[0]), &sb) || !S_ISBLK(sb.st_mode)) {
+ if ((stat(&(stat_name[0]), &sb) != 0) || !S_ISBLK(sb.st_mode)) {
NORM_ERR("diskio device '%s' does not exist", &device_s[0]);
}
#endif
/* lookup existing */
- while (cur->next) {
+ while (cur->next != nullptr) {
cur = cur->next;
- if (!strcmp(cur->dev, &(device_name[0]))) {
+ if (strcmp(cur->dev, &(device_name[0])) == 0) {
return cur;
}
}
@@ -130,17 +130,20 @@ void parse_diskio_arg(struct text_object *obj, const char *arg) {
*/
static void print_diskio_dir(struct text_object *obj, int dir, char *p,
int p_max_size) {
- struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
+ auto *diskio = static_cast(obj->data.opaque);
double val;
- if (!diskio) return;
+ if (diskio == nullptr) {
+ return;
+ }
- if (dir < 0)
+ if (dir < 0) {
val = diskio->current_read;
- else if (dir == 0)
+ } else if (dir == 0) {
val = diskio->current;
- else
+ } else {
val = diskio->current_write;
+ }
/* TODO: move this correction from kB to kB/s elsewhere
* (or get rid of it??) */
@@ -161,7 +164,7 @@ void print_diskio_write(struct text_object *obj, char *p, int p_max_size) {
#ifdef BUILD_X11
void parse_diskiograph_arg(struct text_object *obj, const char *arg) {
- char *buf = 0;
+ char *buf = nullptr;
buf = scan_graph(obj, arg, 0);
obj->data.opaque = prepare_diskio_stat(dev_name(buf));
@@ -169,21 +172,21 @@ void parse_diskiograph_arg(struct text_object *obj, const char *arg) {
}
double diskiographval(struct text_object *obj) {
- struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
+ auto *diskio = static_cast(obj->data.opaque);
- return (diskio ? diskio->current : 0);
+ return (diskio != nullptr ? diskio->current : 0);
}
double diskiographval_read(struct text_object *obj) {
- struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
+ auto *diskio = static_cast(obj->data.opaque);
- return (diskio ? diskio->current_read : 0);
+ return (diskio != nullptr ? diskio->current_read : 0);
}
double diskiographval_write(struct text_object *obj) {
- struct diskio_stat *diskio = (struct diskio_stat *)obj->data.opaque;
+ auto *diskio = static_cast(obj->data.opaque);
- return (diskio ? diskio->current_write : 0);
+ return (diskio != nullptr ? diskio->current_write : 0);
}
#endif /* BUILD_X11 */
@@ -212,9 +215,9 @@ void update_diskio_values(struct diskio_stat *ds, unsigned int reads,
sum_r += ds->sample_read[i];
sum_w += ds->sample_write[i];
}
- ds->current = sum / (double)samples;
- ds->current_read = sum_r / (double)samples;
- ds->current_write = sum_w / (double)samples;
+ ds->current = sum / static_cast(samples);
+ ds->current_read = sum_r / static_cast(samples);
+ ds->current_write = sum_w / static_cast(samples);
/* shift sample history */
for (i = samples - 1; i > 0; i--) {
diff --git a/src/dragonfly.cc b/src/dragonfly.cc
index e3c5aca0..689ceb34 100644
--- a/src/dragonfly.cc
+++ b/src/dragonfly.cc
@@ -67,7 +67,7 @@ static short cpu_setup = 0;
static int getsysctl(const char *name, void *ptr, size_t len) {
size_t nlen = len;
- if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
+ if (sysctlbyname(name, ptr, &nlen, nullptr, 0) == -1) {
fprintf(stderr, "getsysctl(): %s failed '%s'\n", name, strerror(errno));
return -1;
}
@@ -84,9 +84,9 @@ static int swapmode(unsigned long *retavail, unsigned long *retfree) {
int total, used;
size_t len = sizeof(int);
- if (sysctlbyname("vm.swap_size", &total, &len, NULL, 0) == -1)
+ if (sysctlbyname("vm.swap_size", &total, &len, nullptr, 0) == -1)
perror("vm_swap_usage(): vm.swap_size");
- else if (sysctlbyname("vm.swap_anon_use", &used, &len, NULL, 0) == -1)
+ else if (sysctlbyname("vm.swap_anon_use", &used, &len, nullptr, 0) == -1)
perror("vm_swap_usage(): vm.swap_anon_use");
else {
int size = getpagesize();
@@ -109,7 +109,7 @@ int update_uptime(void) {
time_t now;
size_t size = sizeof(boottime);
- if ((sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) && boottime.tv_sec) {
+ if ((sysctl(mib, 2, &boottime, &size, nullptr, 0) != -1) && boottime.tv_sec) {
time(&now);
info.uptime = now - boottime.tv_sec;
} else {
@@ -187,7 +187,7 @@ int update_net_stats(void) {
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- ns = get_net_stat((const char *)ifa->ifa_name, NULL, NULL);
+ ns = get_net_stat((const char *)ifa->ifa_name, nullptr, NULL);
if (ifa->ifa_flags & IFF_UP) {
struct ifaddrs *iftmp;
@@ -201,7 +201,7 @@ int update_net_stats(void) {
}
for (iftmp = ifa->ifa_next;
- iftmp != NULL && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0;
+ iftmp != nullptr && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0;
iftmp = iftmp->ifa_next) {
if (iftmp->ifa_addr->sa_family == AF_INET) {
memcpy(&(ns->addr), iftmp->ifa_addr, iftmp->ifa_addr->sa_len);
@@ -243,7 +243,7 @@ int update_net_stats(void) {
static int kern_proc_all_n() {
size_t len = 0;
- if (sysctlbyname("kern.proc.all_lwp", NULL, &len, NULL, 0) == -1) {
+ if (sysctlbyname("kern.proc.all_lwp", nullptr, &len, NULL, 0) == -1) {
perror("kern.proc.all_lwp");
return -1;
}
@@ -264,7 +264,7 @@ static struct kinfo_proc *kern_proc_all(size_t proc_n) {
struct kinfo_proc *kp = (struct kinfo_proc *)malloc(len);
if (kp) {
- if (sysctlbyname("kern.proc.all_lwp", kp, &len, NULL, 0) == -1)
+ if (sysctlbyname("kern.proc.all_lwp", kp, &len, nullptr, 0) == -1)
perror("kern_proc(): kern.proc.all_lwp");
else
return kp;
@@ -272,7 +272,7 @@ static struct kinfo_proc *kern_proc_all(size_t proc_n) {
} else
perror("malloc");
}
- return NULL;
+ return nullptr;
}
void get_cpu_count(void) {
@@ -286,8 +286,8 @@ void get_cpu_count(void) {
}
info.cpu_usage = (float *)malloc((info.cpu_count + 1) * sizeof(float));
- if (info.cpu_usage == NULL) {
- CRIT_ERR(NULL, NULL, "malloc");
+ if (info.cpu_usage == nullptr) {
+ CRIT_ERR(nullptr, NULL, "malloc");
}
}
@@ -313,7 +313,7 @@ static void stat_cpu(struct cpu_info *cpu, struct kinfo_cputime *percpu,
}
int update_cpu_usage(void) {
- static struct cpu_info *cpu = NULL;
+ static struct cpu_info *cpu = nullptr;
extern void *global_cpu;
/* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */
@@ -335,7 +335,7 @@ int update_cpu_usage(void) {
info.cpu_count * sizeof(struct kinfo_cputime));
if (percpu) {
- if (sysctlbyname("kern.cputime", percpu, &percpu_n, NULL, 0) == -1 &&
+ if (sysctlbyname("kern.cputime", percpu, &percpu_n, nullptr, 0) == -1 &&
errno != ENOMEM) {
printf("update_cpu_usage(): with %d cpu(s) ", info.cpu_count);
perror("kern.cputime");
@@ -545,7 +545,7 @@ void update_wifi_stats(void)
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- ns = get_net_stat((const char *) ifa->ifa_name, NULL, NULL);
+ ns = get_net_stat((const char *) ifa->ifa_name, nullptr, NULL);
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@@ -586,7 +586,7 @@ cleanup:
int update_diskio(void) {
int devs_count, num_selected, num_selections, dn;
- struct device_selection *dev_select = NULL;
+ struct device_selection *dev_select = nullptr;
long select_generation;
static struct statinfo statinfo_cur;
char device_name[DEFAULT_TEXT_BUFFER_SIZE];
@@ -606,7 +606,7 @@ int update_diskio(void) {
devs_count = statinfo_cur.dinfo->numdevs;
if (selectdevs(&dev_select, &num_selected, &num_selections,
&select_generation, statinfo_cur.dinfo->generation,
- statinfo_cur.dinfo->devices, devs_count, NULL, 0, NULL, 0,
+ statinfo_cur.dinfo->devices, devs_count, nullptr, 0, NULL, 0,
DS_SELECT_ONLY, MAXSHOWDEVS, 1) >= 0) {
for (dn = 0; dn < devs_count; dn++) {
int di;
diff --git a/src/entropy.cc b/src/entropy.cc
index 0b412cd2..9884b262 100644
--- a/src/entropy.cc
+++ b/src/entropy.cc
@@ -49,14 +49,14 @@
#endif
struct _entropy {
- _entropy() : avail(0), poolsize(0) {}
- unsigned int avail;
- unsigned int poolsize;
+ _entropy() = default;
+ unsigned int avail{0};
+ unsigned int poolsize{0};
};
static _entropy entropy;
-int update_entropy(void) {
+int update_entropy() {
get_entropy_avail(&entropy.avail);
get_entropy_poolsize(&entropy.poolsize);
return 0;
@@ -69,7 +69,8 @@ void print_entropy_avail(struct text_object *obj, char *p, int p_max_size) {
uint8_t entropy_percentage(struct text_object *obj) {
(void)obj;
- return round_to_int((double)entropy.avail * 100.0 / (double)entropy.poolsize);
+ return round_to_int(static_cast(entropy.avail) * 100.0 /
+ static_cast(entropy.poolsize));
}
void print_entropy_poolsize(struct text_object *obj, char *p, int p_max_size) {
@@ -80,5 +81,5 @@ void print_entropy_poolsize(struct text_object *obj, char *p, int p_max_size) {
double entropy_barval(struct text_object *obj) {
(void)obj;
- return (double)entropy.avail / entropy.poolsize;
+ return static_cast(entropy.avail) / entropy.poolsize;
}
diff --git a/src/eve.cc b/src/eve.cc
index 657e1247..a7fbb080 100644
--- a/src/eve.cc
+++ b/src/eve.cc
@@ -103,13 +103,13 @@ int parseTrainingXml(char *data, Character *s) {
struct tm end_tm, cache_tm;
// initialize the time structs
- time_t now = time(NULL);
+ time_t now = time(nullptr);
localtime_r(&now, &end_tm);
localtime_r(&now, &cache_tm);
if (!data) return 1;
- doc = xmlReadMemory(data, strlen(data), "", NULL, XML_PARSE_RECOVER);
+ doc = xmlReadMemory(data, strlen(data), "", nullptr, XML_PARSE_RECOVER);
root = xmlDocGetRootElement(doc);
for (n = root->children; n; n = n->next) {
@@ -153,14 +153,14 @@ int parseTrainingXml(char *data, Character *s) {
static char *getXmlFromAPI(const char *apiKeyID, const char *apiVCode,
const char *charid, const char *url) {
- struct curl_httppost *post = NULL;
- struct curl_httppost *last = NULL;
+ struct curl_httppost *post = nullptr;
+ struct curl_httppost *last = nullptr;
struct xmlData chr;
char *content;
CURL *curl_handle;
int rc = 0;
- chr.data = NULL;
+ chr.data = nullptr;
chr.size = 0;
curl_handle = curl_easy_init();
@@ -183,8 +183,8 @@ static char *getXmlFromAPI(const char *apiKeyID, const char *apiVCode,
rc = curl_easy_perform(curl_handle);
- if (chr.data == NULL) {
- return NULL;
+ if (chr.data == nullptr) {
+ return nullptr;
}
content = strdup(chr.data);
@@ -197,9 +197,9 @@ static void init_eve(void) {
int i;
for (i = 0; i < MAXCHARS; i++) {
- eveCharacters[i].charid = NULL;
- eveCharacters[i].skillname = NULL;
- eveCharacters[i].time = NULL;
+ eveCharacters[i].charid = nullptr;
+ eveCharacters[i].skillname = nullptr;
+ eveCharacters[i].time = nullptr;
eveCharacters[i].level = 0;
eveCharacters[i].skill = 0;
eveCharacters[i].delay = 0;
@@ -210,7 +210,7 @@ static int isCacheValid(struct tm cached) {
// struct timeval tv;
// struct timezone tz;
double offset = 0;
- time_t now = time(NULL);
+ time_t now = time(nullptr);
time_t cache = 0;
double diff = 0;
@@ -232,7 +232,7 @@ static char *formatTime(struct tm *ends) {
// struct timeval tv;
// struct timezone tz;
double offset = 0;
- time_t now = time(NULL);
+ time_t now = time(nullptr);
time_t tEnds = 0;
long lin = 0;
long lie = 0;
@@ -279,20 +279,20 @@ static void writeSkilltree(char *content, const char *filename) {
static char *getSkillname(const char *file, int skillid) {
char *skilltree;
- char *skill = NULL;
+ char *skill = nullptr;
xmlNodePtr n;
xmlDocPtr doc = 0;
xmlNodePtr root = 0;
- skilltree = getXmlFromAPI(NULL, NULL, NULL, EVEURL_SKILLTREE);
+ skilltree = getXmlFromAPI(nullptr, NULL, NULL, EVEURL_SKILLTREE);
if (skilltree) {
writeSkilltree(skilltree, file);
free(skilltree);
}
- doc = xmlReadFile(file, NULL, XML_PARSE_RECOVER);
+ doc = xmlReadFile(file, nullptr, XML_PARSE_RECOVER);
unlink(file);
- if (!doc) return NULL;
+ if (!doc) return nullptr;
root = xmlDocGetRootElement(doc);
@@ -307,10 +307,10 @@ static char *getSkillname(const char *file, int skillid) {
for (r = q->children; r; r = r->next) {
xmlElementPtr ele = (xmlElementPtr)r;
xmlAttrPtr attr = (xmlAttrPtr)ele->attributes;
- char *mySkill = NULL;
+ char *mySkill = nullptr;
int id;
- while (attr != NULL) {
+ while (attr != nullptr) {
if (!strcasecmp((const char *)attr->name, "typeName")) {
mySkill = strdup((const char *)attr->children->content);
} else if (!strcasecmp((const char *)attr->name, "typeID")) {
@@ -337,7 +337,7 @@ END:
}
static char *eve(char *apiKeyID, char *apiVCode, char *charid) {
- Character *chr = NULL;
+ Character *chr = nullptr;
char skillfile[] = "/tmp/.cesfXXXXXX";
int i = 0;
char *output = 0;
@@ -349,7 +349,7 @@ static char *eve(char *apiKeyID, char *apiVCode, char *charid) {
int tmp_fd, old_umask;
for (i = 0; i < num_chars; i++) {
- if (eveCharacters[i].charid != NULL) {
+ if (eveCharacters[i].charid != nullptr) {
if (strcasecmp(eveCharacters[i].charid, charid) == 0) {
chr = &eveCharacters[i];
break;
@@ -358,7 +358,7 @@ static char *eve(char *apiKeyID, char *apiVCode, char *charid) {
}
if (!chr) {
- if (num_chars == MAXCHARS - 1) return NULL;
+ if (num_chars == MAXCHARS - 1) return nullptr;
chr = &eveCharacters[num_chars];
memset(chr, 0, sizeof(Character));
chr->charid = strdup(charid);
@@ -366,7 +366,7 @@ static char *eve(char *apiKeyID, char *apiVCode, char *charid) {
}
if (chr->delay > 0) {
- now = time(NULL);
+ now = time(nullptr);
if (now < chr->delay) {
output = strdup("Server error");
return output;
@@ -386,9 +386,9 @@ static char *eve(char *apiKeyID, char *apiVCode, char *charid) {
}
} else {
content = getXmlFromAPI(apiKeyID, apiVCode, charid, EVEURL_TRAINING);
- if (content == NULL) {
+ if (content == nullptr) {
error = strdup("Server error");
- now = time(NULL);
+ now = time(nullptr);
now += (time_t)1800;
chr->delay = now;
return error;
diff --git a/src/exec.cc b/src/exec.cc
index df29c180..3eeb13b3 100644
--- a/src/exec.cc
+++ b/src/exec.cc
@@ -28,11 +28,12 @@
*/
#include "exec.h"
-#include