Merge pull request #447 from triveria/refactor-canplayer

Format code of canplayer
pull/455/head
Marc Kleine-Budde 2023-09-05 11:51:56 +02:00 committed by GitHub
commit 2f9958c699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 193 additions and 84 deletions

118
.clang-format 100644
View File

@ -0,0 +1,118 @@
# SPDX-License-Identifier: GPL-2.0
#
# clang-format configuration file. Intended for clang-format >= 11.
#
# For more information, see:
#
# Documentation/process/clang-format.rst
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 200
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
IncludeBlocks: Preserve
IncludeCategories:
- Regex: ".*"
Priority: 1
IncludeIsMainRegex: "(Test)?$"
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 8
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
# Taken from git's rules
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 8
UseTab: Always

View File

@ -81,18 +81,22 @@ void print_usage(char *prg)
fprintf(stderr, "\nUsage: %s <options> [interface assignment]*\n\n", prg);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -I <infile> (default stdin)\n");
fprintf(stderr, " -l <num> "
fprintf(stderr,
" -l <num> "
"(process input file <num> times)\n"
" "
"(Use 'i' for infinite loop - default: %d)\n", DEFAULT_LOOPS);
"(Use 'i' for infinite loop - default: %d)\n",
DEFAULT_LOOPS);
fprintf(stderr, " -t (ignore timestamps: "
"send frames immediately)\n");
fprintf(stderr, " -i (interactive - wait "
"for ENTER key to process next frame)\n");
fprintf(stderr, " -n <count> (terminate after "
"processing <count> CAN frames)\n");
fprintf(stderr, " -g <ms> (gap in milli "
"seconds - default: %d ms)\n", DEFAULT_GAP);
fprintf(stderr,
" -g <ms> (gap in milli "
"seconds - default: %d ms)\n",
DEFAULT_GAP);
fprintf(stderr, " -s <s> (skip gaps in "
"timestamps > 's' seconds)\n");
fprintf(stderr, " -x (disable local "
@ -125,16 +129,14 @@ static inline int timeval_compare(struct timeval *lhs, struct timeval *rhs)
return lhs->tv_usec - rhs->tv_usec;
}
static inline void create_diff_tv(struct timeval *today, struct timeval *diff,
struct timeval *log) {
static inline void create_diff_tv(struct timeval *today, struct timeval *diff, struct timeval *log)
{
/* create diff_tv so that log_tv + diff_tv = today_tv */
diff->tv_sec = today->tv_sec - log->tv_sec;
diff->tv_usec = today->tv_usec - log->tv_usec;
}
static inline int frames_to_send(struct timeval *today, struct timeval *diff,
struct timeval *log)
static inline int frames_to_send(struct timeval *today, struct timeval *diff, struct timeval *log)
{
/* return value <0 when log + diff < today */
@ -156,8 +158,8 @@ static inline int frames_to_send(struct timeval *today, struct timeval *diff,
return timeval_compare(&cmp, today);
}
int get_txidx(char *logif_name) {
int get_txidx(char *logif_name)
{
int i;
for (i = 0; i < CHANNELS; i++) {
@ -173,8 +175,8 @@ int get_txidx(char *logif_name) {
return asgn[i].txifidx; /* return interface index */
}
char *get_txname(char *logif_name) {
char *get_txname(char *logif_name)
{
int i;
for (i = 0; i < CHANNELS; i++) {
@ -190,9 +192,8 @@ char *get_txname(char *logif_name) {
return asgn[i].txif; /* return interface name */
}
int add_assignment(char *mode, int socket, char *txname, char *rxname,
int verbose) {
int add_assignment(char *mode, int socket, char *txname, char *rxname, int verbose)
{
struct ifreq ifr;
int i;
@ -231,8 +232,7 @@ int add_assignment(char *mode, int socket, char *txname, char *rxname,
asgn[i].txifidx = STDOUTIDX;
if (verbose > 1) /* use -v -v to see this */
printf("added %s assignment: log-if=%s write-if=%s write-if-idx=%d\n",
mode, asgn[i].rxif, asgn[i].txif, asgn[i].txifidx);
printf("added %s assignment: log-if=%s write-if=%s write-if-idx=%d\n", mode, asgn[i].rxif, asgn[i].txif, asgn[i].txifidx);
return 0;
}
@ -273,8 +273,7 @@ int main(int argc, char **argv)
case 'l':
if (optarg[0] == 'i')
infinite_loops = 1;
else
if (!(loops = atoi(optarg))) {
else if (!(loops = atoi(optarg))) {
fprintf(stderr, "Invalid argument for option -l !\n");
return 1;
}
@ -365,8 +364,7 @@ int main(int argc, char **argv)
if (loopback_disable) {
int loopback = 0;
setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
&loopback, sizeof(loopback));
setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback));
}
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
@ -399,7 +397,6 @@ int main(int argc, char **argv)
}
while (infinite_loops || loops--) {
if (infile != stdin)
rewind(infile); /* for each loop */
@ -419,8 +416,7 @@ int main(int argc, char **argv)
eof = 0;
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
device, ascframe) != 4) {
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, device, ascframe) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;
}
@ -442,10 +438,7 @@ int main(int argc, char **argv)
}
while (!eof) {
while ((!use_timestamps) ||
(frames_to_send(&today_tv, &diff_tv, &log_tv) < 0)) {
while ((!use_timestamps) || (frames_to_send(&today_tv, &diff_tv, &log_tv) < 0)) {
/* wait for keypress to process next frame */
if (interactive)
getchar();
@ -514,8 +507,7 @@ int main(int argc, char **argv)
break;
}
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
device, ascframe) != 4) {
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, device, ascframe) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;
}
@ -534,8 +526,7 @@ int main(int argc, char **argv)
/* test for logfile timestamps jumping backwards OR */
/* if the user likes to skip long gaps in the timestamps */
if ((last_log_tv.tv_sec > log_tv.tv_sec) ||
(skipgap && labs(last_log_tv.tv_sec - log_tv.tv_sec) > (long)skipgap))
if ((last_log_tv.tv_sec > log_tv.tv_sec) || (skipgap && labs(last_log_tv.tv_sec - log_tv.tv_sec) > (long)skipgap))
create_diff_tv(&today_tv, &diff_tv, &log_tv);
last_log_tv = log_tv;