Make GitLab build work with clang checks.
This commit is contained in:
@@ -17,7 +17,7 @@ AllowShortLoopsOnASingleLine: true
|
|||||||
AlwaysBreakAfterDefinitionReturnType: None
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: true
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
AlwaysBreakTemplateDeclarations: true
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
BinPackArguments: true
|
BinPackArguments: true
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
@@ -39,6 +39,7 @@ BraceWrapping:
|
|||||||
BreakBeforeBinaryOperators: None
|
BreakBeforeBinaryOperators: None
|
||||||
BreakBeforeBraces: Attach
|
BreakBeforeBraces: Attach
|
||||||
BreakBeforeInheritanceComma: false
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializersBeforeComma: false
|
BreakConstructorInitializersBeforeComma: false
|
||||||
BreakConstructorInitializers: BeforeColon
|
BreakConstructorInitializers: BeforeColon
|
||||||
@@ -81,6 +82,7 @@ MacroBlockBegin: ''
|
|||||||
MacroBlockEnd: ''
|
MacroBlockEnd: ''
|
||||||
MaxEmptyLinesToKeep: 1
|
MaxEmptyLinesToKeep: 1
|
||||||
NamespaceIndentation: None
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Never
|
||||||
ObjCBlockIndentWidth: 2
|
ObjCBlockIndentWidth: 2
|
||||||
ObjCSpaceAfterProperty: false
|
ObjCSpaceAfterProperty: false
|
||||||
ObjCSpaceBeforeProtocolList: false
|
ObjCSpaceBeforeProtocolList: false
|
||||||
@@ -89,12 +91,37 @@ PenaltyBreakBeforeFirstCallParameter: 1
|
|||||||
PenaltyBreakComment: 300
|
PenaltyBreakComment: 300
|
||||||
PenaltyBreakFirstLessLess: 120
|
PenaltyBreakFirstLessLess: 120
|
||||||
PenaltyBreakString: 1000
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
PenaltyExcessCharacter: 1000000
|
PenaltyExcessCharacter: 1000000
|
||||||
PenaltyReturnTypeOnItsOwnLine: 200
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
RawStringFormats:
|
RawStringFormats:
|
||||||
- Delimiter: pb
|
- Language: Cpp
|
||||||
Language: TextProto
|
Delimiters:
|
||||||
|
- cc
|
||||||
|
- CC
|
||||||
|
- cpp
|
||||||
|
- Cpp
|
||||||
|
- CPP
|
||||||
|
- 'c++'
|
||||||
|
- 'C++'
|
||||||
|
CanonicalDelimiter: ''
|
||||||
|
BasedOnStyle: google
|
||||||
|
- Language: TextProto
|
||||||
|
Delimiters:
|
||||||
|
- pb
|
||||||
|
- PB
|
||||||
|
- proto
|
||||||
|
- PROTO
|
||||||
|
EnclosingFunctions:
|
||||||
|
- EqualsProto
|
||||||
|
- EquivToProto
|
||||||
|
- PARSE_PARTIAL_TEXT_PROTO
|
||||||
|
- PARSE_TEST_PROTO
|
||||||
|
- PARSE_TEXT_PROTO
|
||||||
|
- ParseTextOrDie
|
||||||
|
- ParseTextProtoOrDie
|
||||||
|
CanonicalDelimiter: ''
|
||||||
BasedOnStyle: google
|
BasedOnStyle: google
|
||||||
ReflowComments: true
|
ReflowComments: true
|
||||||
SortIncludes: true
|
SortIncludes: true
|
||||||
@@ -102,7 +129,11 @@ SortUsingDeclarations: true
|
|||||||
SpaceAfterCStyleCast: false
|
SpaceAfterCStyleCast: false
|
||||||
SpaceAfterTemplateKeyword: true
|
SpaceAfterTemplateKeyword: true
|
||||||
SpaceBeforeAssignmentOperators: true
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
SpaceBeforeParens: ControlStatements
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
SpaceInEmptyParentheses: false
|
SpaceInEmptyParentheses: false
|
||||||
SpacesBeforeTrailingComments: 2
|
SpacesBeforeTrailingComments: 2
|
||||||
SpacesInAngles: false
|
SpacesInAngles: false
|
||||||
|
52
.clang-tidy
Normal file
52
.clang-tidy
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
Checks: 'clang-diagnostic-*,clang-analyzer-*,google-*'
|
||||||
|
WarningsAsErrors: ''
|
||||||
|
HeaderFilterRegex: ''
|
||||||
|
AnalyzeTemporaryDtors: false
|
||||||
|
FormatStyle: none
|
||||||
|
User: brenden
|
||||||
|
CheckOptions:
|
||||||
|
- key: google-build-namespaces.HeaderFileExtensions
|
||||||
|
value: ',h,hh,hpp,hxx'
|
||||||
|
- key: google-global-names-in-headers.HeaderFileExtensions
|
||||||
|
value: ',h,hh,hpp,hxx'
|
||||||
|
- key: google-readability-braces-around-statements.ShortStatementLines
|
||||||
|
value: '1'
|
||||||
|
- key: google-readability-function-size.BranchThreshold
|
||||||
|
value: '4294967295'
|
||||||
|
- key: google-readability-function-size.LineThreshold
|
||||||
|
value: '4294967295'
|
||||||
|
- key: google-readability-function-size.NestingThreshold
|
||||||
|
value: '4294967295'
|
||||||
|
- key: google-readability-function-size.ParameterThreshold
|
||||||
|
value: '4294967295'
|
||||||
|
- key: google-readability-function-size.StatementThreshold
|
||||||
|
value: '800'
|
||||||
|
- key: google-readability-function-size.VariableThreshold
|
||||||
|
value: '4294967295'
|
||||||
|
- key: google-readability-namespace-comments.ShortNamespaceLines
|
||||||
|
value: '10'
|
||||||
|
- key: google-readability-namespace-comments.SpacesBeforeComments
|
||||||
|
value: '2'
|
||||||
|
- key: google-runtime-int.SignedTypePrefix
|
||||||
|
value: int
|
||||||
|
- key: google-runtime-int.TypeSuffix
|
||||||
|
value: ''
|
||||||
|
- key: google-runtime-int.UnsignedTypePrefix
|
||||||
|
value: uint
|
||||||
|
- key: google-runtime-references.WhiteListTypes
|
||||||
|
value: ''
|
||||||
|
- key: modernize-loop-convert.MaxCopySize
|
||||||
|
value: '16'
|
||||||
|
- key: modernize-loop-convert.MinConfidence
|
||||||
|
value: reasonable
|
||||||
|
- key: modernize-loop-convert.NamingStyle
|
||||||
|
value: CamelCase
|
||||||
|
- key: modernize-pass-by-value.IncludeStyle
|
||||||
|
value: llvm
|
||||||
|
- key: modernize-replace-auto-ptr.IncludeStyle
|
||||||
|
value: llvm
|
||||||
|
- key: modernize-use-nullptr.NullMacros
|
||||||
|
value: 'NULL'
|
||||||
|
...
|
||||||
|
|
@@ -1,27 +1,65 @@
|
|||||||
stages:
|
stages:
|
||||||
|
- dependencies
|
||||||
- build
|
- build
|
||||||
- test
|
- test
|
||||||
- lint
|
- lint
|
||||||
|
|
||||||
image: brndnmtthws/conky-builder:latest
|
|
||||||
variables:
|
variables:
|
||||||
CC: clang-7
|
CC: clang-7
|
||||||
CXX: clang++-7
|
CXX: clang++-7
|
||||||
|
DOCKER_DRIVER: overlay2
|
||||||
|
DOCKER_HOST: tcp://localhost:2375/
|
||||||
|
|
||||||
|
docker_builder:
|
||||||
|
stage: dependencies
|
||||||
|
image: docker:stable
|
||||||
|
only:
|
||||||
|
changes:
|
||||||
|
- Dockerfile.builder
|
||||||
|
services:
|
||||||
|
- docker:dind
|
||||||
|
before_script:
|
||||||
|
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
|
||||||
|
script:
|
||||||
|
- docker pull $CI_REGISTRY_IMAGE/builder:latest || true
|
||||||
|
- docker build -f Dockerfile.builder --cache-from $CI_REGISTRY_IMAGE/builder:latest --tag $CI_REGISTRY_IMAGE/builder:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE/builder:latest .
|
||||||
|
- docker push ${CI_REGISTRY_IMAGE}/builder:$CI_COMMIT_SHA
|
||||||
|
- docker push ${CI_REGISTRY_IMAGE}/builder:latest
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||||
|
stage: build
|
||||||
script:
|
script:
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
- cmake ..
|
- cmake -DMAINTAINER_MODE=ON ..
|
||||||
- make -j4
|
- make -j4
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 day
|
||||||
|
paths:
|
||||||
|
- build/
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||||
|
stage: test
|
||||||
script:
|
script:
|
||||||
- cd build
|
- cd build
|
||||||
- make test
|
- cmake -DCMAKE_SOURCE_DIR=$(dirname `pwd`) -DCMAKE_BINARY_DIR=`pwd` -DMAINTAINER_MODE=ON -DBUILD_TESTS=ON ..
|
||||||
|
- make -j4
|
||||||
|
- make -j4 test
|
||||||
|
|
||||||
lint:
|
check-clang-tidy:
|
||||||
|
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||||
|
stage: test
|
||||||
script:
|
script:
|
||||||
- cd build
|
- cd build
|
||||||
- cmake -DCHECK_CODE_QUALITY=ON ..
|
- cmake -DCMAKE_SOURCE_DIR=$(dirname `pwd`) -DCMAKE_BINARY_DIR=`pwd` -DMAINTAINER_MODE=ON -DCHECK_CODE_QUALITY=ON ..
|
||||||
- make check
|
- make -j4 check-clang-tidy
|
||||||
|
|
||||||
|
check-clang-format:
|
||||||
|
image: $CI_REGISTRY_IMAGE/builder:latest
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- cd build
|
||||||
|
- cmake -DCMAKE_SOURCE_DIR=$(dirname `pwd`) -DCMAKE_BINARY_DIR=`pwd` -DMAINTAINER_MODE=ON -DCHECK_CODE_QUALITY=ON ..
|
||||||
|
- make -j4 check-clang-format
|
||||||
|
@@ -101,12 +101,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|||||||
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
|
|
||||||
if(CHECK_CODE_QUALITY)
|
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)
|
find_package(ClangTidy)
|
||||||
|
find_package(ClangFormat)
|
||||||
endif(CHECK_CODE_QUALITY)
|
endif(CHECK_CODE_QUALITY)
|
||||||
|
@@ -1,16 +1,11 @@
|
|||||||
FROM ubuntu:bionic
|
FROM ubuntu:bionic
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& DEBIAN_FRONTEND=noninteractive \
|
&& DEBIAN_FRONTEND=noninteractive \
|
||||||
apt-get install -qy --no-install-recommends \
|
apt-get install -qy --no-install-recommends \
|
||||||
software-properties-common \
|
software-properties-common \
|
||||||
wget \
|
wget \
|
||||||
gpg-agent \
|
gpg-agent \
|
||||||
&& wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
|
||||||
&& apt-key add llvm-snapshot.gpg.key \
|
|
||||||
&& add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main' \
|
|
||||||
&& DEBIAN_FRONTEND=noninteractive \
|
|
||||||
apt-get install -qy --no-install-recommends \
|
|
||||||
software-properties-common \
|
|
||||||
cmake \
|
cmake \
|
||||||
git \
|
git \
|
||||||
audacious-dev \
|
audacious-dev \
|
||||||
@@ -35,6 +30,16 @@ RUN apt-get update \
|
|||||||
libxmmsclient-dev \
|
libxmmsclient-dev \
|
||||||
libxnvctrl-dev \
|
libxnvctrl-dev \
|
||||||
ncurses-dev \
|
ncurses-dev \
|
||||||
|
lcov \
|
||||||
|
docbook2x \
|
||||||
|
man \
|
||||||
|
less
|
||||||
|
|
||||||
|
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||||
|
&& apt-key add llvm-snapshot.gpg.key \
|
||||||
|
&& add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main' \
|
||||||
|
&& DEBIAN_FRONTEND=noninteractive \
|
||||||
|
apt-get install -qy --no-install-recommends \
|
||||||
clang-7 \
|
clang-7 \
|
||||||
lldb-7 \
|
lldb-7 \
|
||||||
lld-7 \
|
lld-7 \
|
||||||
|
326
bin/run-clang-format.py
Executable file
326
bin/run-clang-format.py
Executable file
@@ -0,0 +1,326 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""A wrapper script around clang-format, suitable for linting multiple files
|
||||||
|
and to use for continuous integration.
|
||||||
|
|
||||||
|
This is an alternative API for the clang-format command line.
|
||||||
|
It runs over multiple files and directories in parallel.
|
||||||
|
A diff output is produced and a sensible exit code is returned.
|
||||||
|
|
||||||
|
Source: https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import codecs
|
||||||
|
import difflib
|
||||||
|
import fnmatch
|
||||||
|
import io
|
||||||
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'
|
||||||
|
|
||||||
|
|
||||||
|
class ExitStatus:
|
||||||
|
SUCCESS = 0
|
||||||
|
DIFF = 1
|
||||||
|
TROUBLE = 2
|
||||||
|
|
||||||
|
|
||||||
|
def list_files(files, recursive=False, extensions=None, exclude=None):
|
||||||
|
if extensions is None:
|
||||||
|
extensions = []
|
||||||
|
if exclude is None:
|
||||||
|
exclude = []
|
||||||
|
|
||||||
|
out = []
|
||||||
|
for file in files:
|
||||||
|
if recursive and os.path.isdir(file):
|
||||||
|
for dirpath, dnames, fnames in os.walk(file):
|
||||||
|
fpaths = [os.path.join(dirpath, fname) for fname in fnames]
|
||||||
|
for pattern in exclude:
|
||||||
|
# os.walk() supports trimming down the dnames list
|
||||||
|
# by modifying it in-place,
|
||||||
|
# to avoid unnecessary directory listings.
|
||||||
|
dnames[:] = [
|
||||||
|
x for x in dnames
|
||||||
|
if
|
||||||
|
not fnmatch.fnmatch(os.path.join(dirpath, x), pattern)
|
||||||
|
]
|
||||||
|
fpaths = [
|
||||||
|
x for x in fpaths if not fnmatch.fnmatch(x, pattern)
|
||||||
|
]
|
||||||
|
for f in fpaths:
|
||||||
|
ext = os.path.splitext(f)[1][1:]
|
||||||
|
if ext in extensions:
|
||||||
|
out.append(f)
|
||||||
|
else:
|
||||||
|
out.append(file)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def make_diff(file, original, reformatted):
|
||||||
|
return list(
|
||||||
|
difflib.unified_diff(
|
||||||
|
original,
|
||||||
|
reformatted,
|
||||||
|
fromfile='{}\t(original)'.format(file),
|
||||||
|
tofile='{}\t(reformatted)'.format(file),
|
||||||
|
n=3))
|
||||||
|
|
||||||
|
|
||||||
|
class DiffError(Exception):
|
||||||
|
def __init__(self, message, errs=None):
|
||||||
|
super(DiffError, self).__init__(message)
|
||||||
|
self.errs = errs or []
|
||||||
|
|
||||||
|
|
||||||
|
class UnexpectedError(Exception):
|
||||||
|
def __init__(self, message, exc=None):
|
||||||
|
super(UnexpectedError, self).__init__(message)
|
||||||
|
self.formatted_traceback = traceback.format_exc()
|
||||||
|
self.exc = exc
|
||||||
|
|
||||||
|
|
||||||
|
def run_clang_format_diff_wrapper(args, file):
|
||||||
|
try:
|
||||||
|
ret = run_clang_format_diff(args, file)
|
||||||
|
return ret
|
||||||
|
except DiffError:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__,
|
||||||
|
e), e)
|
||||||
|
|
||||||
|
|
||||||
|
def run_clang_format_diff(args, file):
|
||||||
|
try:
|
||||||
|
with io.open(file, 'r', encoding='utf-8') as f:
|
||||||
|
original = f.readlines()
|
||||||
|
except IOError as exc:
|
||||||
|
raise DiffError(str(exc))
|
||||||
|
invocation = [args.clang_format_executable, file]
|
||||||
|
|
||||||
|
# Use of utf-8 to decode the process output.
|
||||||
|
#
|
||||||
|
# Hopefully, this is the correct thing to do.
|
||||||
|
#
|
||||||
|
# It's done due to the following assumptions (which may be incorrect):
|
||||||
|
# - clang-format will returns the bytes read from the files as-is,
|
||||||
|
# without conversion, and it is already assumed that the files use utf-8.
|
||||||
|
# - if the diagnostics were internationalized, they would use utf-8:
|
||||||
|
# > Adding Translations to Clang
|
||||||
|
# >
|
||||||
|
# > Not possible yet!
|
||||||
|
# > Diagnostic strings should be written in UTF-8,
|
||||||
|
# > the client can translate to the relevant code page if needed.
|
||||||
|
# > Each translation completely replaces the format string
|
||||||
|
# > for the diagnostic.
|
||||||
|
# > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation
|
||||||
|
#
|
||||||
|
# It's not pretty, due to Python 2 & 3 compatibility.
|
||||||
|
encoding_py3 = {}
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
encoding_py3['encoding'] = 'utf-8'
|
||||||
|
|
||||||
|
try:
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
invocation,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True,
|
||||||
|
**encoding_py3)
|
||||||
|
except OSError as exc:
|
||||||
|
raise DiffError(str(exc))
|
||||||
|
proc_stdout = proc.stdout
|
||||||
|
proc_stderr = proc.stderr
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
# make the pipes compatible with Python 3,
|
||||||
|
# reading lines should output unicode
|
||||||
|
encoding = 'utf-8'
|
||||||
|
proc_stdout = codecs.getreader(encoding)(proc_stdout)
|
||||||
|
proc_stderr = codecs.getreader(encoding)(proc_stderr)
|
||||||
|
# hopefully the stderr pipe won't get full and block the process
|
||||||
|
outs = list(proc_stdout.readlines())
|
||||||
|
errs = list(proc_stderr.readlines())
|
||||||
|
proc.wait()
|
||||||
|
if proc.returncode:
|
||||||
|
raise DiffError("clang-format exited with status {}: '{}'".format(
|
||||||
|
proc.returncode, file), errs)
|
||||||
|
return make_diff(file, original, outs), errs
|
||||||
|
|
||||||
|
|
||||||
|
def bold_red(s):
|
||||||
|
return '\x1b[1m\x1b[31m' + s + '\x1b[0m'
|
||||||
|
|
||||||
|
|
||||||
|
def colorize(diff_lines):
|
||||||
|
def bold(s):
|
||||||
|
return '\x1b[1m' + s + '\x1b[0m'
|
||||||
|
|
||||||
|
def cyan(s):
|
||||||
|
return '\x1b[36m' + s + '\x1b[0m'
|
||||||
|
|
||||||
|
def green(s):
|
||||||
|
return '\x1b[32m' + s + '\x1b[0m'
|
||||||
|
|
||||||
|
def red(s):
|
||||||
|
return '\x1b[31m' + s + '\x1b[0m'
|
||||||
|
|
||||||
|
for line in diff_lines:
|
||||||
|
if line[:4] in ['--- ', '+++ ']:
|
||||||
|
yield bold(line)
|
||||||
|
elif line.startswith('@@ '):
|
||||||
|
yield cyan(line)
|
||||||
|
elif line.startswith('+'):
|
||||||
|
yield green(line)
|
||||||
|
elif line.startswith('-'):
|
||||||
|
yield red(line)
|
||||||
|
else:
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def print_diff(diff_lines, use_color):
|
||||||
|
if use_color:
|
||||||
|
diff_lines = colorize(diff_lines)
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
sys.stdout.writelines((l.encode('utf-8') for l in diff_lines))
|
||||||
|
else:
|
||||||
|
sys.stdout.writelines(diff_lines)
|
||||||
|
|
||||||
|
|
||||||
|
def print_trouble(prog, message, use_colors):
|
||||||
|
error_text = 'error:'
|
||||||
|
if use_colors:
|
||||||
|
error_text = bold_red(error_text)
|
||||||
|
print("{}: {} {}".format(prog, error_text, message), file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument(
|
||||||
|
'--clang-format-executable',
|
||||||
|
metavar='EXECUTABLE',
|
||||||
|
help='path to the clang-format executable',
|
||||||
|
default='clang-format')
|
||||||
|
parser.add_argument(
|
||||||
|
'--extensions',
|
||||||
|
help='comma separated list of file extensions (default: {})'.format(
|
||||||
|
DEFAULT_EXTENSIONS),
|
||||||
|
default=DEFAULT_EXTENSIONS)
|
||||||
|
parser.add_argument(
|
||||||
|
'-r',
|
||||||
|
'--recursive',
|
||||||
|
action='store_true',
|
||||||
|
help='run recursively over directories')
|
||||||
|
parser.add_argument('files', metavar='file', nargs='+')
|
||||||
|
parser.add_argument(
|
||||||
|
'-q',
|
||||||
|
'--quiet',
|
||||||
|
action='store_true')
|
||||||
|
parser.add_argument(
|
||||||
|
'-j',
|
||||||
|
metavar='N',
|
||||||
|
type=int,
|
||||||
|
default=0,
|
||||||
|
help='run N clang-format jobs in parallel'
|
||||||
|
' (default number of cpus + 1)')
|
||||||
|
parser.add_argument(
|
||||||
|
'--color',
|
||||||
|
default='auto',
|
||||||
|
choices=['auto', 'always', 'never'],
|
||||||
|
help='show colored diff (default: auto)')
|
||||||
|
parser.add_argument(
|
||||||
|
'-e',
|
||||||
|
'--exclude',
|
||||||
|
metavar='PATTERN',
|
||||||
|
action='append',
|
||||||
|
default=[],
|
||||||
|
help='exclude paths matching the given glob-like pattern(s)'
|
||||||
|
' from recursive search')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# use default signal handling, like diff return SIGINT value on ^C
|
||||||
|
# https://bugs.python.org/issue14229#msg156446
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
|
try:
|
||||||
|
signal.SIGPIPE
|
||||||
|
except AttributeError:
|
||||||
|
# compatibility, SIGPIPE does not exist on Windows
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||||
|
|
||||||
|
colored_stdout = False
|
||||||
|
colored_stderr = False
|
||||||
|
if args.color == 'always':
|
||||||
|
colored_stdout = True
|
||||||
|
colored_stderr = True
|
||||||
|
elif args.color == 'auto':
|
||||||
|
colored_stdout = sys.stdout.isatty()
|
||||||
|
colored_stderr = sys.stderr.isatty()
|
||||||
|
|
||||||
|
retcode = ExitStatus.SUCCESS
|
||||||
|
files = list_files(
|
||||||
|
args.files,
|
||||||
|
recursive=args.recursive,
|
||||||
|
exclude=args.exclude,
|
||||||
|
extensions=args.extensions.split(','))
|
||||||
|
|
||||||
|
if not files:
|
||||||
|
return
|
||||||
|
|
||||||
|
njobs = args.j
|
||||||
|
if njobs == 0:
|
||||||
|
njobs = multiprocessing.cpu_count() + 1
|
||||||
|
njobs = min(len(files), njobs)
|
||||||
|
|
||||||
|
if njobs == 1:
|
||||||
|
# execute directly instead of in a pool,
|
||||||
|
# less overhead, simpler stacktraces
|
||||||
|
it = (run_clang_format_diff_wrapper(args, file) for file in files)
|
||||||
|
pool = None
|
||||||
|
else:
|
||||||
|
pool = multiprocessing.Pool(njobs)
|
||||||
|
it = pool.imap_unordered(
|
||||||
|
partial(run_clang_format_diff_wrapper, args), files)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
outs, errs = next(it)
|
||||||
|
except StopIteration:
|
||||||
|
break
|
||||||
|
except DiffError as e:
|
||||||
|
print_trouble(parser.prog, str(e), use_colors=colored_stderr)
|
||||||
|
retcode = ExitStatus.TROUBLE
|
||||||
|
sys.stderr.writelines(e.errs)
|
||||||
|
except UnexpectedError as e:
|
||||||
|
print_trouble(parser.prog, str(e), use_colors=colored_stderr)
|
||||||
|
sys.stderr.write(e.formatted_traceback)
|
||||||
|
retcode = ExitStatus.TROUBLE
|
||||||
|
# stop at the first unexpected error,
|
||||||
|
# something could be very wrong,
|
||||||
|
# don't process all files unnecessarily
|
||||||
|
if pool:
|
||||||
|
pool.terminate()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
sys.stderr.writelines(errs)
|
||||||
|
if outs == []:
|
||||||
|
continue
|
||||||
|
if not args.quiet:
|
||||||
|
print_diff(outs, use_color=colored_stdout)
|
||||||
|
if retcode == ExitStatus.SUCCESS:
|
||||||
|
retcode = ExitStatus.DIFF
|
||||||
|
return retcode
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
23
cmake/FindClangFormat.cmake
Normal file
23
cmake/FindClangFormat.cmake
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Find Clang format
|
||||||
|
#
|
||||||
|
|
||||||
|
set(CLANG_FORMAT_BIN_NAME
|
||||||
|
clang-format
|
||||||
|
clang-format-5.0
|
||||||
|
clang-format-6.0
|
||||||
|
clang-format-7)
|
||||||
|
|
||||||
|
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()
|
@@ -1,17 +1,7 @@
|
|||||||
# Find Clang tidy
|
# Find Clang tidy
|
||||||
#
|
#
|
||||||
|
|
||||||
if(NOT CLANG_TIDY_BIN_NAME)
|
set(CLANG_TIDY_BIN_NAME clang-tidy clang-tidy-5.0 clang-tidy-6.0 clang-tidy-7)
|
||||||
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})
|
find_program(CLANG_TIDY_BIN NAMES ${CLANG_TIDY_BIN_NAME})
|
||||||
|
|
||||||
|
27
cmake/clang-format.cmake
Normal file
27
cmake/clang-format.cmake
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
set(CLANG_FORMAT_CXX_FILE_EXTENSIONS
|
||||||
|
${CLANG_FORMAT_CXX_FILE_EXTENSIONS}
|
||||||
|
*.cpp
|
||||||
|
*.h
|
||||||
|
*.cxx
|
||||||
|
*.hxx
|
||||||
|
*.hpp
|
||||||
|
*.cc
|
||||||
|
*.hh
|
||||||
|
*.ipp)
|
||||||
|
|
||||||
|
foreach(PATTERN ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
|
||||||
|
list(APPEND CLANG_FORMAT_CXX_PATTERN ${CMAKE_SOURCE_DIR}/src/${PATTERN})
|
||||||
|
list(APPEND CLANG_FORMAT_CXX_PATTERN ${CMAKE_SOURCE_DIR}/tests/${PATTERN})
|
||||||
|
list(APPEND CLANG_FORMAT_CXX_PATTERN ${CMAKE_SOURCE_DIR}/lua/${PATTERN})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
file(GLOB_RECURSE CLANG_FORMAT_SRCS ${CLANG_FORMAT_CXX_PATTERN})
|
||||||
|
|
||||||
|
add_custom_target(clang-format
|
||||||
|
COMMAND ${CLANG_FORMAT_BIN} -style=file -i
|
||||||
|
${CLANG_FORMAT_SRCS})
|
||||||
|
add_custom_target(check-clang-format
|
||||||
|
COMMAND ${CMAKE_SOURCE_DIR}/bin/run-clang-format.py
|
||||||
|
--color always
|
||||||
|
--clang-format-executable ${CLANG_FORMAT_BIN}
|
||||||
|
${CLANG_FORMAT_SRCS})
|
@@ -1,15 +1,27 @@
|
|||||||
# Run clang-tidy
|
get_target_property(CLANG_TIDY_SRCS_TMP conky SOURCES)
|
||||||
|
get_target_property(conky_SRC_DIR conky SOURCE_DIR)
|
||||||
|
|
||||||
set(DO_CLANG_TIDY
|
if(BUILD_TESTS)
|
||||||
"${CLANG_TIDY_BIN}"
|
get_target_property(CLANG_TIDY_SRCS_TMP_CORE conky_core SOURCES)
|
||||||
-format-style='{BasedOnStyle:
|
list(APPEND CLANG_TIDY_SRCS_TMP ${CLANG_TIDY_SRCS_TMP_CORE})
|
||||||
google,
|
|
||||||
IndentWidth:
|
|
||||||
2}'
|
|
||||||
-checks=*,-clang-analyzer-alpha.*
|
|
||||||
-fix
|
|
||||||
-fix-errors)
|
|
||||||
|
|
||||||
if(CLANG_TIDY_BIN)
|
|
||||||
set_target_properties(conky PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
foreach(TMP_SRC ${CLANG_TIDY_SRCS_TMP})
|
||||||
|
if("${TMP_SRC}" MATCHES ".*\.cc|.*\.hh|.*\.[chi]pp|.*\.[chi]xx|.*\.ii")
|
||||||
|
list(APPEND CLANG_TIDY_SRCS ${conky_SRC_DIR}/${TMP_SRC})
|
||||||
|
endif()
|
||||||
|
endforeach(TMP_SRC)
|
||||||
|
|
||||||
|
get_target_property(CLANG_INCLUDES_tmp conky INCLUDE_DIRECTORIES)
|
||||||
|
foreach(TMP_INCLUDE ${CLANG_INCLUDES_tmp})
|
||||||
|
list(APPEND CLANG_INCLUDES -I${TMP_INCLUDE})
|
||||||
|
endforeach(TMP_INCLUDE)
|
||||||
|
|
||||||
|
add_custom_target(clang-tidy
|
||||||
|
COMMAND ${CLANG_TIDY_BIN} -config='' -fix -format-style=file
|
||||||
|
${CLANG_TIDY_SRCS}
|
||||||
|
-- -std=c++17 -I${CMAKE_BINARY_DIR} ${CLANG_INCLUDES})
|
||||||
|
add_custom_target(check-clang-tidy
|
||||||
|
COMMAND ${CLANG_TIDY_BIN} -config='' -format-style=file
|
||||||
|
${CLANG_TIDY_SRCS}
|
||||||
|
-- -std=c++17 -I${CMAKE_BINARY_DIR} ${CLANG_INCLUDES})
|
||||||
|
@@ -47,9 +47,6 @@ void destroy_cairo_font_extents_t(cairo_font_extents_t *pointer) {
|
|||||||
free(pointer);
|
free(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_cairo_matrix_t(cairo_matrix_t *pointer) {
|
void destroy_cairo_matrix_t(cairo_matrix_t *pointer) { free(pointer); }
|
||||||
free(pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _LIBCAIRO_HELPER_H_ */
|
#endif /* _LIBCAIRO_HELPER_H_ */
|
||||||
|
@@ -29,13 +29,16 @@ void print_audacious_title(struct text_object *, char *, unsigned int);
|
|||||||
void print_audacious_length(struct text_object *, char *, unsigned int);
|
void print_audacious_length(struct text_object *, char *, unsigned int);
|
||||||
void print_audacious_length_seconds(struct text_object *, char *, unsigned int);
|
void print_audacious_length_seconds(struct text_object *, char *, unsigned int);
|
||||||
void print_audacious_position(struct text_object *, char *, unsigned int);
|
void print_audacious_position(struct text_object *, char *, unsigned int);
|
||||||
void print_audacious_position_seconds(struct text_object *, char *, unsigned int);
|
void print_audacious_position_seconds(struct text_object *, char *,
|
||||||
|
unsigned int);
|
||||||
void print_audacious_bitrate(struct text_object *, char *, unsigned int);
|
void print_audacious_bitrate(struct text_object *, char *, unsigned int);
|
||||||
void print_audacious_frequency(struct text_object *, char *, unsigned int);
|
void print_audacious_frequency(struct text_object *, char *, unsigned int);
|
||||||
void print_audacious_channels(struct text_object *, char *, unsigned int);
|
void print_audacious_channels(struct text_object *, char *, unsigned int);
|
||||||
void print_audacious_filename(struct text_object *, char *, unsigned int);
|
void print_audacious_filename(struct text_object *, char *, unsigned int);
|
||||||
void print_audacious_playlist_length(struct text_object *, char *, unsigned int);
|
void print_audacious_playlist_length(struct text_object *, char *,
|
||||||
void print_audacious_playlist_position(struct text_object *, char *, unsigned int);
|
unsigned int);
|
||||||
|
void print_audacious_playlist_position(struct text_object *, char *,
|
||||||
|
unsigned int);
|
||||||
void print_audacious_main_volume(struct text_object *, char *, unsigned int);
|
void print_audacious_main_volume(struct text_object *, char *, unsigned int);
|
||||||
double audacious_barval(struct text_object *);
|
double audacious_barval(struct text_object *);
|
||||||
|
|
||||||
|
@@ -61,7 +61,8 @@ static int apm_getinfo(int fd, apm_info_t aip) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_apm_adapter(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_apm_adapter(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int fd;
|
int fd;
|
||||||
const char *out;
|
const char *out;
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
@@ -109,7 +110,8 @@ void print_apm_adapter(struct text_object *obj, char *p, unsigned int p_max_size
|
|||||||
snprintf(p, p_max_size, "%s", out);
|
snprintf(p, p_max_size, "%s", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_apm_battery_life(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_apm_battery_life(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int fd;
|
int fd;
|
||||||
u_int batt_life;
|
u_int batt_life;
|
||||||
const char *out;
|
const char *out;
|
||||||
@@ -150,7 +152,8 @@ void print_apm_battery_life(struct text_object *obj, char *p, unsigned int p_max
|
|||||||
snprintf(p, p_max_size, "%s", out);
|
snprintf(p, p_max_size, "%s", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_apm_battery_time(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_apm_battery_time(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int fd;
|
int fd;
|
||||||
int batt_time;
|
int batt_time;
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
|
@@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
#include "c++wrap.hh"
|
#include "c++wrap.hh"
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
/* force use of POSIX strerror_r instead of non-portable GNU specific */
|
/* force use of POSIX strerror_r instead of non-portable GNU specific */
|
||||||
#ifdef _GNU_SOURCE
|
#ifdef _GNU_SOURCE
|
||||||
@@ -42,9 +42,7 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int pipe2_emulate(int pipefd[2], int flags) {
|
int pipe2_emulate(int pipefd[2], int flags) {
|
||||||
if (pipe(pipefd) == -1) {
|
if (pipe(pipefd) == -1) { return -1; }
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & O_CLOEXEC) != 0) {
|
if ((flags & O_CLOEXEC) != 0) {
|
||||||
// we emulate O_CLOEXEC if the system does not have it
|
// we emulate O_CLOEXEC if the system does not have it
|
||||||
@@ -52,13 +50,9 @@ int pipe2_emulate(int pipefd[2], int flags) {
|
|||||||
|
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
int r = fcntl(pipefd[i], F_GETFD);
|
int r = fcntl(pipefd[i], F_GETFD);
|
||||||
if (r == -1) {
|
if (r == -1) { return -1; }
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) {
|
if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) { return -1; }
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +75,6 @@ std::string strerror_r(int errnum) {
|
|||||||
|
|
||||||
std::pair<int, int> pipe2(int flags) {
|
std::pair<int, int> pipe2(int flags) {
|
||||||
int fd[2];
|
int fd[2];
|
||||||
if (pipe2_ptr(fd, flags) == -1) {
|
if (pipe2_ptr(fd, flags) == -1) { throw errno_error("pipe2"); }
|
||||||
throw errno_error("pipe2");
|
|
||||||
}
|
|
||||||
{ return std::pair<int, int>(fd[0], fd[1]); }
|
{ return std::pair<int, int>(fd[0], fd[1]); }
|
||||||
}
|
}
|
||||||
|
@@ -179,7 +179,8 @@ double cmus_progress(struct text_object *obj) {
|
|||||||
return (double)cmus.progress;
|
return (double)cmus.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_cmus_totaltime(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_cmus_totaltime(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
uint32_t period = std::max(
|
uint32_t period = std::max(
|
||||||
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
||||||
@@ -188,7 +189,8 @@ void print_cmus_totaltime(struct text_object *obj, char *p, unsigned int p_max_s
|
|||||||
format_seconds_short(p, p_max_size, atol(cmus.totaltime.c_str()));
|
format_seconds_short(p, p_max_size, atol(cmus.totaltime.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_cmus_timeleft(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_cmus_timeleft(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
uint32_t period = std::max(
|
uint32_t period = std::max(
|
||||||
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
||||||
@@ -198,7 +200,8 @@ void print_cmus_timeleft(struct text_object *obj, char *p, unsigned int p_max_si
|
|||||||
format_seconds_short(p, p_max_size, (long)cmus.timeleft);
|
format_seconds_short(p, p_max_size, (long)cmus.timeleft);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_cmus_curtime(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_cmus_curtime(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
uint32_t period = std::max(
|
uint32_t period = std::max(
|
||||||
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
|
||||||
|
@@ -63,9 +63,7 @@ static void set_up_gradient() {
|
|||||||
greenmask |= 1 << i;
|
greenmask |= 1 << i;
|
||||||
bluemask |= 1 << i;
|
bluemask |= 1 << i;
|
||||||
}
|
}
|
||||||
if (colour_depth % 3 == 1) {
|
if (colour_depth % 3 == 1) { greenmask |= 1 << (colour_depth / 3); }
|
||||||
greenmask |= 1 << (colour_depth / 3);
|
|
||||||
}
|
|
||||||
redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
|
redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
|
||||||
greenmask = greenmask << (colour_depth / 3);
|
greenmask = greenmask << (colour_depth / 3);
|
||||||
}
|
}
|
||||||
@@ -74,9 +72,7 @@ static void set_up_gradient() {
|
|||||||
unsigned int adjust_colours(unsigned int colour) {
|
unsigned int adjust_colours(unsigned int colour) {
|
||||||
double r, g, b;
|
double r, g, b;
|
||||||
|
|
||||||
if (colour_depth == 0) {
|
if (colour_depth == 0) { set_up_gradient(); }
|
||||||
set_up_gradient();
|
|
||||||
}
|
|
||||||
if (colour_depth == 16) {
|
if (colour_depth == 16) {
|
||||||
r = (colour & 0xff0000) >> 16;
|
r = (colour & 0xff0000) >> 16;
|
||||||
g = (colour & 0xff00) >> 8;
|
g = (colour & 0xff00) >> 8;
|
||||||
@@ -100,9 +96,7 @@ unsigned long *do_gradient(int width, unsigned long first_colour,
|
|||||||
static_cast<unsigned long *>(malloc(width * sizeof(unsigned long)));
|
static_cast<unsigned long *>(malloc(width * sizeof(unsigned long)));
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (colour_depth == 0) {
|
if (colour_depth == 0) { set_up_gradient(); }
|
||||||
set_up_gradient();
|
|
||||||
}
|
|
||||||
red1 = (first_colour & redmask) >> redshift;
|
red1 = (first_colour & redmask) >> redshift;
|
||||||
green1 = (first_colour & greenmask) >> greenshift;
|
green1 = (first_colour & greenmask) >> greenshift;
|
||||||
blue1 = first_colour & bluemask;
|
blue1 = first_colour & bluemask;
|
||||||
@@ -139,24 +133,12 @@ unsigned long *do_gradient(int width, unsigned long first_colour,
|
|||||||
red3 += red1;
|
red3 += red1;
|
||||||
green3 += green1;
|
green3 += green1;
|
||||||
blue3 += blue1;
|
blue3 += blue1;
|
||||||
if (red3 < 0) {
|
if (red3 < 0) { red3 = 0; }
|
||||||
red3 = 0;
|
if (green3 < 0) { green3 = 0; }
|
||||||
}
|
if (blue3 < 0) { blue3 = 0; }
|
||||||
if (green3 < 0) {
|
if (red3 > bluemask) { red3 = bluemask; }
|
||||||
green3 = 0;
|
if (green3 > bluemask) { green3 = bluemask; }
|
||||||
}
|
if (blue3 > bluemask) { blue3 = bluemask; }
|
||||||
if (blue3 < 0) {
|
|
||||||
blue3 = 0;
|
|
||||||
}
|
|
||||||
if (red3 > bluemask) {
|
|
||||||
red3 = bluemask;
|
|
||||||
}
|
|
||||||
if (green3 > bluemask) {
|
|
||||||
green3 = bluemask;
|
|
||||||
}
|
|
||||||
if (blue3 > bluemask) {
|
|
||||||
blue3 = bluemask;
|
|
||||||
}
|
|
||||||
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
|
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
|
||||||
}
|
}
|
||||||
return colours;
|
return colours;
|
||||||
|
@@ -54,7 +54,8 @@ int get_entropy_poolsize(const unsigned int *);
|
|||||||
|
|
||||||
/* System Integrity Protection */
|
/* System Integrity Protection */
|
||||||
int get_sip_status(void);
|
int get_sip_status(void);
|
||||||
void print_sip_status(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_sip_status(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
|
|
||||||
void deallocate_cpu_sample(struct text_object *obj);
|
void deallocate_cpu_sample(struct text_object *obj);
|
||||||
|
|
||||||
|
@@ -62,9 +62,7 @@ struct diskio_stat *prepare_diskio_stat(const char *s) {
|
|||||||
char *rpbuf;
|
char *rpbuf;
|
||||||
char rpbuf2[256];
|
char rpbuf2[256];
|
||||||
|
|
||||||
if (s == nullptr) {
|
if (s == nullptr) { return &stats; }
|
||||||
return &stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strncmp(s, "label:", 6) == 0) {
|
if (strncmp(s, "label:", 6) == 0) {
|
||||||
snprintf(&(device_name[0]), text_buffer_size.get(*state),
|
snprintf(&(device_name[0]), text_buffer_size.get(*state),
|
||||||
@@ -115,9 +113,7 @@ struct diskio_stat *prepare_diskio_stat(const char *s) {
|
|||||||
/* lookup existing */
|
/* lookup existing */
|
||||||
while (cur->next != nullptr) {
|
while (cur->next != nullptr) {
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
if (strcmp(cur->dev, &(device_name[0])) == 0) {
|
if (strcmp(cur->dev, &(device_name[0])) == 0) { return cur; }
|
||||||
return cur;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no existing found, make a new one */
|
/* no existing found, make a new one */
|
||||||
@@ -145,9 +141,7 @@ static void print_diskio_dir(struct text_object *obj, int dir, char *p,
|
|||||||
auto *diskio = static_cast<struct diskio_stat *>(obj->data.opaque);
|
auto *diskio = static_cast<struct diskio_stat *>(obj->data.opaque);
|
||||||
double val;
|
double val;
|
||||||
|
|
||||||
if (diskio == nullptr) {
|
if (diskio == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dir < 0) {
|
if (dir < 0) {
|
||||||
val = diskio->current_read;
|
val = diskio->current_read;
|
||||||
@@ -166,11 +160,13 @@ void print_diskio(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
print_diskio_dir(obj, 0, p, p_max_size);
|
print_diskio_dir(obj, 0, p, p_max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_diskio_read(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_diskio_read(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
print_diskio_dir(obj, -1, p, p_max_size);
|
print_diskio_dir(obj, -1, p, p_max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_diskio_write(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_diskio_write(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
print_diskio_dir(obj, 1, p, p_max_size);
|
print_diskio_dir(obj, 1, p, p_max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -347,7 +347,8 @@ int update_cpu_usage(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_cpu(struct text_object *) { /* no-op */ }
|
void free_cpu(struct text_object *) { /* no-op */
|
||||||
|
}
|
||||||
|
|
||||||
int update_load_average(void) {
|
int update_load_average(void) {
|
||||||
double v[3];
|
double v[3];
|
||||||
|
@@ -27,11 +27,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <time.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
#include <inttypes.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
/* check for OS and include appropriate headers */
|
/* check for OS and include appropriate headers */
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
@@ -64,7 +64,8 @@ int update_entropy() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_entropy_avail(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_entropy_avail(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
snprintf(p, p_max_size, "%u", entropy.avail);
|
snprintf(p, p_max_size, "%u", entropy.avail);
|
||||||
}
|
}
|
||||||
@@ -75,7 +76,8 @@ uint8_t entropy_percentage(struct text_object *obj) {
|
|||||||
static_cast<double>(entropy.poolsize));
|
static_cast<double>(entropy.poolsize));
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_entropy_poolsize(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_entropy_poolsize(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
snprintf(p, p_max_size, "%u", entropy.poolsize);
|
snprintf(p, p_max_size, "%u", entropy.poolsize);
|
||||||
}
|
}
|
||||||
@@ -88,18 +90,16 @@ double entropy_barval(struct text_object *obj) {
|
|||||||
|
|
||||||
void print_password(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_password(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||||
time_t t;
|
time_t t;
|
||||||
static const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_";
|
static const char letters[] =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*("
|
||||||
|
")_";
|
||||||
static const int len = (int)sizeof(letters) - 1;
|
static const int len = (int)sizeof(letters) - 1;
|
||||||
uintmax_t x = strtoumax(obj->data.s, (char **)NULL, 10);
|
uintmax_t x = strtoumax(obj->data.s, (char **)NULL, 10);
|
||||||
uintmax_t z = 0;
|
uintmax_t z = 0;
|
||||||
|
|
||||||
if (-1 == (t = time(NULL))) {
|
if (-1 == (t = time(NULL))) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
srandom((unsigned int)t);
|
srandom((unsigned int)t);
|
||||||
|
|
||||||
for (; z < x && p_max_size-1 > z; z++) {
|
for (; z < x && p_max_size - 1 > z; z++) { *p++ = letters[random() % len]; }
|
||||||
*p++ = letters[random() % len];
|
|
||||||
}
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "exec.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@@ -36,7 +37,6 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "exec.h"
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "specials.h"
|
#include "specials.h"
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
@@ -68,7 +68,7 @@ static char *remove_excess_quotes(const char *command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; *command_ptr; command_ptr++) {
|
for (; *command_ptr; command_ptr++) {
|
||||||
if ('\0' == *(command_ptr+1) && 1 == skip &&
|
if ('\0' == *(command_ptr + 1) && 1 == skip &&
|
||||||
(*command_ptr == '"' || *command_ptr == '\'')) {
|
(*command_ptr == '"' || *command_ptr == '\'')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,8 @@ static FILE *pid_popen(const char *command, const char *mode, pid_t *child) {
|
|||||||
if (fcntl(childend, F_DUPFD, 0) == -1) { perror("fcntl()"); }
|
if (fcntl(childend, F_DUPFD, 0) == -1) { perror("fcntl()"); }
|
||||||
close(childend);
|
close(childend);
|
||||||
|
|
||||||
execl("/bin/sh", "sh", "-c", remove_excess_quotes(command), (char *)nullptr);
|
execl("/bin/sh", "sh", "-c", remove_excess_quotes(command),
|
||||||
|
(char *)nullptr);
|
||||||
_exit(EXIT_FAILURE); // child should die here, (normally execl will take
|
_exit(EXIT_FAILURE); // child should die here, (normally execl will take
|
||||||
// care of this but it can fail)
|
// care of this but it can fail)
|
||||||
}
|
}
|
||||||
|
22
src/i8k.cc
22
src/i8k.cc
@@ -56,13 +56,11 @@ static char *i8k_procbuf = nullptr;
|
|||||||
int update_i8k(void) {
|
int update_i8k(void) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (!i8k_procbuf) {
|
if (!i8k_procbuf) { i8k_procbuf = (char *)malloc(128 * sizeof(char)); }
|
||||||
i8k_procbuf = (char *)malloc(128 * sizeof(char));
|
|
||||||
}
|
|
||||||
if ((fp = fopen(PROC_I8K, "r")) == nullptr) {
|
if ((fp = fopen(PROC_I8K, "r")) == nullptr) {
|
||||||
free_and_zero(i8k_procbuf);
|
free_and_zero(i8k_procbuf);
|
||||||
/*THREAD_CRIT_ERR(nullptr, NULL, "/proc/i8k doesn't exist! use insmod to make
|
/*THREAD_CRIT_ERR(nullptr, NULL, "/proc/i8k doesn't exist! use insmod to
|
||||||
sure the kernel " "driver is loaded...");*/
|
make sure the kernel " "driver is loaded...");*/
|
||||||
NORM_ERR(
|
NORM_ERR(
|
||||||
"/proc/i8k doesn't exist! use insmod to make sure the kernel driver is "
|
"/proc/i8k doesn't exist! use insmod to make sure the kernel driver is "
|
||||||
"loaded...");
|
"loaded...");
|
||||||
@@ -107,7 +105,8 @@ void print_i8k_left_fan_status(struct text_object *obj, char *p,
|
|||||||
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
|
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_i8k_cpu_temp(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_i8k_cpu_temp(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int cpu_temp;
|
int cpu_temp;
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
@@ -122,7 +121,8 @@ void print_i8k_right_fan_status(struct text_object *obj, char *p,
|
|||||||
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
|
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_i8k_ac_status(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_i8k_ac_status(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int ac_status;
|
int ac_status;
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
@@ -131,12 +131,8 @@ void print_i8k_ac_status(struct text_object *obj, char *p, unsigned int p_max_si
|
|||||||
if (ac_status == -1) {
|
if (ac_status == -1) {
|
||||||
snprintf(p, p_max_size, "%s", "disabled (read i8k docs)");
|
snprintf(p, p_max_size, "%s", "disabled (read i8k docs)");
|
||||||
}
|
}
|
||||||
if (ac_status == 0) {
|
if (ac_status == 0) { snprintf(p, p_max_size, "%s", "off"); }
|
||||||
snprintf(p, p_max_size, "%s", "off");
|
if (ac_status == 1) { snprintf(p, p_max_size, "%s", "on"); }
|
||||||
}
|
|
||||||
if (ac_status == 1) {
|
|
||||||
snprintf(p, p_max_size, "%s", "on");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define I8K_PRINT_GENERATOR(name) \
|
#define I8K_PRINT_GENERATOR(name) \
|
||||||
|
67
src/ibm.cc
67
src/ibm.cc
@@ -72,16 +72,15 @@ speed: 2944
|
|||||||
commands: enable, disable
|
commands: enable, disable
|
||||||
* Peter Tarjan (ptarjan@citromail.hu) */
|
* Peter Tarjan (ptarjan@citromail.hu) */
|
||||||
|
|
||||||
void get_ibm_acpi_fan(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void get_ibm_acpi_fan(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
unsigned int speed = 0;
|
unsigned int speed = 0;
|
||||||
char fan[128];
|
char fan[128];
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
if (!p || p_max_size <= 0) {
|
if (!p || p_max_size <= 0) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
|
snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
|
||||||
|
|
||||||
@@ -90,12 +89,8 @@ void get_ibm_acpi_fan(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
char line[256];
|
char line[256];
|
||||||
|
|
||||||
if (fgets(line, 255, fp) == nullptr) {
|
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||||
break;
|
if (sscanf(line, "speed: %u", &speed)) { break; }
|
||||||
}
|
|
||||||
if (sscanf(line, "speed: %u", &speed)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(nullptr, NULL,
|
CRIT_ERR(nullptr, NULL,
|
||||||
@@ -140,9 +135,7 @@ int get_ibm_acpi_temps(void) {
|
|||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
char line[256];
|
char line[256];
|
||||||
|
|
||||||
if (fgets(line, 255, fp) == nullptr) {
|
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
|
if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
|
||||||
&ibm_acpi_temps[0], &ibm_acpi_temps[1], &ibm_acpi_temps[2],
|
&ibm_acpi_temps[0], &ibm_acpi_temps[1], &ibm_acpi_temps[2],
|
||||||
&ibm_acpi_temps[3], &ibm_acpi_temps[4], &ibm_acpi_temps[5],
|
&ibm_acpi_temps[3], &ibm_acpi_temps[4], &ibm_acpi_temps[5],
|
||||||
@@ -171,7 +164,8 @@ commands: up, down, mute
|
|||||||
commands: level <level> (<level> is 0-15)
|
commands: level <level> (<level> is 0-15)
|
||||||
* Peter Tarjan (ptarjan@citromail.hu) */
|
* Peter Tarjan (ptarjan@citromail.hu) */
|
||||||
|
|
||||||
void get_ibm_acpi_volume(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void get_ibm_acpi_volume(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char volume[128];
|
char volume[128];
|
||||||
unsigned int vol = -1;
|
unsigned int vol = -1;
|
||||||
@@ -179,9 +173,7 @@ void get_ibm_acpi_volume(struct text_object *obj, char *p, unsigned int p_max_si
|
|||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
if (!p || p_max_size <= 0) {
|
if (!p || p_max_size <= 0) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
|
snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
|
||||||
|
|
||||||
@@ -191,16 +183,12 @@ void get_ibm_acpi_volume(struct text_object *obj, char *p, unsigned int p_max_si
|
|||||||
char line[256];
|
char line[256];
|
||||||
unsigned int read_vol = -1;
|
unsigned int read_vol = -1;
|
||||||
|
|
||||||
if (fgets(line, 255, fp) == nullptr) {
|
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (sscanf(line, "level: %u", &read_vol)) {
|
if (sscanf(line, "level: %u", &read_vol)) {
|
||||||
vol = read_vol;
|
vol = read_vol;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sscanf(line, "mute: %s", mute)) {
|
if (sscanf(line, "mute: %s", mute)) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(nullptr, NULL,
|
CRIT_ERR(nullptr, NULL,
|
||||||
@@ -226,16 +214,15 @@ commands: up, down
|
|||||||
commands: level <level> (<level> is 0-7)
|
commands: level <level> (<level> is 0-7)
|
||||||
* Peter Tarjan (ptarjan@citromail.hu) */
|
* Peter Tarjan (ptarjan@citromail.hu) */
|
||||||
|
|
||||||
void get_ibm_acpi_brightness(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void get_ibm_acpi_brightness(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
unsigned int brightness = 0;
|
unsigned int brightness = 0;
|
||||||
char filename[128];
|
char filename[128];
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
if (!p || p_max_size <= 0) {
|
if (!p || p_max_size <= 0) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
|
snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
|
||||||
|
|
||||||
@@ -244,12 +231,8 @@ void get_ibm_acpi_brightness(struct text_object *obj, char *p, unsigned int p_ma
|
|||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
char line[256];
|
char line[256];
|
||||||
|
|
||||||
if (fgets(line, 255, fp) == nullptr) {
|
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||||
break;
|
if (sscanf(line, "level: %u", &brightness)) { break; }
|
||||||
}
|
|
||||||
if (sscanf(line, "level: %u", &brightness)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(nullptr, NULL,
|
CRIT_ERR(nullptr, NULL,
|
||||||
@@ -271,16 +254,15 @@ commands: on, off
|
|||||||
* get "unknown" for a few models that do not make the status available.
|
* get "unknown" for a few models that do not make the status available.
|
||||||
* Lluis Esquerda (eskerda@gmail.com) */
|
* Lluis Esquerda (eskerda@gmail.com) */
|
||||||
|
|
||||||
void get_ibm_acpi_thinklight(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void get_ibm_acpi_thinklight(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char thinklight[8];
|
char thinklight[8];
|
||||||
char filename[128];
|
char filename[128];
|
||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
if (!p || p_max_size <= 0) {
|
if (!p || p_max_size <= 0) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(filename, 127, "%s/light", IBM_ACPI_DIR);
|
snprintf(filename, 127, "%s/light", IBM_ACPI_DIR);
|
||||||
|
|
||||||
@@ -289,12 +271,8 @@ void get_ibm_acpi_thinklight(struct text_object *obj, char *p, unsigned int p_ma
|
|||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
char line[256];
|
char line[256];
|
||||||
|
|
||||||
if (fgets(line, 255, fp) == nullptr) {
|
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||||
break;
|
if (sscanf(line, "status: %s", thinklight)) { break; }
|
||||||
}
|
|
||||||
if (sscanf(line, "status: %s", thinklight)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(nullptr, NULL,
|
CRIT_ERR(nullptr, NULL,
|
||||||
@@ -317,6 +295,7 @@ void parse_ibm_temps_arg(struct text_object *obj, const char *arg) {
|
|||||||
obj->data.l = atoi(arg);
|
obj->data.l = atoi(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_ibm_temps(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_ibm_temps(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS, 1);
|
temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS, 1);
|
||||||
}
|
}
|
||||||
|
@@ -44,13 +44,9 @@ static iconv_t **iconv_cd = 0;
|
|||||||
|
|
||||||
int register_iconv(iconv_t *new_iconv) {
|
int register_iconv(iconv_t *new_iconv) {
|
||||||
iconv_cd = (void ***)realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
|
iconv_cd = (void ***)realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
|
||||||
if (!iconv_cd) {
|
if (!iconv_cd) { CRIT_ERR(nullptr, NULL, "Out of memory"); }
|
||||||
CRIT_ERR(nullptr, NULL, "Out of memory");
|
|
||||||
}
|
|
||||||
iconv_cd[iconv_count] = (void **)malloc(sizeof(iconv_t));
|
iconv_cd[iconv_count] = (void **)malloc(sizeof(iconv_t));
|
||||||
if (!iconv_cd[iconv_count]) {
|
if (!iconv_cd[iconv_count]) { CRIT_ERR(nullptr, NULL, "Out of memory"); }
|
||||||
CRIT_ERR(nullptr, NULL, "Out of memory");
|
|
||||||
}
|
|
||||||
memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
|
memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
|
||||||
iconv_count++;
|
iconv_count++;
|
||||||
return iconv_count;
|
return iconv_count;
|
||||||
@@ -135,7 +131,8 @@ void init_iconv_start(struct text_object *obj, void *free_at_crash,
|
|||||||
|
|
||||||
void init_iconv_stop(void) { iconv_converting = 0; }
|
void init_iconv_stop(void) { iconv_converting = 0; }
|
||||||
|
|
||||||
void print_iconv_start(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_iconv_start(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)p;
|
(void)p;
|
||||||
(void)p_max_size;
|
(void)p_max_size;
|
||||||
|
|
||||||
@@ -143,7 +140,8 @@ void print_iconv_start(struct text_object *obj, char *p, unsigned int p_max_size
|
|||||||
iconv_selected = obj->data.i;
|
iconv_selected = obj->data.i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_iconv_stop(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_iconv_stop(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
(void)p;
|
(void)p;
|
||||||
(void)p_max_size;
|
(void)p_max_size;
|
||||||
|
@@ -62,8 +62,7 @@ conky::range_config_setting<unsigned int> imlib_cache_flush_interval(
|
|||||||
|
|
||||||
unsigned int cimlib_cache_flush_last = 0;
|
unsigned int cimlib_cache_flush_last = 0;
|
||||||
|
|
||||||
conky::simple_config_setting<bool> draw_blended(
|
conky::simple_config_setting<bool> draw_blended("draw_blended", true, true);
|
||||||
"draw_blended", true, true);
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) {
|
void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) {
|
||||||
@@ -123,7 +122,7 @@ void cimlib_add_image(const char *args) {
|
|||||||
"Invalid args for $image. Format is: '<path to image> (-p"
|
"Invalid args for $image. Format is: '<path to image> (-p"
|
||||||
"x,y) (-s WxH) (-n) (-f interval)' (got '%s')",
|
"x,y) (-s WxH) (-n) (-f interval)' (got '%s')",
|
||||||
args);
|
args);
|
||||||
delete [] cur;
|
delete[] cur;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
strncpy(cur->name, to_real_path(cur->name).c_str(), 1024);
|
strncpy(cur->name, to_real_path(cur->name).c_str(), 1024);
|
||||||
@@ -138,22 +137,16 @@ void cimlib_add_image(const char *args) {
|
|||||||
tmp = strstr(args, "-s ");
|
tmp = strstr(args, "-s ");
|
||||||
if (tmp != nullptr) {
|
if (tmp != nullptr) {
|
||||||
tmp += 3;
|
tmp += 3;
|
||||||
if (sscanf(tmp, "%ix%i", &cur->w, &cur->h) != 0) {
|
if (sscanf(tmp, "%ix%i", &cur->w, &cur->h) != 0) { cur->wh_set = 1; }
|
||||||
cur->wh_set = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = strstr(args, "-n");
|
tmp = strstr(args, "-n");
|
||||||
if (tmp != nullptr) {
|
if (tmp != nullptr) { cur->no_cache = 1; }
|
||||||
cur->no_cache = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = strstr(args, "-f ");
|
tmp = strstr(args, "-f ");
|
||||||
if (tmp != nullptr) {
|
if (tmp != nullptr) {
|
||||||
tmp += 3;
|
tmp += 3;
|
||||||
if (sscanf(tmp, "%d", &cur->flush_interval) != 0) {
|
if (sscanf(tmp, "%d", &cur->flush_interval) != 0) { cur->no_cache = 0; }
|
||||||
cur->no_cache = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cur->flush_interval < 0) {
|
if (cur->flush_interval < 0) {
|
||||||
NORM_ERR("Imlib2: flush interval should be >= 0");
|
NORM_ERR("Imlib2: flush interval should be >= 0");
|
||||||
@@ -180,9 +173,7 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x,
|
|||||||
|
|
||||||
image = imlib_load_image(cur->name);
|
image = imlib_load_image(cur->name);
|
||||||
if (image == nullptr) {
|
if (image == nullptr) {
|
||||||
if (rep == 0) {
|
if (rep == 0) { NORM_ERR("Unable to load image '%s'", cur->name); }
|
||||||
NORM_ERR("Unable to load image '%s'", cur->name);
|
|
||||||
}
|
|
||||||
rep = 1;
|
rep = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -213,18 +204,10 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x,
|
|||||||
} else {
|
} else {
|
||||||
imlib_free_image();
|
imlib_free_image();
|
||||||
}
|
}
|
||||||
if (cur->x < *clip_x) {
|
if (cur->x < *clip_x) { *clip_x = cur->x; }
|
||||||
*clip_x = cur->x;
|
if (cur->y < *clip_y) { *clip_y = cur->y; }
|
||||||
}
|
if (cur->x + cur->w > *clip_x2) { *clip_x2 = cur->x + cur->w; }
|
||||||
if (cur->y < *clip_y) {
|
if (cur->y + cur->h > *clip_y2) { *clip_y2 = cur->y + cur->h; }
|
||||||
*clip_y = cur->y;
|
|
||||||
}
|
|
||||||
if (cur->x + cur->w > *clip_x2) {
|
|
||||||
*clip_x2 = cur->x + cur->w;
|
|
||||||
}
|
|
||||||
if (cur->y + cur->h > *clip_y2) {
|
|
||||||
*clip_y2 = cur->y + cur->h;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cimlib_draw_all(int *clip_x, int *clip_y, int *clip_x2,
|
static void cimlib_draw_all(int *clip_x, int *clip_y, int *clip_x2,
|
||||||
@@ -280,12 +263,8 @@ void cimlib_render(int x, int y, int width, int height) {
|
|||||||
imlib_context_set_image(buffer);
|
imlib_context_set_image(buffer);
|
||||||
|
|
||||||
/* setup our clip rect */
|
/* setup our clip rect */
|
||||||
if (clip_x == INT_MAX) {
|
if (clip_x == INT_MAX) { clip_x = 0; }
|
||||||
clip_x = 0;
|
if (clip_y == INT_MAX) { clip_y = 0; }
|
||||||
}
|
|
||||||
if (clip_y == INT_MAX) {
|
|
||||||
clip_y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* render the image at 0, 0 */
|
/* render the image at 0, 0 */
|
||||||
imlib_render_image_part_on_drawable_at_size(
|
imlib_render_image_part_on_drawable_at_size(
|
||||||
@@ -295,7 +274,6 @@ void cimlib_render(int x, int y, int width, int height) {
|
|||||||
imlib_free_image();
|
imlib_free_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_image_callback(struct text_object *obj, char *,
|
void print_image_callback(struct text_object *obj, char *, unsigned int) {
|
||||||
unsigned int) {
|
|
||||||
cimlib_add_image(obj->data.s);
|
cimlib_add_image(obj->data.s);
|
||||||
}
|
}
|
||||||
|
@@ -114,7 +114,8 @@ struct _tcp_port_monitor_t {
|
|||||||
|
|
||||||
_tcp_port_monitor_t(int max_connections)
|
_tcp_port_monitor_t(int max_connections)
|
||||||
: hash(),
|
: hash(),
|
||||||
p_peek(max_connections, static_cast<const tcp_connection_t *>(nullptr)) {}
|
p_peek(max_connections,
|
||||||
|
static_cast<const tcp_connection_t *>(nullptr)) {}
|
||||||
|
|
||||||
_tcp_port_monitor_t(const _tcp_port_monitor_t &other)
|
_tcp_port_monitor_t(const _tcp_port_monitor_t &other)
|
||||||
: hash(other.hash),
|
: hash(other.hash),
|
||||||
@@ -202,9 +203,7 @@ void show_connection_to_tcp_port_monitor(monitor_hash_t::value_type &monitor,
|
|||||||
|
|
||||||
tcp_connection_t *p_connection;
|
tcp_connection_t *p_connection;
|
||||||
|
|
||||||
if (!p_void) {
|
if (!p_void) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This p_connection is on caller's stack and not the heap.
|
/* This p_connection is on caller's stack and not the heap.
|
||||||
* If we are interested, we will create a copy of the connection
|
* If we are interested, we will create a copy of the connection
|
||||||
@@ -242,9 +241,7 @@ void show_connection_to_tcp_port_monitor(monitor_hash_t::value_type &monitor,
|
|||||||
void for_each_tcp_port_monitor_in_collection(
|
void for_each_tcp_port_monitor_in_collection(
|
||||||
tcp_port_monitor_collection_t *p_collection,
|
tcp_port_monitor_collection_t *p_collection,
|
||||||
tcp_port_monitor_function_ptr_t p_function, void *p_function_args) {
|
tcp_port_monitor_function_ptr_t p_function, void *p_function_args) {
|
||||||
if (!p_collection || !p_function) {
|
if (!p_collection || !p_function) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* for each monitor in the collection */
|
/* for each monitor in the collection */
|
||||||
for (monitor_hash_t::iterator i = p_collection->hash.begin();
|
for (monitor_hash_t::iterator i = p_collection->hash.begin();
|
||||||
@@ -318,9 +315,7 @@ void process_file(tcp_port_monitor_collection_t *p_collection,
|
|||||||
tcp_connection_t conn;
|
tcp_connection_t conn;
|
||||||
unsigned long inode, uid, state;
|
unsigned long inode, uid, state;
|
||||||
|
|
||||||
if ((fp = std::fopen(file, "r")) == nullptr) {
|
if ((fp = std::fopen(file, "r")) == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ignore field name line */
|
/* ignore field name line */
|
||||||
if (std::fgets(buf, 255, fp) == nullptr) {
|
if (std::fgets(buf, 255, fp) == nullptr) {
|
||||||
@@ -340,9 +335,7 @@ void process_file(tcp_port_monitor_collection_t *p_collection,
|
|||||||
}
|
}
|
||||||
/** TCP_ESTABLISHED equals 1, but is not (always??) included **/
|
/** TCP_ESTABLISHED equals 1, but is not (always??) included **/
|
||||||
// if ((inode == 0) || (state != TCP_ESTABLISHED)) {
|
// if ((inode == 0) || (state != TCP_ESTABLISHED)) {
|
||||||
if ((inode == 0) || (state != 1)) {
|
if ((inode == 0) || (state != 1)) { continue; }
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string_to_addr(&conn.local_addr, local_addr);
|
string_to_addr(&conn.local_addr, local_addr);
|
||||||
string_to_addr(&conn.remote_addr, remote_addr);
|
string_to_addr(&conn.remote_addr, remote_addr);
|
||||||
@@ -375,9 +368,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
|||||||
size_t buffer_size) {
|
size_t buffer_size) {
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
|
|
||||||
if (!p_monitor || !p_buffer || connection_index < 0) {
|
if (!p_monitor || !p_buffer || connection_index < 0) { return -1; }
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::memset(p_buffer, 0, buffer_size);
|
std::memset(p_buffer, 0, buffer_size);
|
||||||
std::memset(&sa, 0, sizeof(sa));
|
std::memset(&sa, 0, sizeof(sa));
|
||||||
@@ -419,8 +410,8 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
|||||||
case REMOTESERVICE:
|
case REMOTESERVICE:
|
||||||
|
|
||||||
sa.sin_port = htons(p_monitor->p_peek[connection_index]->remote_port);
|
sa.sin_port = htons(p_monitor->p_peek[connection_index]->remote_port);
|
||||||
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr, 0,
|
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr,
|
||||||
p_buffer, buffer_size, NI_NUMERICHOST);
|
0, p_buffer, buffer_size, NI_NUMERICHOST);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOCALIP:
|
case LOCALIP:
|
||||||
@@ -444,8 +435,8 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
|||||||
case LOCALSERVICE:
|
case LOCALSERVICE:
|
||||||
|
|
||||||
sa.sin_port = htons(p_monitor->p_peek[connection_index]->local_port);
|
sa.sin_port = htons(p_monitor->p_peek[connection_index]->local_port);
|
||||||
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr, 0,
|
getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in), nullptr,
|
||||||
p_buffer, buffer_size, NI_NUMERICHOST);
|
0, p_buffer, buffer_size, NI_NUMERICHOST);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -474,9 +465,7 @@ void destroy_tcp_port_monitor_collection(
|
|||||||
/* Updates the tcp statistics for all monitors within a collection */
|
/* Updates the tcp statistics for all monitors within a collection */
|
||||||
void update_tcp_port_monitor_collection(
|
void update_tcp_port_monitor_collection(
|
||||||
tcp_port_monitor_collection_t *p_collection) {
|
tcp_port_monitor_collection_t *p_collection) {
|
||||||
if (!p_collection) {
|
if (!p_collection) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
process_file(p_collection, "/proc/net/tcp");
|
process_file(p_collection, "/proc/net/tcp");
|
||||||
process_file(p_collection, "/proc/net/tcp6");
|
process_file(p_collection, "/proc/net/tcp6");
|
||||||
@@ -495,9 +484,7 @@ void update_tcp_port_monitor_collection(
|
|||||||
int insert_new_tcp_port_monitor_into_collection(
|
int insert_new_tcp_port_monitor_into_collection(
|
||||||
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
|
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
|
||||||
in_port_t port_range_end, tcp_port_monitor_args_t *p_creation_args) {
|
in_port_t port_range_end, tcp_port_monitor_args_t *p_creation_args) {
|
||||||
if (!p_collection) {
|
if (!p_collection) { return -1; }
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
p_collection->hash.insert(monitor_hash_t::value_type(
|
p_collection->hash.insert(monitor_hash_t::value_type(
|
||||||
port_range_t(port_range_begin, port_range_end),
|
port_range_t(port_range_begin, port_range_end),
|
||||||
@@ -510,9 +497,7 @@ int insert_new_tcp_port_monitor_into_collection(
|
|||||||
tcp_port_monitor_t *find_tcp_port_monitor(
|
tcp_port_monitor_t *find_tcp_port_monitor(
|
||||||
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
|
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
|
||||||
in_port_t port_range_end) {
|
in_port_t port_range_end) {
|
||||||
if (!p_collection) {
|
if (!p_collection) { return nullptr; }
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* is monitor in hash? */
|
/* is monitor in hash? */
|
||||||
monitor_hash_t::iterator i =
|
monitor_hash_t::iterator i =
|
||||||
|
18
src/linux.cc
18
src/linux.cc
@@ -1126,8 +1126,7 @@ static int get_first_file_in_a_directory(const char *dir, char *s, int *rep) {
|
|||||||
/*
|
/*
|
||||||
* Convert @dev "0" (hwmon number) or "k10temp" (hwmon name) to "hwmon2/device"
|
* Convert @dev "0" (hwmon number) or "k10temp" (hwmon name) to "hwmon2/device"
|
||||||
*/
|
*/
|
||||||
static void get_dev_path(const char *dir, const char *dev, char *out_buf)
|
static void get_dev_path(const char *dir, const char *dev, char *out_buf) {
|
||||||
{
|
|
||||||
struct dirent **namelist;
|
struct dirent **namelist;
|
||||||
char path[256] = {'\0'};
|
char path[256] = {'\0'};
|
||||||
char name[256] = {'\0'};
|
char name[256] = {'\0'};
|
||||||
@@ -1151,18 +1150,15 @@ static void get_dev_path(const char *dir, const char *dev, char *out_buf)
|
|||||||
NORM_ERR("scandir for %s: %s", dir, strerror(errno));
|
NORM_ERR("scandir for %s: %s", dir, strerror(errno));
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
if (n == 0)
|
if (n == 0) goto not_found;
|
||||||
goto not_found;
|
|
||||||
|
|
||||||
/* Search each hwmon%s/name */
|
/* Search each hwmon%s/name */
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (found)
|
if (found) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
snprintf(path, 256, "%s%s/name", dir, namelist[i]->d_name);
|
snprintf(path, 256, "%s%s/name", dir, namelist[i]->d_name);
|
||||||
name_fd = open(path, O_RDONLY);
|
name_fd = open(path, O_RDONLY);
|
||||||
if (name_fd < 0)
|
if (name_fd < 0) continue;
|
||||||
continue;
|
|
||||||
size = read(name_fd, name, strlen(dev));
|
size = read(name_fd, name, strlen(dev));
|
||||||
if (size < strlen(dev)) {
|
if (size < strlen(dev)) {
|
||||||
close(name_fd);
|
close(name_fd);
|
||||||
@@ -1177,11 +1173,9 @@ static void get_dev_path(const char *dir, const char *dev, char *out_buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++) free(namelist[i]);
|
||||||
free(namelist[i]);
|
|
||||||
free(namelist);
|
free(namelist);
|
||||||
if (found)
|
if (found) return;
|
||||||
return;
|
|
||||||
|
|
||||||
not_found:
|
not_found:
|
||||||
out_buf[0] = '\0';
|
out_buf[0] = '\0';
|
||||||
|
54
src/luamm.cc
54
src/luamm.cc
@@ -53,9 +53,7 @@ int exception_to_string(lua_State *l) {
|
|||||||
assert(ptr);
|
assert(ptr);
|
||||||
try {
|
try {
|
||||||
std::rethrow_exception(*ptr);
|
std::rethrow_exception(*ptr);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) { lua_pushstring(l, e.what()); } catch (...) {
|
||||||
lua_pushstring(l, e.what());
|
|
||||||
} catch (...) {
|
|
||||||
lua_pushstring(l, typeid(*ptr).name());
|
lua_pushstring(l, typeid(*ptr).name());
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@@ -68,12 +66,9 @@ int absindex(lua_State *l, int index) {
|
|||||||
|
|
||||||
// Just like getfield(), only without calling metamethods (or throwing random
|
// Just like getfield(), only without calling metamethods (or throwing random
|
||||||
// exceptions)
|
// exceptions)
|
||||||
inline void rawgetfield(lua_State *l, int index,
|
inline void rawgetfield(lua_State *l, int index, const char *k) {
|
||||||
const char *k) {
|
|
||||||
index = absindex(l, index);
|
index = absindex(l, index);
|
||||||
if (lua_checkstack(l, 1) == 0) {
|
if (lua_checkstack(l, 1) == 0) { throw std::bad_alloc(); }
|
||||||
throw std::bad_alloc();
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pushstring(l, k);
|
lua_pushstring(l, k);
|
||||||
lua_rawget(l, index);
|
lua_rawget(l, index);
|
||||||
@@ -81,12 +76,9 @@ inline void rawgetfield(lua_State *l, int index,
|
|||||||
|
|
||||||
// Just like setfield(), only without calling metamethods (or throwing random
|
// Just like setfield(), only without calling metamethods (or throwing random
|
||||||
// exceptions)
|
// exceptions)
|
||||||
inline void rawsetfield(lua_State *l, int index,
|
inline void rawsetfield(lua_State *l, int index, const char *k) {
|
||||||
const char *k) {
|
|
||||||
index = absindex(l, index);
|
index = absindex(l, index);
|
||||||
if (lua_checkstack(l, 2) == 0) {
|
if (lua_checkstack(l, 2) == 0) { throw std::bad_alloc(); }
|
||||||
throw std::bad_alloc();
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pushstring(l, k);
|
lua_pushstring(l, k);
|
||||||
lua_insert(l, -2);
|
lua_insert(l, -2);
|
||||||
@@ -130,9 +122,7 @@ int closure_trampoline(lua_State *l) {
|
|||||||
* execute everything in protected mode).
|
* execute everything in protected mode).
|
||||||
*/
|
*/
|
||||||
int panic_throw(lua_State *l) {
|
int panic_throw(lua_State *l) {
|
||||||
if (lua_checkstack(l, 1) == 0) {
|
if (lua_checkstack(l, 1) == 0) { throw std::bad_alloc(); }
|
||||||
throw std::bad_alloc();
|
|
||||||
}
|
|
||||||
|
|
||||||
rawgetfield(l, REGISTRYINDEX, this_cpp_object);
|
rawgetfield(l, REGISTRYINDEX, this_cpp_object);
|
||||||
assert(lua_islightuserdata(l, -1));
|
assert(lua_islightuserdata(l, -1));
|
||||||
@@ -191,9 +181,7 @@ std::string exception::get_error_msg(state *L) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return L->tostring(-1);
|
return L->tostring(-1);
|
||||||
} catch (not_string_error &e) {
|
} catch (not_string_error &e) { return default_msg; }
|
||||||
return default_msg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exception::exception(state *l) : std::runtime_error(get_error_msg(l)), L(l) {
|
exception::exception(state *l) : std::runtime_error(get_error_msg(l)), L(l) {
|
||||||
@@ -206,9 +194,7 @@ exception::exception(state *l) : std::runtime_error(get_error_msg(l)), L(l) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exception::~exception() {
|
exception::~exception() {
|
||||||
if (L == nullptr) {
|
if (L == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
L->checkstack(1);
|
L->checkstack(1);
|
||||||
|
|
||||||
L->rawgetfield(REGISTRYINDEX, lua_exception_namespace);
|
L->rawgetfield(REGISTRYINDEX, lua_exception_namespace);
|
||||||
@@ -272,9 +258,7 @@ state::state() {
|
|||||||
|
|
||||||
void state::call(int nargs, int nresults, int errfunc) {
|
void state::call(int nargs, int nresults, int errfunc) {
|
||||||
int r = lua_pcall(cobj.get(), nargs, nresults, errfunc);
|
int r = lua_pcall(cobj.get(), nargs, nresults, errfunc);
|
||||||
if (r == 0) {
|
if (r == 0) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r == LUA_ERRMEM) {
|
if (r == LUA_ERRMEM) {
|
||||||
// memory allocation error, cross your fingers
|
// memory allocation error, cross your fingers
|
||||||
@@ -301,16 +285,12 @@ void state::call(int nargs, int nresults, int errfunc) {
|
|||||||
pop(2);
|
pop(2);
|
||||||
}
|
}
|
||||||
// it's a lua exception, wrap it
|
// it's a lua exception, wrap it
|
||||||
if (r == LUA_ERRERR) {
|
if (r == LUA_ERRERR) { throw lua::errfunc_error(this); }
|
||||||
throw lua::errfunc_error(this);
|
|
||||||
}
|
|
||||||
{ throw lua::exception(this); }
|
{ throw lua::exception(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void state::checkstack(int extra) {
|
void state::checkstack(int extra) {
|
||||||
if (lua_checkstack(cobj.get(), extra) == 0) {
|
if (lua_checkstack(cobj.get(), extra) == 0) { throw std::bad_alloc(); }
|
||||||
throw std::bad_alloc();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void state::concat(int n) {
|
void state::concat(int n) {
|
||||||
@@ -323,9 +303,7 @@ void state::concat(int n) {
|
|||||||
|
|
||||||
bool state::equal(int index1, int index2) {
|
bool state::equal(int index1, int index2) {
|
||||||
// avoid pcall overhead in trivial cases
|
// avoid pcall overhead in trivial cases
|
||||||
if (rawequal(index1, index2)) {
|
if (rawequal(index1, index2)) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return safe_compare(&safe_compare_trampoline<lua_equal>, index1, index2);
|
return safe_compare(&safe_compare_trampoline<lua_equal>, index1, index2);
|
||||||
}
|
}
|
||||||
@@ -438,9 +416,7 @@ void state::rawsetfield(int index, const char *k) {
|
|||||||
|
|
||||||
bool state::safe_compare(lua_CFunction trampoline, int index1, int index2) {
|
bool state::safe_compare(lua_CFunction trampoline, int index1, int index2) {
|
||||||
// if one of the indexes is invalid, return false
|
// if one of the indexes is invalid, return false
|
||||||
if (isnone(index1) || isnone(index2)) {
|
if (isnone(index1) || isnone(index2)) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert relative indexes into absolute
|
// convert relative indexes into absolute
|
||||||
index1 = absindex(index1);
|
index1 = absindex(index1);
|
||||||
@@ -491,9 +467,7 @@ void state::settable(int index) {
|
|||||||
std::string state::tostring(int index) {
|
std::string state::tostring(int index) {
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *str = lua_tolstring(cobj.get(), index, &len);
|
const char *str = lua_tolstring(cobj.get(), index, &len);
|
||||||
if (str == nullptr) {
|
if (str == nullptr) { throw not_string_error(); }
|
||||||
throw not_string_error();
|
|
||||||
}
|
|
||||||
return std::string(str, len);
|
return std::string(str, len);
|
||||||
}
|
}
|
||||||
} // namespace lua
|
} // namespace lua
|
||||||
|
12
src/luamm.hh
12
src/luamm.hh
@@ -152,8 +152,7 @@ class state : private std::mutex {
|
|||||||
// throwing exceptions in destructors is a bad idea
|
// throwing exceptions in destructors is a bad idea
|
||||||
// but we catch (and ignore) them, just in case
|
// but we catch (and ignore) them, just in case
|
||||||
ptr->~T();
|
ptr->~T();
|
||||||
} catch (...) {
|
} catch (...) {}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,9 +304,9 @@ class state : private std::mutex {
|
|||||||
void setfield(int index, const char *k);
|
void setfield(int index, const char *k);
|
||||||
void setglobal(const char *name);
|
void setglobal(const char *name);
|
||||||
void settable(int index);
|
void settable(int index);
|
||||||
// lua_tostring uses nullptr to indicate conversion error, since there is no such
|
// lua_tostring uses nullptr to indicate conversion error, since there is no
|
||||||
// thing as a nullptr std::string, we throw an exception. Returned value may
|
// such thing as a nullptr std::string, we throw an exception. Returned value
|
||||||
// contain '\0'
|
// may contain '\0'
|
||||||
std::string tostring(int index);
|
std::string tostring(int index);
|
||||||
// allocate a new lua userdata of appropriate size, and create a object in it
|
// allocate a new lua userdata of appropriate size, and create a object in it
|
||||||
// pushes the userdata on stack and returns the pointer
|
// pushes the userdata on stack and returns the pointer
|
||||||
@@ -343,8 +342,7 @@ class stack_sentry {
|
|||||||
const stack_sentry &operator=(const stack_sentry &) = delete;
|
const stack_sentry &operator=(const stack_sentry &) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit stack_sentry(state &l, int n_ = 0)
|
explicit stack_sentry(state &l, int n_ = 0) : L(&l), n(l.gettop() + n_) {
|
||||||
: L(&l), n(l.gettop() + n_) {
|
|
||||||
assert(n >= 0);
|
assert(n >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -181,8 +181,8 @@ static void print_version() {
|
|||||||
<< _(" * Own window\n")
|
<< _(" * Own window\n")
|
||||||
#endif
|
#endif
|
||||||
#endif /* BUILD_X11 */
|
#endif /* BUILD_X11 */
|
||||||
#if defined BUILD_AUDACIOUS || defined BUILD_CMUS || \
|
#if defined BUILD_AUDACIOUS || defined BUILD_CMUS || defined BUILD_MPD || \
|
||||||
defined BUILD_MPD || defined BUILD_MOC || defined BUILD_XMMS2
|
defined BUILD_MOC || defined BUILD_XMMS2
|
||||||
<< _("\n Music detection:\n")
|
<< _("\n Music detection:\n")
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUILD_AUDACIOUS
|
#ifdef BUILD_AUDACIOUS
|
||||||
|
@@ -86,9 +86,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
|||||||
} else {
|
} else {
|
||||||
print_num_mails = PRINT_MAILS;
|
print_num_mails = PRINT_MAILS;
|
||||||
}
|
}
|
||||||
if (print_num_mails < 1) {
|
if (print_num_mails < 1) { print_num_mails = 1; }
|
||||||
print_num_mails = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
substr = strstr(args, "-t");
|
substr = strstr(args, "-t");
|
||||||
if (substr != nullptr) {
|
if (substr != nullptr) {
|
||||||
@@ -131,9 +129,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
|||||||
|
|
||||||
while (tmp != nullptr) {
|
while (tmp != nullptr) {
|
||||||
tmp = strtok(nullptr, " ");
|
tmp = strtok(nullptr, " ");
|
||||||
if (tmp != nullptr) {
|
if (tmp != nullptr) { start = tmp; }
|
||||||
start = tmp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
strncpy(mbox_mail_spool, start, DEFAULT_TEXT_BUFFER_SIZE);
|
strncpy(mbox_mail_spool, start, DEFAULT_TEXT_BUFFER_SIZE);
|
||||||
free(copy_args);
|
free(copy_args);
|
||||||
@@ -189,9 +185,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
|||||||
curr->from[0] = '\0';
|
curr->from[0] = '\0';
|
||||||
curr->subject[0] = '\0';
|
curr->subject[0] = '\0';
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) { startlist = curr; }
|
||||||
startlist = curr;
|
|
||||||
}
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
curr->previous = prev;
|
curr->previous = prev;
|
||||||
prev->next = curr;
|
prev->next = curr;
|
||||||
@@ -199,34 +193,26 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
|||||||
prev = curr;
|
prev = curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startlist == nullptr) {
|
if (startlist == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* connect end to start for an endless loop-ring */
|
/* connect end to start for an endless loop-ring */
|
||||||
startlist->previous = curr;
|
startlist->previous = curr;
|
||||||
curr->next = startlist;
|
curr->next = startlist;
|
||||||
|
|
||||||
/* mbox */
|
/* mbox */
|
||||||
fp = fopen(mbox_mail_spool, "re");
|
fp = fopen(mbox_mail_spool, "re");
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* first find a "From " to set it to 0 for header-sarchings */
|
/* first find a "From " to set it to 0 for header-sarchings */
|
||||||
flag = 1;
|
flag = 1;
|
||||||
while (feof(fp) == 0) {
|
while (feof(fp) == 0) {
|
||||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strncmp(buf, "From ", 5) == 0) {
|
if (strncmp(buf, "From ", 5) == 0) {
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
|
|
||||||
/* skip until \n */
|
/* skip until \n */
|
||||||
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
||||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flag = 0; /* in the headers now */
|
flag = 0; /* in the headers now */
|
||||||
@@ -242,9 +228,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
|||||||
/* then search for new mail ("From ") */
|
/* then search for new mail ("From ") */
|
||||||
|
|
||||||
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
||||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
flag = 1; /* in the body now */
|
flag = 1; /* in the body now */
|
||||||
continue;
|
continue;
|
||||||
@@ -260,9 +244,7 @@ static void mbox_scan(char *args, char *output, size_t max_len) {
|
|||||||
curr = curr->previous;
|
curr = curr->previous;
|
||||||
/* Skip until \n */
|
/* Skip until \n */
|
||||||
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
while (strchr(buf, '\n') == nullptr && (feof(fp) == 0)) {
|
||||||
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) {
|
if (fgets(buf, text_buffer_size.get(*state), fp) == nullptr) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -398,9 +380,7 @@ void parse_mboxscan_arg(struct text_object *obj, const char *arg) {
|
|||||||
void print_mboxscan(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_mboxscan(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||||
auto *msd = static_cast<mboxscan_data *>(obj->data.opaque);
|
auto *msd = static_cast<mboxscan_data *>(obj->data.opaque);
|
||||||
|
|
||||||
if (msd == nullptr) {
|
if (msd == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mbox_scan(msd->args, msd->output, text_buffer_size.get(*state));
|
mbox_scan(msd->args, msd->output, text_buffer_size.get(*state));
|
||||||
snprintf(p, p_max_size, "%s", msd->output);
|
snprintf(p, p_max_size, "%s", msd->output);
|
||||||
@@ -409,9 +389,7 @@ void print_mboxscan(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
void free_mboxscan(struct text_object *obj) {
|
void free_mboxscan(struct text_object *obj) {
|
||||||
auto *msd = static_cast<mboxscan_data *>(obj->data.opaque);
|
auto *msd = static_cast<mboxscan_data *>(obj->data.opaque);
|
||||||
|
|
||||||
if (msd == nullptr) {
|
if (msd == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
free_and_zero(msd->args);
|
free_and_zero(msd->args);
|
||||||
free_and_zero(msd->output);
|
free_and_zero(msd->output);
|
||||||
free_and_zero(obj->data.opaque);
|
free_and_zero(obj->data.opaque);
|
||||||
|
12
src/mixer.cc
12
src/mixer.cc
@@ -59,9 +59,7 @@ static const char *devs[] = SOUND_DEVICE_NAMES;
|
|||||||
int mixer_init(const char *name) {
|
int mixer_init(const char *name) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (name == 0 || name[0] == '\0') {
|
if (name == 0 || name[0] == '\0') { name = "vol"; }
|
||||||
name = "vol";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* open mixer */
|
/* open mixer */
|
||||||
if (mixer_fd <= 0) {
|
if (mixer_fd <= 0) {
|
||||||
@@ -73,9 +71,7 @@ int mixer_init(const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < sizeof(devs) / sizeof(const char *); i++) {
|
for (i = 0; i < sizeof(devs) / sizeof(const char *); i++) {
|
||||||
if (strcasecmp(devs[i], name) == 0) {
|
if (strcasecmp(devs[i], name) == 0) { return i; }
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -86,9 +82,7 @@ static int mixer_get(int i) {
|
|||||||
int val = -1;
|
int val = -1;
|
||||||
|
|
||||||
if (ioctl(mixer_fd, MIXER_READ(i), &val) == -1) {
|
if (ioctl(mixer_fd, MIXER_READ(i), &val) == -1) {
|
||||||
if (!rep) {
|
if (!rep) { NORM_ERR("mixer ioctl: %s", strerror(errno)); }
|
||||||
NORM_ERR("mixer ioctl: %s", strerror(errno));
|
|
||||||
}
|
|
||||||
rep = 1;
|
rep = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -70,12 +70,8 @@ void moc_cb::work() {
|
|||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
/* Read a line from the pipe and strip the possible '\n'. */
|
/* Read a line from the pipe and strip the possible '\n'. */
|
||||||
if (fgets(line, 100, fp) == nullptr) {
|
if (fgets(line, 100, fp) == nullptr) { break; }
|
||||||
break;
|
if ((p = strrchr(line, '\n')) != nullptr) { *p = '\0'; }
|
||||||
}
|
|
||||||
if ((p = strrchr(line, '\n')) != nullptr) {
|
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse infos. */
|
/* Parse infos. */
|
||||||
if (strncmp(line, "State:", 6) == 0) {
|
if (strncmp(line, "State:", 6) == 0) {
|
||||||
|
32
src/mpd.cc
32
src/mpd.cc
@@ -27,13 +27,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mpd.h"
|
#include "mpd.h"
|
||||||
|
#include <cmath>
|
||||||
|
#include <mutex>
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "libmpdclient.h"
|
#include "libmpdclient.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "timeinfo.h"
|
#include "timeinfo.h"
|
||||||
#include "update-cb.hh"
|
#include "update-cb.hh"
|
||||||
#include <cmath>
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -61,9 +61,7 @@ void mpd_host_setting::lua_setter(lua::state &l, bool init) {
|
|||||||
l.checkstack(1);
|
l.checkstack(1);
|
||||||
const char *h = strchr(t, '@');
|
const char *h = strchr(t, '@');
|
||||||
if (h != nullptr) {
|
if (h != nullptr) {
|
||||||
if (h[1] != 0) {
|
if (h[1] != 0) { l.pushstring(h + 1); }
|
||||||
l.pushstring(h + 1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
l.pushstring(t);
|
l.pushstring(t);
|
||||||
}
|
}
|
||||||
@@ -147,9 +145,7 @@ class mpd_cb : public conky::callback<mpd_result> {
|
|||||||
: Base(period, false, Tuple()), conn(nullptr) {}
|
: Base(period, false, Tuple()), conn(nullptr) {}
|
||||||
|
|
||||||
~mpd_cb() override {
|
~mpd_cb() override {
|
||||||
if (conn != nullptr) {
|
if (conn != nullptr) { mpd_closeConnection(conn); }
|
||||||
mpd_closeConnection(conn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -234,8 +230,8 @@ void mpd_cb::work() {
|
|||||||
mpd_info.is_playing = 1;
|
mpd_info.is_playing = 1;
|
||||||
mpd_info.bitrate = status->bitRate;
|
mpd_info.bitrate = status->bitRate;
|
||||||
mpd_info.progress =
|
mpd_info.progress =
|
||||||
((0 != status->totalTime) ?
|
((0 != status->totalTime)
|
||||||
static_cast<float>(status->elapsedTime) / status->totalTime
|
? static_cast<float>(status->elapsedTime) / status->totalTime
|
||||||
: 0.0);
|
: 0.0);
|
||||||
mpd_info.elapsed = status->elapsedTime;
|
mpd_info.elapsed = status->elapsedTime;
|
||||||
mpd_info.length = status->totalTime;
|
mpd_info.length = status->totalTime;
|
||||||
@@ -335,12 +331,14 @@ static inline void format_media_player_time(char *buf, const int size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_mpd_elapsed(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_mpd_elapsed(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
format_media_player_time(p, p_max_size, get_mpd().elapsed);
|
format_media_player_time(p, p_max_size, get_mpd().elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_mpd_length(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_mpd_length(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
format_media_player_time(p, p_max_size, get_mpd().length);
|
format_media_player_time(p, p_max_size, get_mpd().length);
|
||||||
}
|
}
|
||||||
@@ -355,12 +353,11 @@ double mpd_barval(struct text_object *obj) {
|
|||||||
return get_mpd().progress;
|
return get_mpd().progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_mpd_smart(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_mpd_smart(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
const mpd_result &mpd_info = get_mpd();
|
const mpd_result &mpd_info = get_mpd();
|
||||||
int len = obj->data.i;
|
int len = obj->data.i;
|
||||||
if (len == 0 || (unsigned int) len > p_max_size) {
|
if (len == 0 || (unsigned int)len > p_max_size) { len = p_max_size; }
|
||||||
len = p_max_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(p, 0, p_max_size);
|
memset(p, 0, p_max_size);
|
||||||
if ((static_cast<unsigned int>(!mpd_info.artist.empty()) != 0u) &&
|
if ((static_cast<unsigned int>(!mpd_info.artist.empty()) != 0u) &&
|
||||||
@@ -386,7 +383,8 @@ int check_mpd_playing(struct text_object *obj) {
|
|||||||
#define MPD_PRINT_GENERATOR(name, fmt, acc) \
|
#define MPD_PRINT_GENERATOR(name, fmt, acc) \
|
||||||
void print_mpd_##name(struct text_object *obj, char *p, \
|
void print_mpd_##name(struct text_object *obj, char *p, \
|
||||||
unsigned int p_max_size) { \
|
unsigned int p_max_size) { \
|
||||||
if (obj->data.i && (unsigned int) obj->data.i < p_max_size) p_max_size = obj->data.i; \
|
if (obj->data.i && (unsigned int)obj->data.i < p_max_size) \
|
||||||
|
p_max_size = obj->data.i; \
|
||||||
snprintf(p, p_max_size, fmt, get_mpd().name acc); \
|
snprintf(p, p_max_size, fmt, get_mpd().name acc); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,9 +26,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "mysql.h"
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "mysql.h"
|
|
||||||
|
|
||||||
#include <mysql.h>
|
#include <mysql.h>
|
||||||
|
|
||||||
|
@@ -52,9 +52,7 @@ void out_to_ncurses_setting::lua_setter(lua::state &l, bool init) {
|
|||||||
void out_to_ncurses_setting::cleanup(lua::state &l) {
|
void out_to_ncurses_setting::cleanup(lua::state &l) {
|
||||||
lua::stack_sentry s(l, -1);
|
lua::stack_sentry s(l, -1);
|
||||||
|
|
||||||
if (do_convert(l, -1).first) {
|
if (do_convert(l, -1).first) { endwin(); }
|
||||||
endwin();
|
|
||||||
}
|
|
||||||
|
|
||||||
l.pop();
|
l.pop();
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
#define NVIDIA_CONKY_H
|
#define NVIDIA_CONKY_H
|
||||||
|
|
||||||
int set_nvidia_query(struct text_object *, const char *, unsigned int);
|
int set_nvidia_query(struct text_object *, const char *, unsigned int);
|
||||||
void print_nvidia_value(struct text_object *, char *,unsigned int);
|
void print_nvidia_value(struct text_object *, char *, unsigned int);
|
||||||
double get_nvidia_barval(struct text_object *);
|
double get_nvidia_barval(struct text_object *);
|
||||||
void free_nvidia(struct text_object *);
|
void free_nvidia(struct text_object *);
|
||||||
|
|
||||||
|
@@ -84,21 +84,15 @@ struct prio_queue *init_prio_queue() {
|
|||||||
|
|
||||||
void pq_set_compare(struct prio_queue *queue,
|
void pq_set_compare(struct prio_queue *queue,
|
||||||
int (*pqcompare)(void *a, void *b)) {
|
int (*pqcompare)(void *a, void *b)) {
|
||||||
if (pqcompare != nullptr) {
|
if (pqcompare != nullptr) { queue->compare = pqcompare; }
|
||||||
queue->compare = pqcompare;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pq_set_free(struct prio_queue *queue, void (*pqfree)(void *a)) {
|
void pq_set_free(struct prio_queue *queue, void (*pqfree)(void *a)) {
|
||||||
if (pqfree != nullptr) {
|
if (pqfree != nullptr) { queue->free = pqfree; }
|
||||||
queue->free = pqfree;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pq_set_max_size(struct prio_queue *queue, int max_size) {
|
void pq_set_max_size(struct prio_queue *queue, int max_size) {
|
||||||
if (max_size >= 0) {
|
if (max_size >= 0) { queue->max_size = max_size; }
|
||||||
queue->max_size = max_size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pq_get_cur_size(struct prio_queue *queue) { return queue->cur_size; }
|
int pq_get_cur_size(struct prio_queue *queue) { return queue->cur_size; }
|
||||||
@@ -117,9 +111,7 @@ void insert_prio_elem(struct prio_queue *queue, void *data) {
|
|||||||
struct prio_elem *cur;
|
struct prio_elem *cur;
|
||||||
|
|
||||||
/* queue->compare is a must-have */
|
/* queue->compare is a must-have */
|
||||||
if (queue->compare == nullptr) {
|
if (queue->compare == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* empty queue, insert the first item */
|
/* empty queue, insert the first item */
|
||||||
if (queue->cur_size == 0) {
|
if (queue->cur_size == 0) {
|
||||||
@@ -176,9 +168,7 @@ void *pop_prio_elem(struct prio_queue *queue) {
|
|||||||
struct prio_elem *tmp;
|
struct prio_elem *tmp;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
if (queue->cur_size <= 0) {
|
if (queue->cur_size <= 0) { return nullptr; }
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = queue->head;
|
tmp = queue->head;
|
||||||
data = tmp->data;
|
data = tmp->data;
|
||||||
@@ -197,8 +187,6 @@ void *pop_prio_elem(struct prio_queue *queue) {
|
|||||||
|
|
||||||
void free_prio_queue(struct prio_queue *queue) {
|
void free_prio_queue(struct prio_queue *queue) {
|
||||||
void *data;
|
void *data;
|
||||||
while ((data = pop_prio_elem(queue)) != nullptr) {
|
while ((data = pop_prio_elem(queue)) != nullptr) { (*queue->free)(data); }
|
||||||
(*queue->free)(data);
|
|
||||||
}
|
|
||||||
free(queue);
|
free(queue);
|
||||||
}
|
}
|
||||||
|
169
src/proc.cc
169
src/proc.cc
@@ -32,10 +32,10 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
char *readfile(const char *filename, int *total_read, char showerror) {
|
char *readfile(const char *filename, int *total_read, char showerror) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
@@ -79,18 +79,14 @@ struct ll_string *addnode(struct ll_string *end, char *string) {
|
|||||||
static_cast<struct ll_string *>(malloc(sizeof(struct ll_string)));
|
static_cast<struct ll_string *>(malloc(sizeof(struct ll_string)));
|
||||||
current->string = strdup(string);
|
current->string = strdup(string);
|
||||||
current->next = nullptr;
|
current->next = nullptr;
|
||||||
if (end != nullptr) {
|
if (end != nullptr) { end->next = current; }
|
||||||
end->next = current;
|
|
||||||
}
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freelist(struct ll_string *front) {
|
void freelist(struct ll_string *front) {
|
||||||
if (front != nullptr) {
|
if (front != nullptr) {
|
||||||
free(front->string);
|
free(front->string);
|
||||||
if (front->next != nullptr) {
|
if (front->next != nullptr) { freelist(front->next); }
|
||||||
freelist(front->next);
|
|
||||||
}
|
|
||||||
free(front);
|
free(front);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,14 +95,13 @@ int inlist(struct ll_string *front, char *string) {
|
|||||||
struct ll_string *current;
|
struct ll_string *current;
|
||||||
|
|
||||||
for (current = front; current != nullptr; current = current->next) {
|
for (current = front; current != nullptr; current = current->next) {
|
||||||
if (strcmp(current->string, string) == 0) {
|
if (strcmp(current->string, string) == 0) { return 1; }
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_chroot(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_chroot(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
std::unique_ptr<char[]> buf(new char[max_user_text.get(*state)]);
|
std::unique_ptr<char[]> buf(new char[max_user_text.get(*state)]);
|
||||||
|
|
||||||
@@ -115,7 +110,8 @@ void print_pid_chroot(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_cmdline(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_cmdline(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
char *buf;
|
char *buf;
|
||||||
int i, bytes_read;
|
int i, bytes_read;
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
@@ -128,9 +124,7 @@ void print_pid_cmdline(struct text_object *obj, char *p, unsigned int p_max_size
|
|||||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||||
if (buf != nullptr) {
|
if (buf != nullptr) {
|
||||||
for (i = 0; i < bytes_read - 1; i++) {
|
for (i = 0; i < bytes_read - 1; i++) {
|
||||||
if (buf[i] == 0) {
|
if (buf[i] == 0) { buf[i] = ' '; }
|
||||||
buf[i] = ' ';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
snprintf(p, p_max_size, "%s", buf);
|
snprintf(p, p_max_size, "%s", buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
@@ -157,7 +151,8 @@ void print_pid_cwd(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_environ(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int i, total_read;
|
int i, total_read;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
@@ -167,9 +162,7 @@ void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size
|
|||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||||
if (sscanf(objbuf.get(), "%d %s", &pid, var) == 2) {
|
if (sscanf(objbuf.get(), "%d %s", &pid, var) == 2) {
|
||||||
for (i = 0; var[i] != 0; i++) {
|
for (i = 0; var[i] != 0; i++) { var[i] = toupper((unsigned char)var[i]); }
|
||||||
var[i] = toupper((unsigned char)var[i]);
|
|
||||||
}
|
|
||||||
pathstream << PROCDIR "/" << pid << "/cwd";
|
pathstream << PROCDIR "/" << pid << "/cwd";
|
||||||
buf = readfile(pathstream.str().c_str(), &total_read, 1);
|
buf = readfile(pathstream.str().c_str(), &total_read, 1);
|
||||||
if (buf != nullptr) {
|
if (buf != nullptr) {
|
||||||
@@ -189,7 +182,8 @@ void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size
|
|||||||
free(var);
|
free(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_environ_list(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_environ_list(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
char *buf = nullptr;
|
char *buf = nullptr;
|
||||||
char *buf2;
|
char *buf2;
|
||||||
int bytes_read, total_read;
|
int bytes_read, total_read;
|
||||||
@@ -249,7 +243,8 @@ void print_pid_nice(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_openfiles(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
std::unique_ptr<char[]> buf(new char[p_max_size]);
|
std::unique_ptr<char[]> buf(new char[p_max_size]);
|
||||||
@@ -273,9 +268,7 @@ void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_si
|
|||||||
buf.get());
|
buf.get());
|
||||||
totallength += length + strlen("; ");
|
totallength += length + strlen("; ");
|
||||||
}
|
}
|
||||||
if (files_front == nullptr) {
|
if (files_front == nullptr) { files_front = files_back; }
|
||||||
files_front = files_back;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@@ -286,7 +279,8 @@ void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_si
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_parent(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
#define PARENT_ENTRY "PPid:\t"
|
#define PARENT_ENTRY "PPid:\t"
|
||||||
#define PARENTNOTFOUND "Can't find the process parent in '%s'"
|
#define PARENTNOTFOUND "Can't find the process parent in '%s'"
|
||||||
char *begin, *end, *buf = nullptr;
|
char *begin, *end, *buf = nullptr;
|
||||||
@@ -303,9 +297,7 @@ void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
if (begin != nullptr) {
|
if (begin != nullptr) {
|
||||||
begin += strlen(PARENT_ENTRY);
|
begin += strlen(PARENT_ENTRY);
|
||||||
end = strchr(begin, '\n');
|
end = strchr(begin, '\n');
|
||||||
if (end != nullptr) {
|
if (end != nullptr) { *(end) = 0; }
|
||||||
*(end) = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", begin);
|
snprintf(p, p_max_size, "%s", begin);
|
||||||
} else {
|
} else {
|
||||||
NORM_ERR(PARENTNOTFOUND, pathstream.str().c_str());
|
NORM_ERR(PARENTNOTFOUND, pathstream.str().c_str());
|
||||||
@@ -314,7 +306,8 @@ void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_priority(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_priority(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
char *buf = nullptr;
|
char *buf = nullptr;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
long int priority;
|
long int priority;
|
||||||
@@ -339,7 +332,8 @@ void print_pid_priority(struct text_object *obj, char *p, unsigned int p_max_siz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_state(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
#define STATE_ENTRY "State:\t"
|
#define STATE_ENTRY "State:\t"
|
||||||
#define STATENOTFOUND "Can't find the process state in '%s'"
|
#define STATENOTFOUND "Can't find the process state in '%s'"
|
||||||
char *begin, *end, *buf = nullptr;
|
char *begin, *end, *buf = nullptr;
|
||||||
@@ -369,7 +363,8 @@ void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_state_short(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_state_short(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
char *begin, *buf = nullptr;
|
char *begin, *buf = nullptr;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
@@ -391,7 +386,8 @@ void print_pid_state_short(struct text_object *obj, char *p, unsigned int p_max_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_stderr(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_stderr(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||||
|
|
||||||
@@ -401,7 +397,8 @@ void print_pid_stderr(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_stdin(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_stdin(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
|
|
||||||
@@ -411,7 +408,8 @@ void print_pid_stdin(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
pid_readlink(pathstream.str().c_str(), p, p_max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_stdout(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_stdout(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
|
||||||
|
|
||||||
@@ -437,15 +435,14 @@ void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg,
|
|||||||
strlen(obj->data.s + i + 1) + 1);
|
strlen(obj->data.s + i + 1) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj->data.s[i - 1] == ' ') {
|
if (obj->data.s[i - 1] == ' ') { obj->data.s[i - 1] = 0; }
|
||||||
obj->data.s[i - 1] = 0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(obj, free_at_crash, "${cmdline_to_pid commandline}");
|
CRIT_ERR(obj, free_at_crash, "${cmdline_to_pid commandline}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_cmdline_to_pid(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
char *buf;
|
char *buf;
|
||||||
@@ -460,9 +457,7 @@ void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_s
|
|||||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 0);
|
buf = readfile(pathstream.str().c_str(), &bytes_read, 0);
|
||||||
if (buf != nullptr) {
|
if (buf != nullptr) {
|
||||||
for (i = 0; i < bytes_read - 1; i++) {
|
for (i = 0; i < bytes_read - 1; i++) {
|
||||||
if (buf[i] == 0) {
|
if (buf[i] == 0) { buf[i] = ' '; }
|
||||||
buf[i] = ' ';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (strstr(buf, obj->data.s) != nullptr) {
|
if (strstr(buf, obj->data.s) != nullptr) {
|
||||||
snprintf(p, p_max_size, "%s", entry->d_name);
|
snprintf(p, p_max_size, "%s", entry->d_name);
|
||||||
@@ -479,7 +474,8 @@ void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_threads(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
#define THREADS_ENTRY "Threads:\t"
|
#define THREADS_ENTRY "Threads:\t"
|
||||||
#define THREADSNOTFOUND \
|
#define THREADSNOTFOUND \
|
||||||
"Can't find the number of the threads of the process in '%s'"
|
"Can't find the number of the threads of the process in '%s'"
|
||||||
@@ -497,9 +493,7 @@ void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size
|
|||||||
if (begin != nullptr) {
|
if (begin != nullptr) {
|
||||||
begin += strlen(THREADS_ENTRY);
|
begin += strlen(THREADS_ENTRY);
|
||||||
end = strchr(begin, '\n');
|
end = strchr(begin, '\n');
|
||||||
if (end != nullptr) {
|
if (end != nullptr) { *(end) = 0; }
|
||||||
*(end) = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", begin);
|
snprintf(p, p_max_size, "%s", begin);
|
||||||
} else {
|
} else {
|
||||||
NORM_ERR(THREADSNOTFOUND, pathstream.str().c_str());
|
NORM_ERR(THREADSNOTFOUND, pathstream.str().c_str());
|
||||||
@@ -508,7 +502,8 @@ void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_thread_list(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_thread_list(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
int totallength = 0;
|
int totallength = 0;
|
||||||
@@ -528,9 +523,7 @@ void print_pid_thread_list(struct text_object *obj, char *p, unsigned int p_max_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
if (p[totallength - 1] == ',') {
|
if (p[totallength - 1] == ',') { p[totallength - 1] = 0; }
|
||||||
p[totallength - 1] = 0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
}
|
}
|
||||||
@@ -560,7 +553,8 @@ void print_pid_time_kernelmode(struct text_object *obj, char *p,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_time_usermode(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_time_usermode(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
char *buf = nullptr;
|
char *buf = nullptr;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
unsigned long int kmtime;
|
unsigned long int kmtime;
|
||||||
@@ -607,9 +601,10 @@ void print_pid_time(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum idtype {egid, euid, fsgid, fsuid, gid, sgid, suid, uid};
|
enum idtype { egid, euid, fsgid, fsuid, gid, sgid, suid, uid };
|
||||||
|
|
||||||
void print_pid_Xid(struct text_object *obj, char *p, int p_max_size, idtype type) {
|
void print_pid_Xid(struct text_object *obj, char *p, int p_max_size,
|
||||||
|
idtype type) {
|
||||||
char *begin, *end, *buf = nullptr;
|
char *begin, *end, *buf = nullptr;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
@@ -621,7 +616,7 @@ void print_pid_Xid(struct text_object *obj, char *p, int p_max_size, idtype type
|
|||||||
|
|
||||||
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
|
||||||
if (buf != nullptr) {
|
if (buf != nullptr) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case egid:
|
case egid:
|
||||||
begin = strstr(buf, "Gid:\t");
|
begin = strstr(buf, "Gid:\t");
|
||||||
break;
|
break;
|
||||||
@@ -650,7 +645,7 @@ void print_pid_Xid(struct text_object *obj, char *p, int p_max_size, idtype type
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (begin != nullptr) {
|
if (begin != nullptr) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case gid:
|
case gid:
|
||||||
begin += strlen("Gid:\t");
|
begin += strlen("Gid:\t");
|
||||||
break;
|
break;
|
||||||
@@ -687,14 +682,15 @@ void print_pid_Xid(struct text_object *obj, char *p, int p_max_size, idtype type
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(type == fsgid || type == fsuid) end = strchr(begin, '\n'); else end = strchr(begin, '\t');
|
if (type == fsgid || type == fsuid)
|
||||||
if (end != nullptr) {
|
end = strchr(begin, '\n');
|
||||||
*(end) = 0;
|
else
|
||||||
}
|
end = strchr(begin, '\t');
|
||||||
|
if (end != nullptr) { *(end) = 0; }
|
||||||
snprintf(p, p_max_size, "%s", begin);
|
snprintf(p, p_max_size, "%s", begin);
|
||||||
} else {
|
} else {
|
||||||
errorstring = "Can't find the process ";
|
errorstring = "Can't find the process ";
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case egid:
|
case egid:
|
||||||
errorstring.append("effective gid");
|
errorstring.append("effective gid");
|
||||||
break;
|
break;
|
||||||
@@ -737,11 +733,13 @@ void print_pid_euid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
print_pid_Xid(obj, p, p_max_size, euid);
|
print_pid_Xid(obj, p, p_max_size, euid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_fsgid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_fsgid(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
print_pid_Xid(obj, p, p_max_size, fsgid);
|
print_pid_Xid(obj, p, p_max_size, fsgid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_fsuid(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_fsuid(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
print_pid_Xid(obj, p, p_max_size, fsuid);
|
print_pid_Xid(obj, p, p_max_size, fsuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,13 +774,9 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size,
|
|||||||
begin = strstr(buf, entry);
|
begin = strstr(buf, entry);
|
||||||
if (begin != nullptr) {
|
if (begin != nullptr) {
|
||||||
begin += strlen(entry);
|
begin += strlen(entry);
|
||||||
while (*begin == '\t' || *begin == ' ') {
|
while (*begin == '\t' || *begin == ' ') { begin++; }
|
||||||
begin++;
|
|
||||||
}
|
|
||||||
end = strchr(begin, '\n');
|
end = strchr(begin, '\n');
|
||||||
if (end != nullptr) {
|
if (end != nullptr) { *(end) = 0; }
|
||||||
*(end) = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", begin);
|
snprintf(p, p_max_size, "%s", begin);
|
||||||
} else {
|
} else {
|
||||||
NORM_ERR(errorstring, pathstream.str().c_str());
|
NORM_ERR(errorstring, pathstream.str().c_str());
|
||||||
@@ -791,55 +785,65 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmpeak(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmpeak(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(
|
internal_print_pid_vm(
|
||||||
obj, p, p_max_size, "VmPeak:\t",
|
obj, p, p_max_size, "VmPeak:\t",
|
||||||
"Can't find the process peak virtual memory size in '%s'");
|
"Can't find the process peak virtual memory size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmsize(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmsize(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(obj, p, p_max_size, "VmSize:\t",
|
internal_print_pid_vm(obj, p, p_max_size, "VmSize:\t",
|
||||||
"Can't find the process virtual memory size in '%s'");
|
"Can't find the process virtual memory size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmlck(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmlck(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(obj, p, p_max_size, "VmLck:\t",
|
internal_print_pid_vm(obj, p, p_max_size, "VmLck:\t",
|
||||||
"Can't find the process locked memory size in '%s'");
|
"Can't find the process locked memory size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmhwm(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmhwm(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(
|
internal_print_pid_vm(
|
||||||
obj, p, p_max_size, "VmHWM:\t",
|
obj, p, p_max_size, "VmHWM:\t",
|
||||||
"Can't find the process peak resident set size in '%s'");
|
"Can't find the process peak resident set size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmrss(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmrss(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(obj, p, p_max_size, "VmHWM:\t",
|
internal_print_pid_vm(obj, p, p_max_size, "VmHWM:\t",
|
||||||
"Can't find the process resident set size in '%s'");
|
"Can't find the process resident set size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmdata(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmdata(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
||||||
"Can't find the process data segment size in '%s'");
|
"Can't find the process data segment size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmstk(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmstk(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
||||||
"Can't find the process stack segment size in '%s'");
|
"Can't find the process stack segment size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmexe(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmexe(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t",
|
||||||
"Can't find the process text segment size in '%s'");
|
"Can't find the process text segment size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmlib(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmlib(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(
|
internal_print_pid_vm(
|
||||||
obj, p, p_max_size, "VmLib:\t",
|
obj, p, p_max_size, "VmLib:\t",
|
||||||
"Can't find the process shared library code size in '%s'");
|
"Can't find the process shared library code size in '%s'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_vmpte(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_vmpte(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
internal_print_pid_vm(
|
internal_print_pid_vm(
|
||||||
obj, p, p_max_size, "VmPTE:\t",
|
obj, p, p_max_size, "VmPTE:\t",
|
||||||
"Can't find the process page table entries size in '%s'");
|
"Can't find the process page table entries size in '%s'");
|
||||||
@@ -861,9 +865,7 @@ void print_pid_read(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
begin = strstr(buf, READ_ENTRY);
|
begin = strstr(buf, READ_ENTRY);
|
||||||
if (begin != nullptr) {
|
if (begin != nullptr) {
|
||||||
end = strchr(begin, '\n');
|
end = strchr(begin, '\n');
|
||||||
if (end != nullptr) {
|
if (end != nullptr) { *(end) = 0; }
|
||||||
*(end) = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", begin);
|
snprintf(p, p_max_size, "%s", begin);
|
||||||
} else {
|
} else {
|
||||||
NORM_ERR(READNOTFOUND, pathstream.str().c_str());
|
NORM_ERR(READNOTFOUND, pathstream.str().c_str());
|
||||||
@@ -874,7 +876,8 @@ void print_pid_read(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
|
|
||||||
#define WRITE_ENTRY "write_bytes: "
|
#define WRITE_ENTRY "write_bytes: "
|
||||||
#define WRITENOTFOUND "Can't find the amount of bytes written in '%s'"
|
#define WRITENOTFOUND "Can't find the amount of bytes written in '%s'"
|
||||||
void print_pid_write(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_pid_write(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
char *begin, *end, *buf = nullptr;
|
char *begin, *end, *buf = nullptr;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
std::ostringstream pathstream;
|
std::ostringstream pathstream;
|
||||||
@@ -888,9 +891,7 @@ void print_pid_write(struct text_object *obj, char *p, unsigned int p_max_size)
|
|||||||
begin = strstr(buf, WRITE_ENTRY);
|
begin = strstr(buf, WRITE_ENTRY);
|
||||||
if (begin != nullptr) {
|
if (begin != nullptr) {
|
||||||
end = strchr(begin, '\n');
|
end = strchr(begin, '\n');
|
||||||
if (end != nullptr) {
|
if (end != nullptr) { *(end) = 0; }
|
||||||
*(end) = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", begin);
|
snprintf(p, p_max_size, "%s", begin);
|
||||||
} else {
|
} else {
|
||||||
NORM_ERR(WRITENOTFOUND, pathstream.str().c_str());
|
NORM_ERR(WRITENOTFOUND, pathstream.str().c_str());
|
||||||
|
51
src/proc.h
51
src/proc.h
@@ -34,26 +34,39 @@
|
|||||||
#define READERR "Can't read '%s'"
|
#define READERR "Can't read '%s'"
|
||||||
#define READSIZE 128
|
#define READSIZE 128
|
||||||
|
|
||||||
void print_pid_chroot(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_chroot(struct text_object *obj, char *p,
|
||||||
void print_pid_cmdline(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
|
void print_pid_cmdline(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_cwd(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_cwd(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_environ(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_environ(struct text_object *obj, char *p,
|
||||||
void print_pid_environ_list(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
|
void print_pid_environ_list(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_exe(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_exe(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_nice(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_nice(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_openfiles(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_openfiles(struct text_object *obj, char *p,
|
||||||
void print_pid_parent(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
void print_pid_priority(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_parent(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
|
void print_pid_priority(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_state(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_state_short(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_state_short(struct text_object *obj, char *p,
|
||||||
void print_pid_stderr(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
|
void print_pid_stderr(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_stdin(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_stdin(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_stdout(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_stdout(struct text_object *obj, char *p,
|
||||||
void print_pid_threads(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
void print_pid_thread_list(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_threads(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
|
void print_pid_thread_list(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_time_kernelmode(struct text_object *obj, char *p,
|
void print_pid_time_kernelmode(struct text_object *obj, char *p,
|
||||||
unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
void print_pid_time_usermode(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_time_usermode(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_time(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_time(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_uid(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_uid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_euid(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_euid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
@@ -64,12 +77,15 @@ void print_pid_egid(struct text_object *obj, char *p, unsigned int p_max_size);
|
|||||||
void print_pid_sgid(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_sgid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_fsgid(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_fsgid(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_read(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_read(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_vmpeak(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmpeak(struct text_object *obj, char *p,
|
||||||
void print_pid_vmsize(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
|
void print_pid_vmsize(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_vmlck(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmlck(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_vmhwm(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmhwm(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_vmrss(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmrss(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_vmdata(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmdata(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
void print_pid_vmstk(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmstk(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_vmexe(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmexe(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
void print_pid_vmlib(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_pid_vmlib(struct text_object *obj, char *p, unsigned int p_max_size);
|
||||||
@@ -78,6 +94,7 @@ void print_pid_write(struct text_object *obj, char *p, unsigned int p_max_size);
|
|||||||
|
|
||||||
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg,
|
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg,
|
||||||
void *free_at_crash);
|
void *free_at_crash);
|
||||||
void print_cmdline_to_pid(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_cmdline_to_pid(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
|
|
||||||
#endif /* CONKY_PROC_H */
|
#endif /* CONKY_PROC_H */
|
||||||
|
28
src/prss.cc
28
src/prss.cc
@@ -101,14 +101,10 @@ static inline void read_item(PRSS_Item *res, xmlNodePtr data) {
|
|||||||
for (; data; data = data->next) {
|
for (; data; data = data->next) {
|
||||||
xmlNodePtr child;
|
xmlNodePtr child;
|
||||||
|
|
||||||
if (data->type != XML_ELEMENT_NODE) {
|
if (data->type != XML_ELEMENT_NODE) { continue; }
|
||||||
continue;
|
|
||||||
}
|
|
||||||
child = data->children;
|
child = data->children;
|
||||||
|
|
||||||
if (!child) {
|
if (!child) { continue; }
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ASSIGN(a) \
|
#define ASSIGN(a) \
|
||||||
if (strcasecmp((const char *)data->name, #a) == EQUAL) { \
|
if (strcasecmp((const char *)data->name, #a) == EQUAL) { \
|
||||||
@@ -128,14 +124,10 @@ static inline void read_item(PRSS_Item *res, xmlNodePtr data) {
|
|||||||
static inline void read_element(PRSS *res, xmlNodePtr n) {
|
static inline void read_element(PRSS *res, xmlNodePtr n) {
|
||||||
xmlNodePtr child;
|
xmlNodePtr child;
|
||||||
|
|
||||||
if (n->type != XML_ELEMENT_NODE) {
|
if (n->type != XML_ELEMENT_NODE) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
child = n->children;
|
child = n->children;
|
||||||
|
|
||||||
if (!child) {
|
if (!child) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ASSIGN(a) \
|
#define ASSIGN(a) \
|
||||||
if (strcasecmp((const char *)n->name, #a) == EQUAL) { \
|
if (strcasecmp((const char *)n->name, #a) == EQUAL) { \
|
||||||
@@ -172,9 +164,7 @@ static inline int parse_rss_2_0(PRSS *res, xmlNodePtr root) {
|
|||||||
strcmp((const char *)channel->name, "channel"))) {
|
strcmp((const char *)channel->name, "channel"))) {
|
||||||
channel = channel->next;
|
channel = channel->next;
|
||||||
}
|
}
|
||||||
if (!channel) {
|
if (!channel) { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (n = channel->children; n; n = n->next) {
|
for (n = channel->children; n; n = n->next) {
|
||||||
if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)n->name, "item")) {
|
if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)n->name, "item")) {
|
||||||
@@ -188,9 +178,7 @@ static inline int parse_rss_2_0(PRSS *res, xmlNodePtr root) {
|
|||||||
res->items = (PRSS_Item *)malloc(items * sizeof(PRSS_Item));
|
res->items = (PRSS_Item *)malloc(items * sizeof(PRSS_Item));
|
||||||
res->item_count = 0;
|
res->item_count = 0;
|
||||||
|
|
||||||
for (n = channel->children; n; n = n->next) {
|
for (n = channel->children; n; n = n->next) { read_element(res, n); }
|
||||||
read_element(res, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -207,9 +195,7 @@ static inline int parse_rss_1_0(PRSS *res, xmlNodePtr root) {
|
|||||||
} else if (!strcmp((const char *)n->name, "channel")) {
|
} else if (!strcmp((const char *)n->name, "channel")) {
|
||||||
xmlNodePtr i;
|
xmlNodePtr i;
|
||||||
|
|
||||||
for (i = n->children; i; i = i->next) {
|
for (i = n->children; i; i = i->next) { read_element(res, i); }
|
||||||
read_element(res, i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,11 +36,16 @@
|
|||||||
void init_pulseaudio(struct text_object *obj);
|
void init_pulseaudio(struct text_object *obj);
|
||||||
void free_pulseaudio(struct text_object *obj);
|
void free_pulseaudio(struct text_object *obj);
|
||||||
uint8_t puau_vol(struct text_object *); // preserve pa_* for libpulse
|
uint8_t puau_vol(struct text_object *); // preserve pa_* for libpulse
|
||||||
void print_puau_sink_description(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_puau_sink_description(struct text_object *obj, char *p,
|
||||||
void print_puau_sink_active_port_name(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
void print_puau_sink_active_port_description(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_puau_sink_active_port_name(struct text_object *obj, char *p,
|
||||||
void print_puau_card_name(struct text_object *obj, char *p, unsigned int p_max_size);
|
unsigned int p_max_size);
|
||||||
void print_puau_card_active_profile(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_puau_sink_active_port_description(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
|
void print_puau_card_name(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
|
void print_puau_card_active_profile(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
double puau_volumebarval(struct text_object *obj);
|
double puau_volumebarval(struct text_object *obj);
|
||||||
int puau_muted(struct text_object *obj);
|
int puau_muted(struct text_object *obj);
|
||||||
|
|
||||||
|
20
src/rss.cc
20
src/rss.cc
@@ -52,9 +52,7 @@ class rss_cb : public curl_callback<std::shared_ptr<PRSS>> {
|
|||||||
|
|
||||||
std::unique_lock<std::mutex> lock(Base::result_mutex);
|
std::unique_lock<std::mutex> lock(Base::result_mutex);
|
||||||
Base::result = tmp;
|
Base::result = tmp;
|
||||||
} catch (std::runtime_error &e) {
|
} catch (std::runtime_error &e) { NORM_ERR("%s", e.what()); }
|
||||||
NORM_ERR("%s", e.what());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -87,9 +85,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
|||||||
str = data->title;
|
str = data->title;
|
||||||
if (str && strlen(str) > 0) {
|
if (str && strlen(str) > 0) {
|
||||||
// remove trailing new line if one exists
|
// remove trailing new line if one exists
|
||||||
if (str[strlen(str) - 1] == '\n') {
|
if (str[strlen(str) - 1] == '\n') { str[strlen(str) - 1] = 0; }
|
||||||
str[strlen(str) - 1] = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", str);
|
snprintf(p, p_max_size, "%s", str);
|
||||||
}
|
}
|
||||||
} else if (strcmp(action, "item_title") == EQUAL) {
|
} else if (strcmp(action, "item_title") == EQUAL) {
|
||||||
@@ -97,9 +93,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
|||||||
str = data->items[act_par].title;
|
str = data->items[act_par].title;
|
||||||
// remove trailing new line if one exists
|
// remove trailing new line if one exists
|
||||||
if (str && strlen(str) > 0) {
|
if (str && strlen(str) > 0) {
|
||||||
if (str[strlen(str) - 1] == '\n') {
|
if (str[strlen(str) - 1] == '\n') { str[strlen(str) - 1] = 0; }
|
||||||
str[strlen(str) - 1] = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", str);
|
snprintf(p, p_max_size, "%s", str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,9 +102,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
|||||||
str = data->items[act_par].description;
|
str = data->items[act_par].description;
|
||||||
// remove trailing new line if one exists
|
// remove trailing new line if one exists
|
||||||
if (str && strlen(str) > 0) {
|
if (str && strlen(str) > 0) {
|
||||||
if (str[strlen(str) - 1] == '\n') {
|
if (str[strlen(str) - 1] == '\n') { str[strlen(str) - 1] = 0; }
|
||||||
str[strlen(str) - 1] = 0;
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", str);
|
snprintf(p, p_max_size, "%s", str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,9 +127,7 @@ static void rss_process_info(char *p, int p_max_size, const std::string &uri,
|
|||||||
str = item->title;
|
str = item->title;
|
||||||
if (str) {
|
if (str) {
|
||||||
// don't add new line before first item
|
// don't add new line before first item
|
||||||
if (itmp > 0) {
|
if (itmp > 0) { strncat(p, "\n", p_max_size); }
|
||||||
strncat(p, "\n", p_max_size);
|
|
||||||
}
|
|
||||||
/* remove trailing new line if one exists,
|
/* remove trailing new line if one exists,
|
||||||
* we have our own */
|
* we have our own */
|
||||||
if (strlen(str) > 0 && str[strlen(str) - 1] == '\n') {
|
if (strlen(str) > 0 && str[strlen(str) - 1] == '\n') {
|
||||||
|
@@ -71,9 +71,7 @@ settings_vector make_settings_vector() {
|
|||||||
settings_vector ret;
|
settings_vector ret;
|
||||||
ret.reserve(settings->size());
|
ret.reserve(settings->size());
|
||||||
|
|
||||||
for (auto &setting : *settings) {
|
for (auto &setting : *settings) { ret.push_back(setting.second); }
|
||||||
ret.push_back(setting.second);
|
|
||||||
}
|
|
||||||
sort(ret.begin(), ret.end(), &priv::config_setting_base::seq_compare);
|
sort(ret.begin(), ret.end(), &priv::config_setting_base::seq_compare);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -131,9 +129,7 @@ void config_setting_base::process_setting(lua::state &l, bool init) {
|
|||||||
lua::stack_sentry s(l, -3);
|
lua::stack_sentry s(l, -3);
|
||||||
|
|
||||||
config_setting_base *ptr = get_setting(l, -3);
|
config_setting_base *ptr = get_setting(l, -3);
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr->lua_setter(l, init);
|
ptr->lua_setter(l, init);
|
||||||
l.pushvalue(-2);
|
l.pushvalue(-2);
|
||||||
|
10
src/smapi.cc
10
src/smapi.cc
@@ -132,7 +132,8 @@ uint8_t smapi_bat_percentage(struct text_object *obj) {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_smapi_bat_temp(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_smapi_bat_temp(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int idx, val;
|
int idx, val;
|
||||||
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
||||||
val = smapi_bat_installed_internal(idx)
|
val = smapi_bat_installed_internal(idx)
|
||||||
@@ -144,7 +145,8 @@ void print_smapi_bat_temp(struct text_object *obj, char *p, unsigned int p_max_s
|
|||||||
NORM_ERR("argument to smapi_bat_temp must be an integer");
|
NORM_ERR("argument to smapi_bat_temp must be an integer");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_smapi_bat_power(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_smapi_bat_power(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
int idx, val;
|
int idx, val;
|
||||||
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
||||||
val = smapi_bat_installed_internal(idx)
|
val = smapi_bat_installed_internal(idx)
|
||||||
@@ -165,9 +167,7 @@ double smapi_bat_barval(struct text_object *obj) {
|
|||||||
int smapi_bat_installed(struct text_object *obj) {
|
int smapi_bat_installed(struct text_object *obj) {
|
||||||
int idx;
|
int idx;
|
||||||
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
||||||
if (!smapi_bat_installed_internal(idx)) {
|
if (!smapi_bat_installed_internal(idx)) { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
NORM_ERR("argument to if_smapi_bat_installed must be an integer");
|
NORM_ERR("argument to if_smapi_bat_installed must be an integer");
|
||||||
return 1;
|
return 1;
|
||||||
|
12
src/sony.cc
12
src/sony.cc
@@ -51,9 +51,7 @@ void get_sony_fanspeed(struct text_object *obj, char *p_client_buffer,
|
|||||||
|
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
if (!p_client_buffer || client_buffer_size <= 0) {
|
if (!p_client_buffer || client_buffer_size <= 0) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(fan, 127, "%s/fanspeed", SONY_LAPTOP_DIR);
|
snprintf(fan, 127, "%s/fanspeed", SONY_LAPTOP_DIR);
|
||||||
|
|
||||||
@@ -62,12 +60,8 @@ void get_sony_fanspeed(struct text_object *obj, char *p_client_buffer,
|
|||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
char line[256];
|
char line[256];
|
||||||
|
|
||||||
if (fgets(line, 255, fp) == nullptr) {
|
if (fgets(line, 255, fp) == nullptr) { break; }
|
||||||
break;
|
if (sscanf(line, "%u", &speed)) { break; }
|
||||||
}
|
|
||||||
if (sscanf(line, "%u", &speed)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(nullptr, NULL,
|
CRIT_ERR(nullptr, NULL,
|
||||||
|
@@ -65,13 +65,9 @@ static void tailstring(char *string, int endofstring, int wantedlines) {
|
|||||||
string[endofstring - 1] = 0;
|
string[endofstring - 1] = 0;
|
||||||
}
|
}
|
||||||
for (i = endofstring - 1; i >= 0 && linescounted < wantedlines; i--) {
|
for (i = endofstring - 1; i >= 0 && linescounted < wantedlines; i--) {
|
||||||
if (string[i] == '\n') {
|
if (string[i] == '\n') { linescounted++; }
|
||||||
linescounted++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i > 0) {
|
|
||||||
strfold(string, i + 2);
|
|
||||||
}
|
}
|
||||||
|
if (i > 0) { strfold(string, i + 2); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,9 +120,7 @@ static void print_tailhead(const char *type, struct text_object *obj, char *p,
|
|||||||
struct stat st {};
|
struct stat st {};
|
||||||
auto *ht = static_cast<struct headtail *>(obj->data.opaque);
|
auto *ht = static_cast<struct headtail *>(obj->data.opaque);
|
||||||
|
|
||||||
if (ht == nullptr) {
|
if (ht == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// empty the buffer and reset the counter if we used it the max number of
|
// empty the buffer and reset the counter if we used it the max number of
|
||||||
// times
|
// times
|
||||||
@@ -145,12 +139,8 @@ static void print_tailhead(const char *type, struct text_object *obj, char *p,
|
|||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
if (strcmp(type, "head") == 0) {
|
if (strcmp(type, "head") == 0) {
|
||||||
for (i = 0; linescounted < ht->wantedlines; i++) {
|
for (i = 0; linescounted < ht->wantedlines; i++) {
|
||||||
if (read(fd, p + i, 1) <= 0) {
|
if (read(fd, p + i, 1) <= 0) { break; }
|
||||||
break;
|
if (p[i] == '\n') { linescounted++; }
|
||||||
}
|
|
||||||
if (p[i] == '\n') {
|
|
||||||
linescounted++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p[i] = 0;
|
p[i] = 0;
|
||||||
} else if (strcmp(type, "tail") == 0) {
|
} else if (strcmp(type, "tail") == 0) {
|
||||||
@@ -175,7 +165,7 @@ static void print_tailhead(const char *type, struct text_object *obj, char *p,
|
|||||||
endofstring = strlen(p);
|
endofstring = strlen(p);
|
||||||
}
|
}
|
||||||
} else if (strcmp(type, "tail") == 0) {
|
} else if (strcmp(type, "tail") == 0) {
|
||||||
fseek(fp, - (long) p_max_size, SEEK_END);
|
fseek(fp, -(long)p_max_size, SEEK_END);
|
||||||
i = fread(p, 1, p_max_size - 1, fp);
|
i = fread(p, 1, p_max_size - 1, fp);
|
||||||
tailstring(p, i, ht->wantedlines);
|
tailstring(p, i, ht->wantedlines);
|
||||||
} else {
|
} else {
|
||||||
@@ -219,9 +209,7 @@ void print_lines(struct text_object *obj, char *p, unsigned int p_max_size) {
|
|||||||
lines = 0;
|
lines = 0;
|
||||||
while (fgets(buf, BUFSZ, fp) != nullptr) {
|
while (fgets(buf, BUFSZ, fp) != nullptr) {
|
||||||
for (j = 0; buf[j] != 0; j++) {
|
for (j = 0; buf[j] != 0; j++) {
|
||||||
if (buf[j] == '\n') {
|
if (buf[j] == '\n') { lines++; }
|
||||||
lines++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf(p, p_max_size, "%d", lines);
|
snprintf(p, p_max_size, "%d", lines);
|
||||||
|
@@ -17,10 +17,10 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#include "tcp-portmon.h"
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "libtcp-portmon.h"
|
#include "libtcp-portmon.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "tcp-portmon.h"
|
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
|
|
||||||
static tcp_port_monitor_collection_t *pmc = nullptr;
|
static tcp_port_monitor_collection_t *pmc = nullptr;
|
||||||
@@ -122,7 +122,8 @@ int tcp_portmon_init(struct text_object *obj, const char *arg) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tcp_portmon_action(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void tcp_portmon_action(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
struct tcp_port_monitor_data *pmd = (tcp_port_monitor_data *)obj->data.opaque;
|
struct tcp_port_monitor_data *pmd = (tcp_port_monitor_data *)obj->data.opaque;
|
||||||
tcp_port_monitor_t *p_monitor;
|
tcp_port_monitor_t *p_monitor;
|
||||||
|
|
||||||
|
@@ -41,9 +41,7 @@ static double fahrenheit_to_celsius(double n) { return ((n - 32) * 5 / 9); }
|
|||||||
static double celsius_to_fahrenheit(double n) { return ((n * 9 / 5) + 32); }
|
static double celsius_to_fahrenheit(double n) { return ((n * 9 / 5) + 32); }
|
||||||
|
|
||||||
static double convert_temp_output(double n, enum TEMP_UNIT input_unit) {
|
static double convert_temp_output(double n, enum TEMP_UNIT input_unit) {
|
||||||
if (input_unit == output_unit.get(*state)) {
|
if (input_unit == output_unit.get(*state)) { return n; }
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (output_unit.get(*state)) {
|
switch (output_unit.get(*state)) {
|
||||||
case TEMP_CELSIUS:
|
case TEMP_CELSIUS:
|
||||||
@@ -55,8 +53,8 @@ static double convert_temp_output(double n, enum TEMP_UNIT input_unit) {
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int temp_print(char *p, size_t p_max_size, double n,
|
int temp_print(char *p, size_t p_max_size, double n, enum TEMP_UNIT input_unit,
|
||||||
enum TEMP_UNIT input_unit, int to_int) {
|
int to_int) {
|
||||||
int i_out = 0;
|
int i_out = 0;
|
||||||
float f_out = 0.0;
|
float f_out = 0.0;
|
||||||
size_t plen = 0;
|
size_t plen = 0;
|
||||||
|
@@ -184,7 +184,10 @@ char *find_and_replace_templates(const char *inbuf) {
|
|||||||
if (*(p + 1) == '{') {
|
if (*(p + 1) == '{') {
|
||||||
p += 2;
|
p += 2;
|
||||||
templ = p;
|
templ = p;
|
||||||
while ((*p != 0) && (isspace((unsigned char)*p) == 0) && *p != '{' && *p != '}') { p++; }
|
while ((*p != 0) && (isspace((unsigned char)*p) == 0) && *p != '{' &&
|
||||||
|
*p != '}') {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
if (*p == '}') {
|
if (*p == '}') {
|
||||||
args = nullptr;
|
args = nullptr;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -44,7 +44,8 @@ void scan_tztime(struct text_object *, const char *);
|
|||||||
void print_time(struct text_object *, char *, unsigned int);
|
void print_time(struct text_object *, char *, unsigned int);
|
||||||
void print_utime(struct text_object *, char *, unsigned int);
|
void print_utime(struct text_object *, char *, unsigned int);
|
||||||
void print_tztime(struct text_object *, char *, unsigned int);
|
void print_tztime(struct text_object *, char *, unsigned int);
|
||||||
void print_format_time(struct text_object *obj, char *p, unsigned int p_max_size);
|
void print_format_time(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size);
|
||||||
|
|
||||||
/* free object data */
|
/* free object data */
|
||||||
void free_time(struct text_object *);
|
void free_time(struct text_object *);
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "weather.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
@@ -34,9 +35,8 @@
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "temphelper.h"
|
#include "temphelper.h"
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
#include "weather.h"
|
|
||||||
|
|
||||||
void print_weather(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_weather(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||||
(void) obj;
|
(void)obj;
|
||||||
strncpy(p ,"TODO...", p_max_size);
|
strncpy(p, "TODO...", p_max_size);
|
||||||
}
|
}
|
||||||
|
16
src/xmms2.cc
16
src/xmms2.cc
@@ -289,9 +289,7 @@ int update_xmms2(void) {
|
|||||||
|
|
||||||
/* initialize connection */
|
/* initialize connection */
|
||||||
if (current_info->xmms2.conn_state == CONN_INIT) {
|
if (current_info->xmms2.conn_state == CONN_INIT) {
|
||||||
if (xmms2_conn == nullptr) {
|
if (xmms2_conn == nullptr) { xmms2_conn = xmmsc_init(PACKAGE_NAME); }
|
||||||
xmms2_conn = xmmsc_init(PACKAGE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* did init fail? */
|
/* did init fail? */
|
||||||
if (xmms2_conn == nullptr) {
|
if (xmms2_conn == nullptr) {
|
||||||
@@ -351,20 +349,23 @@ int update_xmms2(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_xmms2_tracknr(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_xmms2_tracknr(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
if (info.xmms2.tracknr != -1) {
|
if (info.xmms2.tracknr != -1) {
|
||||||
snprintf(p, p_max_size, "%i", info.xmms2.tracknr);
|
snprintf(p, p_max_size, "%i", info.xmms2.tracknr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_xmms2_elapsed(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_xmms2_elapsed(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.elapsed / 60000,
|
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.elapsed / 60000,
|
||||||
(info.xmms2.elapsed / 1000) % 60);
|
(info.xmms2.elapsed / 1000) % 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_xmms2_duration(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_xmms2_duration(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.duration / 60000,
|
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.duration / 60000,
|
||||||
(info.xmms2.duration / 1000) % 60);
|
(info.xmms2.duration / 1000) % 60);
|
||||||
@@ -376,7 +377,8 @@ double xmms2_barval(struct text_object *obj) {
|
|||||||
return info.xmms2.progress;
|
return info.xmms2.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_xmms2_smart(struct text_object *obj, char *p, unsigned int p_max_size) {
|
void print_xmms2_smart(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
(void)obj;
|
(void)obj;
|
||||||
int artist_len = strlen(info.xmms2.artist);
|
int artist_len = strlen(info.xmms2.artist);
|
||||||
int title_len = strlen(info.xmms2.title);
|
int title_len = strlen(info.xmms2.title);
|
||||||
|
12337
tests/catch2/catch.hpp
12337
tests/catch2/catch.hpp
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user