From 35b852cfeb3d405fbfe22e71cf48b0bc8ab4b01b Mon Sep 17 00:00:00 2001 From: Jonas Stein Date: Wed, 20 Apr 2022 01:00:40 +0200 Subject: [PATCH] add .clang-cormat Add .clang-cormat config file to src folder for unified formatting. --- src/.clang-format | 118 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 26 +++++----- 2 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 src/.clang-format diff --git a/src/.clang-format b/src/.clang-format new file mode 100644 index 0000000..39227cf --- /dev/null +++ b/src/.clang-format @@ -0,0 +1,118 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... + diff --git a/src/main.cpp b/src/main.cpp index 0250e71..f356e6b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -205,8 +205,8 @@ int main(int argc, char **argv) { errorOut("Specify file to save into with the -k argument."); } - std::string const newkey = randomKey(keyLength); - std::ofstream kf { }; + std::string const newkey = randomKey(keyLength); + std::ofstream kf{}; umask(077); // make sure that no one else can read the new key file kf.open(keyFile.c_str(), std::ios::trunc); if (!kf.is_open()) { @@ -263,7 +263,7 @@ int main(int argc, char **argv) { exit(EXIT_SUCCESS); } - Keyinfo ki { }; + Keyinfo ki{}; if (drvOptions.cryptMode != CRYPTMODE_OFF) { if (keyFile == "") { std::string p1 = "01"; @@ -345,7 +345,7 @@ int main(int argc, char **argv) { logFile << timestamp() << ": " << msg.str(); } } else { - std::stringstream msg { }; + std::stringstream msg{}; msg << "Encryption turned off for device '" << tapeDrive << "'."; msg << " Key Instance: " << std::dec << BSLONG(opt->des.keyInstance) @@ -382,8 +382,8 @@ void showUsage() { std::cout << "Type 'man stenc' for more information." << std::endl; } void inquiryDrive(std::string tapeDevice) { - //todo: std::cout should not be used outside main() - SCSI_PAGE_INQ *const iresult = SCSIGetInquiry(tapeDevice); + // todo: std::cout should not be used outside main() + SCSI_PAGE_INQ *const iresult = SCSIGetInquiry(tapeDevice); std::cout << std::left << std::setw(25) << "Device Mfg:"; std::cout.write((const char *)iresult->vender, 8); std::cout << std::endl; @@ -478,7 +478,7 @@ void showDriveStatus(std::string tapeDrive, bool detail) { } if (opt->kads.size() > 0) { for (unsigned int i = 0; i < opt->kads.size(); i++) { - std::stringstream lbl { }; + std::stringstream lbl{}; lbl << "Drive Key Desc.("; switch (opt->kads[i].type) { case KAD_TYPE_UKAD: @@ -580,26 +580,26 @@ void showVolumeStatus(std::string tapeDrive) { } void echo(bool on = true) { - struct termios settings { }; + struct termios settings {}; tcgetattr(STDIN_FILENO, &settings); settings.c_lflag = on ? (settings.c_lflag | ECHO) : (settings.c_lflag & ~(ECHO)); tcsetattr(STDIN_FILENO, TCSANOW, &settings); } std::string timestamp() { - time_t tm { }; + time_t tm{}; time(&tm); char buffer[80]; int len = strftime((char *)&buffer, 80, "%Y-%m-%d", localtime(&tm)); std::string val; val.assign(buffer, len); - return(val); + return (val); } std::string randomKey(int length) { unsigned char rnd; - std::stringstream retval { }; - std::ifstream random { }; + std::stringstream retval{}; + std::ifstream random{}; // Under Linux and AIX /dev/random provides much more cryptographically secure // random output than rand() @@ -628,5 +628,5 @@ std::string randomKey(int length) { } } retval << std::endl; - return(retval.str()); + return (retval.str()); }