summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format246
-rw-r--r--status.c120
2 files changed, 309 insertions, 57 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..bd2d85f
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,246 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignArrayOfStructures: None
+AlignConsecutiveAssignments:
+ Enabled: true
+ AcrossEmptyLines: true
+ AcrossComments: false
+ AlignCompound: false
+ AlignFunctionPointers: false
+ PadOperators: true
+AlignConsecutiveBitFields:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCompound: false
+ AlignFunctionPointers: false
+ PadOperators: false
+AlignConsecutiveDeclarations:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCompound: false
+ AlignFunctionPointers: false
+ PadOperators: false
+AlignConsecutiveMacros:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCompound: false
+ AlignFunctionPointers: false
+ PadOperators: false
+AlignConsecutiveShortCaseStatements:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCaseColons: false
+AlignEscapedNewlines: Right
+AlignOperands: Align
+AlignTrailingComments:
+ Kind: Always
+ OverEmptyLines: 0
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowBreakBeforeNoexceptSpecifier: Never
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortCompoundRequirementOnASingleLine: true
+AllowShortEnumsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLambdasOnASingleLine: All
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: All
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+AttributeMacros:
+ - __capability
+BinPackArguments: true
+BinPackParameters: true
+BitFieldColonSpacing: Both
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: false
+ AfterControlStatement: Never
+ AfterEnum: false
+ AfterExternBlock: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ BeforeCatch: false
+ BeforeElse: false
+ BeforeLambdaBody: false
+ BeforeWhile: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakAdjacentStringLiterals: true
+BreakAfterAttributes: Leave
+BreakAfterJavaFieldAnnotations: false
+BreakArrays: true
+BreakBeforeBinaryOperators: None
+BreakBeforeConceptDeclarations: Always
+BreakBeforeBraces: Attach
+BreakBeforeInlineASMColon: OnlyMultiline
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeColon
+BreakInheritanceList: BeforeColon
+BreakStringLiterals: true
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 2
+ContinuationIndentWidth: 2
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IfMacros:
+ - KJ_IF_MAYBE
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ SortPriority: 0
+ CaseSensitive: false
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ SortPriority: 0
+ CaseSensitive: false
+ - Regex: '.*'
+ Priority: 1
+ SortPriority: 0
+ CaseSensitive: false
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseBlocks: false
+IndentCaseLabels: false
+IndentExternBlock: AfterExternBlock
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentRequiresClause: true
+IndentWidth: 2
+IndentWrappedFunctionNames: false
+InsertBraces: false
+InsertNewlineAtEOF: false
+InsertTrailingCommas: None
+IntegerLiteralSeparator:
+ Binary: 0
+ BinaryMinDigits: 0
+ Decimal: 0
+ DecimalMinDigits: 0
+ Hex: 0
+ HexMinDigits: 0
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+KeepEmptyLinesAtEOF: false
+LambdaBodyIndentation: Signature
+LineEnding: DeriveLF
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PackConstructorInitializers: BinPack
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakScopeResolution: 500
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyIndentedWhitespace: 0
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+PPIndentWidth: -1
+QualifierAlignment: Leave
+ReferenceAlignment: Pointer
+ReflowComments: true
+RemoveBracesLLVM: false
+RemoveParentheses: Leave
+RemoveSemicolon: false
+RequiresClausePosition: OwnLine
+RequiresExpressionIndentation: OuterScope
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SkipMacroDefinitionBody: false
+SortIncludes: CaseSensitive
+SortJavaStaticImport: Before
+SortUsingDeclarations: LexicographicNumeric
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeJsonColon: false
+SpaceBeforeParens: ControlStatements
+SpaceBeforeParensOptions:
+ AfterControlStatements: true
+ AfterForeachMacros: true
+ AfterFunctionDefinitionName: false
+ AfterFunctionDeclarationName: false
+ AfterIfMacros: true
+ AfterOverloadedOperator: false
+ AfterPlacementOperator: true
+ AfterRequiresInClause: false
+ AfterRequiresInExpression: false
+ BeforeNonEmptyParentheses: false
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceBeforeSquareBrackets: false
+SpaceInEmptyBlock: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: Never
+SpacesInContainerLiterals: true
+SpacesInLineCommentPrefix:
+ Minimum: 1
+ Maximum: -1
+SpacesInParens: Never
+SpacesInParensOptions:
+ InCStyleCasts: false
+ InConditionalStatements: false
+ InEmptyParentheses: false
+ Other: false
+SpacesInSquareBrackets: false
+Standard: Latest
+StatementAttributeLikeMacros:
+ - Q_EMIT
+StatementMacros:
+ - Q_UNUSED
+ - QT_REQUIRE_VERSION
+TabWidth: 8
+UseTab: Never
+VerilogBreakBetweenInstancePorts: true
+WhitespaceSensitiveMacros:
+ - BOOST_PP_STRINGIZE
+ - CF_SWIFT_NAME
+ - NS_SWIFT_NAME
+ - PP_STRINGIZE
+ - STRINGIZE
+...
+
diff --git a/status.c b/status.c
index 46fd24d..90ec3d3 100644
--- a/status.c
+++ b/status.c
@@ -1,26 +1,25 @@
#include <errno.h>
#include <ifaddrs.h>
-#include <linux/wireless.h>
#include <linux/net.h>
+#include <linux/wireless.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define __USE_MISC
-#include <sys/time.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <netinet/in.h>
#include <sys/ioctl.h>
-#include <sys/types.h>
#include <sys/socket.h>
-#include <unistd.h>
+#include <sys/time.h>
+#include <sys/types.h>
#include <time.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#include <unistd.h>
#define ELEMENT_SEPERATOR " "
-
#define STATUS_STRBUF_SZ 512
#define ELEMENT_STRBUF_SZ 64
@@ -33,8 +32,8 @@ struct element {
char buf[ELEMENT_STRBUF_SZ];
};
-
-void date(char* buf) {
+void
+date(char* buf) {
time_t now = time(NULL);
struct tm tm;
tm = *localtime(&now);
@@ -42,7 +41,6 @@ void date(char* buf) {
strftime(buf, ELEMENT_STRBUF_SZ, "%Y-%m-%d %H:%M", &tm);
}
-
enum battery_status_charge {
bat_unknown,
bat_not_charging,
@@ -69,7 +67,8 @@ char* battery_level_icon[] = {
"", /* "\uf578" */
};
-struct battery_status get_battery_status(const char* buf) {
+struct battery_status
+get_battery_status(const char* buf) {
const char path_prefix[] = "/sys/class/power_supply/";
char charge_path[128];
@@ -78,7 +77,7 @@ struct battery_status get_battery_status(const char* buf) {
char charge_str[512];
char capacity_str[512];
- int charge = 0;
+ int charge = 0;
int capacity = 0;
FILE* bat_charge;
@@ -95,7 +94,7 @@ struct battery_status get_battery_status(const char* buf) {
strcat(capacity_path, buf);
strcat(capacity_path, "/energy_full");
- bat_charge = fopen(charge_path, "r");
+ bat_charge = fopen(charge_path, "r");
bat_capacity = fopen(capacity_path, "r");
if (!bat_charge) {
@@ -113,79 +112,88 @@ struct battery_status get_battery_status(const char* buf) {
fclose(bat_charge);
fclose(bat_capacity);
- charge = atoi(charge_str);
+ charge = atoi(charge_str);
capacity = atoi(capacity_str);
return (struct battery_status){bat_unknown, (float)charge / capacity};
}
-void get_battery1_status(char* buf) {
+void
+get_battery1_status(char* buf) {
struct battery_status s = get_battery_status("BAT1");
- int batlvl = (int)(s.charge*100.f) / 10;
- char* batlvl_icon = battery_level_icon[batlvl];
+ int batlvl = (int)(s.charge * 100.f) / 10;
+ char* batlvl_icon = battery_level_icon[batlvl];
snprintf(buf, ELEMENT_STRBUF_SZ, "%s %.1f%%", batlvl_icon, 100.f * s.charge);
}
-void get_battery0_status(char* buf) {
+void
+get_battery0_status(char* buf) {
struct battery_status s = get_battery_status("BAT0");
- int batlvl = (int)(s.charge*100.f) / 10;
- char* batlvl_icon = battery_level_icon[batlvl];
+ int batlvl = (int)(s.charge * 100.f) / 10;
+ char* batlvl_icon = battery_level_icon[batlvl];
snprintf(buf, ELEMENT_STRBUF_SZ, "%s %.1f%%", batlvl_icon, 100.f * s.charge);
}
/* todo, remake this to enumerate all possible batteries */
-void get_all_bat_status(char* buf) {
+void
+get_all_bat_status(char* buf) {
struct battery_status s = get_battery_status("BAT0");
struct battery_status t = get_battery_status("BAT1");
- s.charge = (s.charge + t.charge) / 2.f;
+ s.charge = (s.charge + t.charge) / 2.f;
- int batlvl = (int)(s.charge*100.f) / 10;
- char* batlvl_icon = battery_level_icon[batlvl];
+ int batlvl = (int)(s.charge * 100.f) / 10;
+ char* batlvl_icon = battery_level_icon[batlvl];
/*snprintf(buf, ELEMENT_STRBUF_SZ, "%.1f%%", 100.f * s.charge);*/
snprintf(buf, ELEMENT_STRBUF_SZ, "%s %.1f%%", batlvl_icon, 100.f * s.charge);
}
-
-void get_net_link_status(char* buf) {
- struct ifaddrs *if_addr;
+void
+get_net_link_status(char* buf) {
+ struct ifaddrs* if_addr;
size_t n = 0;
getifaddrs(&if_addr);
- for (struct ifaddrs *ifa = if_addr; ifa != NULL; ifa = ifa->ifa_next) {
+ for (struct ifaddrs* ifa = if_addr; ifa != NULL; ifa = ifa->ifa_next) {
/* Ignore loopback interface flag */
- if (ifa->ifa_flags & IFF_LOOPBACK) continue;
+ if (ifa->ifa_flags & IFF_LOOPBACK)
+ continue;
/* Ignore interfaces without an address */
- if (ifa->ifa_addr == NULL) continue;
+ if (ifa->ifa_addr == NULL)
+ continue;
/* Ignore everythings not an IPv4 link */
/* (AF_PACKET might be usefull if you want to display tx) */
- if (ifa->ifa_addr->sa_family != AF_INET) continue;
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ continue;
if (ifa->ifa_flags & IFF_UP) {
size_t l = strlen(ifa->ifa_name);
struct iwreq wreq;
int sock;
- const size_t ipv6_charlen = 8*4+7;
+ const size_t ipv6_charlen = 8 * 4 + 7;
char address[ipv6_charlen + 1]; // in case of ipv6, plus null-byte
- char id[IW_ESSID_MAX_SIZE+1];
+ char id[IW_ESSID_MAX_SIZE + 1];
/* Get the IP address */
memset(address, 0, ipv6_charlen + 1);
- /* Use sa_family instead of hardcoding AF_INET, just in case we get ip6'ed */
+ /* Use sa_family instead of hardcoding AF_INET, just in case
+ * we get ip6'ed */
/* Does inet_ntop add a null-byte? */
- inet_ntop(ifa->ifa_addr->sa_family, (void*)&((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, address, ipv6_charlen);
+ inet_ntop(ifa->ifa_addr->sa_family,
+ (void*)&((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, address,
+ ipv6_charlen);
/* Get the SSID */
- memset(id, 0, IW_ESSID_MAX_SIZE+1);
+ memset(id, 0, IW_ESSID_MAX_SIZE + 1);
memset(&wreq, 0, sizeof(struct iwreq));
sock = socket(AF_INET, SOCK_DGRAM, 0);
setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, ifa->ifa_name, l);
@@ -193,17 +201,14 @@ void get_net_link_status(char* buf) {
strncpy(wreq.ifr_name, ifa->ifa_name, l);
wreq.u.essid.pointer = id;
- wreq.u.essid.length = IW_ESSID_MAX_SIZE;
+ wreq.u.essid.length = IW_ESSID_MAX_SIZE;
ioctl(sock, SIOCGIWESSID, &wreq);
-
-
-
strncpy(buf + n, ifa->ifa_name, l);
size_t ssid_len = strlen(id);
if (ssid_len > 0) {
- buf[n + l] = ' ';
+ buf[n + l] = ' ';
buf[n + l + 1] = '(';
strncpy(buf + n + l + 2, id, ssid_len);
l += ssid_len;
@@ -214,7 +219,6 @@ void get_net_link_status(char* buf) {
strcat(buf + n, address);
n += strlen(address);
-
strcat(buf + n, " ");
n += 2;
@@ -224,18 +228,18 @@ void get_net_link_status(char* buf) {
static struct element statusbar[] = {
- {.f = get_net_link_status, .fire_interval = {5,0}, .fire_previous = {0}, .buf = {0} },
- {.f = get_all_bat_status, .fire_interval = {60,0}, .fire_previous = {0}, .buf = {0} },
- {.f = date, .fire_interval = {2,500000}, .fire_previous = {0}, .buf = {0} },
+ {.f = get_net_link_status, .fire_interval = {5, 0}, .fire_previous = {0}, .buf = {0}},
+ {.f = get_all_bat_status, .fire_interval = {60, 0}, .fire_previous = {0}, .buf = {0}},
+ {.f = date, .fire_interval = {2, 500000}, .fire_previous = {0}, .buf = {0}},
};
-int main(void) {
- const int num_elems = sizeof(statusbar)/sizeof(statusbar[0]);
+int
+main(void) {
+ const int num_elems = sizeof(statusbar) / sizeof(statusbar[0]);
struct timeval now;
const struct timeval one_minute = {60, 0};
-
while (true) {
gettimeofday(&now, NULL);
unsigned i;
@@ -246,11 +250,12 @@ int main(void) {
for (i = 0; i < num_elems; i++) {
struct timeval next_fire;
- timeradd(&statusbar[i].fire_previous, &statusbar[i].fire_interval, &next_fire);
+ timeradd(&statusbar[i].fire_previous, &statusbar[i].fire_interval,
+ &next_fire);
- if (timercmp(&next_fire, &now, >)) {
+ if (timercmp(&next_fire, &now, >)) {
/* Check if this is the next to-be-updated element */
- if (timercmp(&next_fire, &next_update, <)) {
+ if (timercmp(&next_fire, &next_update, <)) {
next_update = next_fire;
}
continue;
@@ -262,8 +267,9 @@ int main(void) {
statusbar[i].fire_previous = now;
/* Check if this element needs to be refreshed next, again */
- timeradd(&statusbar[i].fire_previous, &statusbar[i].fire_interval, &next_fire);
- if (timercmp(&next_fire, &next_update, <)) {
+ timeradd(&statusbar[i].fire_previous, &statusbar[i].fire_interval,
+ &next_fire);
+ if (timercmp(&next_fire, &next_update, <)) {
next_update = next_fire;
}
@@ -272,7 +278,6 @@ int main(void) {
* statusbar[i].fire_interval.tv_usec,
* (char*)statusbar[i].buf);
*/
-
}
char buf[STATUS_STRBUF_SZ];
@@ -280,7 +285,8 @@ int main(void) {
for (i = 0; i < num_elems; i++) {
strcat(buf, statusbar[i].buf);
- if (i != num_elems - 1) strcat(buf, ELEMENT_SEPERATOR);
+ if (i != num_elems - 1)
+ strcat(buf, ELEMENT_SEPERATOR);
}
/* strcat(buf, "\0"); */
@@ -289,7 +295,7 @@ int main(void) {
fflush(stdout);
timersub(&next_update, &now, &next_update);
- usleep(next_update.tv_sec*1000*1000+next_update.tv_usec);
+ usleep(next_update.tv_sec * 1000 * 1000 + next_update.tv_usec);
}
return 0;