]> granicus.if.org Git - vnstat/commitdiff
clang-format files
authorTeemu Toivola <git@humdi.net>
Sat, 13 Apr 2019 23:44:39 +0000 (02:44 +0300)
committerTeemu Toivola <git@humdi.net>
Sat, 13 Apr 2019 23:44:39 +0000 (02:44 +0300)
33 files changed:
.clang-format [new file with mode: 0644]
.gitignore
src/cfg.c
src/cfgoutput.c
src/common.c
src/common.h
src/daemon.c
src/datacache.c
src/dbaccess.c
src/dbaccess.h
src/dbjson.c
src/dbshow.c
src/dbsql.c
src/dbxml.c
src/fs.c
src/ibw.c
src/ifinfo.c
src/image.c
src/image.h
src/misc.c
src/traffic.c
src/vnstat.c
src/vnstatd.c
src/vnstati.c
tests/common_tests.c
tests/config_tests.c
tests/daemon_tests.c
tests/database_tests.c
tests/datacache_tests.c
tests/dbsql_tests.c
tests/image_tests.c
tests/misc_tests.c
tests/vnstat_tests.c

diff --git a/.clang-format b/.clang-format
new file mode 100644 (file)
index 0000000..b89b9d0
--- /dev/null
@@ -0,0 +1,113 @@
+---
+Language:        Cpp
+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: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass:      true
+  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: Linux
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     0
+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: true
+IndentPPDirectives: None
+IndentWidth:     4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+RawStringFormats:
+  - Delimiter:       pb
+    Language:        TextProto
+    BasedOnStyle:    google
+ReflowComments:  true
+SortIncludes:    false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Auto
+TabWidth:        4
+UseTab:          Always
+...
index 4eb26b551b57a503f05fc95f1e56fedbdd2b393b..43fcce604bb6afe047ff49f2cf8fc15d103cf1cb 100644 (file)
@@ -28,3 +28,4 @@ INSTALL
 INSTALL_BSD
 UPGRADE
 UNINSTALL
+.vscode
index 6e9bfa8c9d46d7c7ff30b88fd40da5112e035dcd..92ab27907d79bb380f2d986ec7e5d358a9eb771d 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -10,78 +10,77 @@ int loadcfg(const char *cfgfile)
        char value[512], cfgline[512];
 
        struct cfgsetting cset[] =
-       {       /* cfg string, char var name, int var name, char len, fill status */
-               { "Interface", cfg.iface, 0, 32, 0 },
-               { "DatabaseDir", cfg.dbdir, 0, 512, 0 },
-               { "Locale", cfg.locale, 0, 32, 0 },
-               { "MonthRotate", 0, &cfg.monthrotate, 0, 0 },
-               { "MonthRotateAffectsYears", 0, &cfg.monthrotateyears, 0, 0 },
-               { "DayFormat", cfg.dformat, 0, 64, 0 },
-               { "MonthFormat", cfg.mformat, 0, 64, 0 },
-               { "TopFormat", cfg.tformat, 0, 64, 0 },
-               { "RXCharacter", cfg.rxchar, 0, 2, 0 },
-               { "TXCharacter", cfg.txchar, 0, 2, 0 },
-               { "RXHourCharacter", cfg.rxhourchar, 0, 2, 0 },
-               { "TXHourCharacter", cfg.txhourchar, 0, 2, 0 },
-               { "UnitMode", 0, &cfg.unitmode, 0, 0 },
-               { "RateUnitMode", 0, &cfg.rateunitmode, 0, 0 },
-               { "OutputStyle", 0, &cfg.ostyle, 0, 0 },
-               { "RateUnit", 0, &cfg.rateunit, 0, 0 },
-               { "DefaultDecimals", 0, &cfg.defaultdecimals, 0, 0 },
-               { "HourlyDecimals", 0, &cfg.hourlydecimals, 0, 0 },
-               { "HourlySectionStyle", 0, &cfg.hourlystyle, 0, 0 },
-               { "BandwidthDetection", 0, &cfg.bwdetection, 0, 0 },
-               { "MaxBandwidth", 0, &cfg.maxbw, 0, 0 },
-               { "Sampletime", 0, &cfg.sampletime, 0, 0 },
-               { "QueryMode", 0, &cfg.qmode, 0, 0 },
-               { "CheckDiskSpace", 0, &cfg.spacecheck, 0, 0 },
-               { "BootVariation", 0, &cfg.bvar, 0, 0 },
-               { "TrafficlessEntries", 0, &cfg.trafficlessentries, 0, 0 },
-               { "List5Mins", 0, &cfg.listfivemins, 0, 0 },
-               { "ListHours", 0, &cfg.listhours, 0, 0 },
-               { "ListDays", 0, &cfg.listdays, 0, 0 },
-               { "ListMonths", 0, &cfg.listmonths, 0, 0 },
-               { "ListYears", 0, &cfg.listyears, 0, 0 },
-               { "ListTop", 0, &cfg.listtop, 0, 0 },
-               { "5MinuteHours", 0, &cfg.fiveminutehours, 0, 0 },
-               { "HourlyDays", 0, &cfg.hourlydays, 0, 0 },
-               { "DailyDays", 0, &cfg.dailydays, 0, 0 },
-               { "MonthlyMonths", 0, &cfg.monthlymonths, 0, 0 },
-               { "YearlyYears", 0, &cfg.yearlyyears, 0, 0 },
-               { "TopDayEntries", 0, &cfg.topdayentries, 0, 0 },
-               { "DaemonUser", cfg.daemonuser, 0, 33, 0 },
-               { "DaemonGroup", cfg.daemongroup, 0, 33, 0 },
-               { "TimeSyncWait", 0, &cfg.timesyncwait, 0, 0 },
-               { "UpdateInterval", 0, &cfg.updateinterval, 0, 0 },
-               { "PollInterval", 0, &cfg.pollinterval, 0, 0 },
-               { "SaveInterval", 0, &cfg.saveinterval, 0, 0 },
-               { "OfflineSaveInterval", 0, &cfg.offsaveinterval, 0, 0 },
-               { "BandwidthDetectionInterval", 0, &cfg.bwdetectioninterval, 0, 0 },
-               { "SaveOnStatusChange", 0, &cfg.savestatus, 0, 0 },
-               { "UseLogging", 0, &cfg.uselogging, 0, 0 },
-               { "CreateDirs", 0, &cfg.createdirs, 0, 0 },
-               { "UpdateFileOwner", 0, &cfg.updatefileowner, 0, 0 },
-               { "LogFile", cfg.logfile, 0, 512, 0 },
-               { "PidFile", cfg.pidfile, 0, 512, 0 },
-               { "64bitInterfaceCounters", 0, &cfg.is64bit, 0, 0 },
-               { "HeaderFormat", cfg.hformat, 0, 64, 0 },
-               { "HourlyRate", 0, &cfg.hourlyrate, 0, 0 },
-               { "SummaryRate", 0, &cfg.summaryrate, 0, 0 },
-               { "TransparentBg", 0, &cfg.transbg, 0, 0 },
-               { "CBackground", cfg.cbg, 0, 8, 0 },
-               { "CEdge", cfg.cedge, 0, 8, 0 },
-               { "CHeader", cfg.cheader, 0, 8, 0 },
-               { "CHeaderTitle", cfg.cheadertitle, 0, 8, 0 },
-               { "CHeaderDate", cfg.cheaderdate, 0, 8, 0 },
-               { "CText", cfg.ctext, 0, 8, 0 },
-               { "CLine", cfg.cline, 0, 8, 0 },
-               { "CLineL", cfg.clinel, 0, 8, 0 },
-               { "CRx", cfg.crx, 0, 8, 0 },
-               { "CRxD", cfg.crxd, 0, 8, 0 },
-               { "CTx", cfg.ctx, 0, 8, 0 },
-               { "CTxD", cfg.ctxd, 0, 8, 0 },
-               { 0, 0, 0, 0, 0 }
-       };
+               {/* cfg string, char var name, int var name, char len, fill status */
+                {"Interface", cfg.iface, 0, 32, 0},
+                {"DatabaseDir", cfg.dbdir, 0, 512, 0},
+                {"Locale", cfg.locale, 0, 32, 0},
+                {"MonthRotate", 0, &cfg.monthrotate, 0, 0},
+                {"MonthRotateAffectsYears", 0, &cfg.monthrotateyears, 0, 0},
+                {"DayFormat", cfg.dformat, 0, 64, 0},
+                {"MonthFormat", cfg.mformat, 0, 64, 0},
+                {"TopFormat", cfg.tformat, 0, 64, 0},
+                {"RXCharacter", cfg.rxchar, 0, 2, 0},
+                {"TXCharacter", cfg.txchar, 0, 2, 0},
+                {"RXHourCharacter", cfg.rxhourchar, 0, 2, 0},
+                {"TXHourCharacter", cfg.txhourchar, 0, 2, 0},
+                {"UnitMode", 0, &cfg.unitmode, 0, 0},
+                {"RateUnitMode", 0, &cfg.rateunitmode, 0, 0},
+                {"OutputStyle", 0, &cfg.ostyle, 0, 0},
+                {"RateUnit", 0, &cfg.rateunit, 0, 0},
+                {"DefaultDecimals", 0, &cfg.defaultdecimals, 0, 0},
+                {"HourlyDecimals", 0, &cfg.hourlydecimals, 0, 0},
+                {"HourlySectionStyle", 0, &cfg.hourlystyle, 0, 0},
+                {"BandwidthDetection", 0, &cfg.bwdetection, 0, 0},
+                {"MaxBandwidth", 0, &cfg.maxbw, 0, 0},
+                {"Sampletime", 0, &cfg.sampletime, 0, 0},
+                {"QueryMode", 0, &cfg.qmode, 0, 0},
+                {"CheckDiskSpace", 0, &cfg.spacecheck, 0, 0},
+                {"BootVariation", 0, &cfg.bvar, 0, 0},
+                {"TrafficlessEntries", 0, &cfg.trafficlessentries, 0, 0},
+                {"List5Mins", 0, &cfg.listfivemins, 0, 0},
+                {"ListHours", 0, &cfg.listhours, 0, 0},
+                {"ListDays", 0, &cfg.listdays, 0, 0},
+                {"ListMonths", 0, &cfg.listmonths, 0, 0},
+                {"ListYears", 0, &cfg.listyears, 0, 0},
+                {"ListTop", 0, &cfg.listtop, 0, 0},
+                {"5MinuteHours", 0, &cfg.fiveminutehours, 0, 0},
+                {"HourlyDays", 0, &cfg.hourlydays, 0, 0},
+                {"DailyDays", 0, &cfg.dailydays, 0, 0},
+                {"MonthlyMonths", 0, &cfg.monthlymonths, 0, 0},
+                {"YearlyYears", 0, &cfg.yearlyyears, 0, 0},
+                {"TopDayEntries", 0, &cfg.topdayentries, 0, 0},
+                {"DaemonUser", cfg.daemonuser, 0, 33, 0},
+                {"DaemonGroup", cfg.daemongroup, 0, 33, 0},
+                {"TimeSyncWait", 0, &cfg.timesyncwait, 0, 0},
+                {"UpdateInterval", 0, &cfg.updateinterval, 0, 0},
+                {"PollInterval", 0, &cfg.pollinterval, 0, 0},
+                {"SaveInterval", 0, &cfg.saveinterval, 0, 0},
+                {"OfflineSaveInterval", 0, &cfg.offsaveinterval, 0, 0},
+                {"BandwidthDetectionInterval", 0, &cfg.bwdetectioninterval, 0, 0},
+                {"SaveOnStatusChange", 0, &cfg.savestatus, 0, 0},
+                {"UseLogging", 0, &cfg.uselogging, 0, 0},
+                {"CreateDirs", 0, &cfg.createdirs, 0, 0},
+                {"UpdateFileOwner", 0, &cfg.updatefileowner, 0, 0},
+                {"LogFile", cfg.logfile, 0, 512, 0},
+                {"PidFile", cfg.pidfile, 0, 512, 0},
+                {"64bitInterfaceCounters", 0, &cfg.is64bit, 0, 0},
+                {"HeaderFormat", cfg.hformat, 0, 64, 0},
+                {"HourlyRate", 0, &cfg.hourlyrate, 0, 0},
+                {"SummaryRate", 0, &cfg.summaryrate, 0, 0},
+                {"TransparentBg", 0, &cfg.transbg, 0, 0},
+                {"CBackground", cfg.cbg, 0, 8, 0},
+                {"CEdge", cfg.cedge, 0, 8, 0},
+                {"CHeader", cfg.cheader, 0, 8, 0},
+                {"CHeaderTitle", cfg.cheadertitle, 0, 8, 0},
+                {"CHeaderDate", cfg.cheaderdate, 0, 8, 0},
+                {"CText", cfg.ctext, 0, 8, 0},
+                {"CLine", cfg.cline, 0, 8, 0},
+                {"CLineL", cfg.clinel, 0, 8, 0},
+                {"CRx", cfg.crx, 0, 8, 0},
+                {"CRxD", cfg.crxd, 0, 8, 0},
+                {"CTx", cfg.ctx, 0, 8, 0},
+                {"CTxD", cfg.ctxd, 0, 8, 0},
+                {0, 0, 0, 0, 0}};
 
        /* load default config */
        defaultcfg();
@@ -96,23 +95,23 @@ int loadcfg(const char *cfgfile)
        while (!feof(fd)) {
 
                cfgline[0] = '\0';
-               if (fgets(cfgline, 512, fd)==NULL) {
+               if (fgets(cfgline, 512, fd) == NULL) {
                        break;
                }
 
                linelen = (unsigned int)strlen(cfgline);
-               if (linelen<=2 || cfgline[0]=='#') {
+               if (linelen <= 2 || cfgline[0] == '#') {
                        continue;
                }
 
-               for (i=0; cset[i].name!=0; i++) {
+               for (i = 0; cset[i].name != 0; i++) {
 
                        if (cset[i].found) {
                                continue;
                        }
 
                        cfglen = (unsigned int)strlen(cset[i].name);
-                       if ( (linelen<(cfglen+2)) || (strncasecmp(cfgline, cset[i].name, cfglen)!=0) ) {
+                       if ((linelen < (cfglen + 2)) || (strncasecmp(cfgline, cset[i].name, cfglen) != 0)) {
                                continue;
                        }
 
@@ -131,9 +130,8 @@ int loadcfg(const char *cfgfile)
                        break;
                }
 
-               if ((debug) && (!cset[i].found) && (strncasecmp(cfgline, "MaxBW", 5)!=0))
+               if ((debug) && (!cset[i].found) && (strncasecmp(cfgline, "MaxBW", 5) != 0))
                        printf("Unknown configuration line: %s", cfgline);
-
        }
 
        fclose(fd);
@@ -142,7 +140,6 @@ int loadcfg(const char *cfgfile)
        validatecfg();
 
        return 1;
-
 }
 
 void validatecfg(void)
@@ -151,73 +148,73 @@ void validatecfg(void)
        const char *resettingto = "resetting to";
        const char *noslashstart = "doesn't start with \"/\", resetting to default.";
 
-       if (cfg.unitmode<0 || cfg.unitmode>2) {
+       if (cfg.unitmode < 0 || cfg.unitmode > 2) {
                cfg.unitmode = UNITMODE;
                snprintf(errorstring, 1024, "%s UnitMode, %s \"%d\".", invalidvalue, resettingto, cfg.unitmode);
                printe(PT_Config);
        }
 
-       if (cfg.rateunitmode<0 || cfg.rateunitmode>1) {
+       if (cfg.rateunitmode < 0 || cfg.rateunitmode > 1) {
                cfg.rateunitmode = RATEUNITMODE;
                snprintf(errorstring, 1024, "%s RateUnitMode, %s \"%d\".", invalidvalue, resettingto, cfg.rateunitmode);
                printe(PT_Config);
        }
 
-       if (cfg.ostyle<0 || cfg.ostyle>3) {
+       if (cfg.ostyle < 0 || cfg.ostyle > 3) {
                cfg.ostyle = OSTYLE;
                snprintf(errorstring, 1024, "%s OutputStyle, %s \"%d\".", invalidvalue, resettingto, cfg.ostyle);
                printe(PT_Config);
        }
 
-       if (cfg.defaultdecimals<0 || cfg.defaultdecimals>2) {
+       if (cfg.defaultdecimals < 0 || cfg.defaultdecimals > 2) {
                cfg.defaultdecimals = DEFAULTDECIMALS;
                snprintf(errorstring, 1024, "%s DefaultDecimals, %s \"%d\".", invalidvalue, resettingto, cfg.defaultdecimals);
                printe(PT_Config);
        }
 
-       if (cfg.hourlydecimals<0 || cfg.hourlydecimals>2) {
+       if (cfg.hourlydecimals < 0 || cfg.hourlydecimals > 2) {
                cfg.hourlydecimals = HOURLYDECIMALS;
                snprintf(errorstring, 1024, "%s HourlyDecimals, %s \"%d\".", invalidvalue, resettingto, cfg.hourlydecimals);
                printe(PT_Config);
        }
 
-       if (cfg.hourlystyle<0 || cfg.hourlystyle>3) {
+       if (cfg.hourlystyle < 0 || cfg.hourlystyle > 3) {
                cfg.hourlystyle = HOURLYSTYLE;
                snprintf(errorstring, 1024, "%s HourlySectionStyle, %s \"%d\".", invalidvalue, resettingto, cfg.hourlystyle);
                printe(PT_Config);
        }
 
-       if (cfg.bvar<0 || cfg.bvar>300) {
+       if (cfg.bvar < 0 || cfg.bvar > 300) {
                cfg.bvar = BVAR;
                snprintf(errorstring, 1024, "%s BootVariation, %s \"%d\".", invalidvalue, resettingto, cfg.bvar);
                printe(PT_Config);
        }
 
-       if (cfg.sampletime<2 || cfg.sampletime>600) {
+       if (cfg.sampletime < 2 || cfg.sampletime > 600) {
                cfg.sampletime = DEFSAMPTIME;
                snprintf(errorstring, 1024, "%s Sampletime, %s \"%d\".", invalidvalue, resettingto, cfg.sampletime);
                printe(PT_Config);
        }
 
-       if (cfg.monthrotate<1 || cfg.monthrotate>28) {
+       if (cfg.monthrotate < 1 || cfg.monthrotate > 28) {
                cfg.monthrotate = MONTHROTATE;
                snprintf(errorstring, 1024, "%s MonthRotate, %s \"%d\".", invalidvalue, resettingto, cfg.monthrotate);
                printe(PT_Config);
        }
 
-       if (cfg.monthrotateyears<0 || cfg.monthrotateyears>1) {
+       if (cfg.monthrotateyears < 0 || cfg.monthrotateyears > 1) {
                cfg.monthrotateyears = MONTHROTATEYEARS;
                snprintf(errorstring, 1024, "%s MonthRotateAffectsYears, %s \"%d\".", invalidvalue, resettingto, cfg.monthrotateyears);
                printe(PT_Config);
        }
 
-       if (cfg.maxbw<0 || cfg.maxbw>BWMAX) {
+       if (cfg.maxbw < 0 || cfg.maxbw > BWMAX) {
                cfg.maxbw = DEFMAXBW;
                snprintf(errorstring, 1024, "%s MaxBandwidth, %s \"%d\".", invalidvalue, resettingto, cfg.maxbw);
                printe(PT_Config);
        }
 
-       if (cfg.spacecheck<0 || cfg.spacecheck>1) {
+       if (cfg.spacecheck < 0 || cfg.spacecheck > 1) {
                cfg.spacecheck = USESPACECHECK;
                snprintf(errorstring, 1024, "%s CheckDiskSpace, %s \"%d\".", invalidvalue, resettingto, cfg.spacecheck);
                printe(PT_Config);
@@ -229,20 +226,20 @@ void validatecfg(void)
                printe(PT_Config);
        }
 
-       if (cfg.timesyncwait<0 || cfg.timesyncwait>60) {
+       if (cfg.timesyncwait < 0 || cfg.timesyncwait > 60) {
                cfg.timesyncwait = TIMESYNCWAIT;
                snprintf(errorstring, 1024, "%s TimeSyncWait, %s \"%d\".", invalidvalue, resettingto, cfg.timesyncwait);
                printe(PT_Config);
        }
 
-       if (cfg.pollinterval<2 || cfg.pollinterval>60) {
+       if (cfg.pollinterval < 2 || cfg.pollinterval > 60) {
                cfg.pollinterval = POLLINTERVAL;
                snprintf(errorstring, 1024, "%s PollInterval, %s \"%d\".", invalidvalue, resettingto, cfg.pollinterval);
                printe(PT_Config);
        }
 
-       if (cfg.updateinterval<cfg.pollinterval || cfg.updateinterval>300) {
-               if (cfg.pollinterval>UPDATEINTERVAL) {
+       if (cfg.updateinterval < cfg.pollinterval || cfg.updateinterval > 300) {
+               if (cfg.pollinterval > UPDATEINTERVAL) {
                        cfg.updateinterval = cfg.pollinterval;
                } else {
                        cfg.updateinterval = UPDATEINTERVAL;
@@ -251,8 +248,8 @@ void validatecfg(void)
                printe(PT_Config);
        }
 
-       if ((cfg.saveinterval*60)<cfg.updateinterval || cfg.saveinterval>60) {
-               if (cfg.updateinterval>(SAVEINTERVAL*60)) {
+       if ((cfg.saveinterval * 60) < cfg.updateinterval || cfg.saveinterval > 60) {
+               if (cfg.updateinterval > (SAVEINTERVAL * 60)) {
                        cfg.saveinterval = cfg.updateinterval;
                } else {
                        cfg.saveinterval = SAVEINTERVAL;
@@ -261,8 +258,8 @@ void validatecfg(void)
                printe(PT_Config);
        }
 
-       if (cfg.offsaveinterval<cfg.saveinterval || cfg.offsaveinterval>60) {
-               if (cfg.saveinterval>OFFSAVEINTERVAL) {
+       if (cfg.offsaveinterval < cfg.saveinterval || cfg.offsaveinterval > 60) {
+               if (cfg.saveinterval > OFFSAVEINTERVAL) {
                        cfg.offsaveinterval = cfg.saveinterval;
                } else {
                        cfg.offsaveinterval = OFFSAVEINTERVAL;
@@ -271,25 +268,25 @@ void validatecfg(void)
                printe(PT_Config);
        }
 
-       if (cfg.savestatus<0 || cfg.savestatus>1) {
+       if (cfg.savestatus < 0 || cfg.savestatus > 1) {
                cfg.savestatus = SAVESTATUS;
                snprintf(errorstring, 1024, "%s SaveOnStatusChange, %s \"%d\".", invalidvalue, resettingto, cfg.savestatus);
                printe(PT_Config);
        }
 
-       if (cfg.uselogging<0 || cfg.uselogging>2) {
+       if (cfg.uselogging < 0 || cfg.uselogging > 2) {
                cfg.uselogging = USELOGGING;
                snprintf(errorstring, 1024, "%s UseLogging, %s \"%d\".", invalidvalue, resettingto, cfg.uselogging);
                printe(PT_Config);
        }
 
-       if (cfg.createdirs<0 || cfg.createdirs>2) {
+       if (cfg.createdirs < 0 || cfg.createdirs > 2) {
                cfg.createdirs = CREATEDIRS;
                snprintf(errorstring, 1024, "%s CreateDirs, %s \"%d\".", invalidvalue, resettingto, cfg.createdirs);
                printe(PT_Config);
        }
 
-       if (cfg.updatefileowner<0 || cfg.updatefileowner>2) {
+       if (cfg.updatefileowner < 0 || cfg.updatefileowner > 2) {
                cfg.updatefileowner = UPDATEFILEOWNER;
                snprintf(errorstring, 1024, "%s UpdateFileOwner, %s \"%d\".", invalidvalue, resettingto, cfg.updatefileowner);
                printe(PT_Config);
@@ -307,115 +304,115 @@ void validatecfg(void)
                printe(PT_Config);
        }
 
-       if (cfg.is64bit<-2 || cfg.is64bit>1) {
+       if (cfg.is64bit < -2 || cfg.is64bit > 1) {
                cfg.is64bit = IS64BIT;
                snprintf(errorstring, 1024, "%s 64bitInterfaceCounters, %s \"%d\".", invalidvalue, resettingto, cfg.is64bit);
                printe(PT_Config);
        }
 
-       if (cfg.transbg<0 || cfg.transbg>1) {
+       if (cfg.transbg < 0 || cfg.transbg > 1) {
                cfg.transbg = TRANSBG;
                snprintf(errorstring, 1024, "%s TransparentBg, %s \"%d\".", invalidvalue, resettingto, cfg.transbg);
                printe(PT_Config);
        }
 
-       if (cfg.hourlyrate<0 || cfg.hourlyrate>1) {
+       if (cfg.hourlyrate < 0 || cfg.hourlyrate > 1) {
                cfg.hourlyrate = HOURLYRATE;
                snprintf(errorstring, 1024, "%s HourlyRate, %s \"%d\".", invalidvalue, resettingto, cfg.hourlyrate);
                printe(PT_Config);
        }
 
-       if (cfg.summaryrate<0 || cfg.summaryrate>1) {
+       if (cfg.summaryrate < 0 || cfg.summaryrate > 1) {
                cfg.summaryrate = SUMMARYRATE;
                snprintf(errorstring, 1024, "%s SummaryRate, %s \"%d\".", invalidvalue, resettingto, cfg.summaryrate);
                printe(PT_Config);
        }
 
-       if (cfg.trafficlessentries<0 || cfg.trafficlessentries>1) {
+       if (cfg.trafficlessentries < 0 || cfg.trafficlessentries > 1) {
                cfg.trafficlessentries = TRAFFICLESSENTRIES;
                snprintf(errorstring, 1024, "%s TrafficlessEntries, %s \"%d\".", invalidvalue, resettingto, cfg.trafficlessentries);
                printe(PT_Config);
        }
 
-       if (cfg.listfivemins<0) {
+       if (cfg.listfivemins < 0) {
                cfg.listfivemins = LISTFIVEMINS;
                snprintf(errorstring, 1024, "%s List5Mins, %s \"%d\".", invalidvalue, resettingto, cfg.listfivemins);
                printe(PT_Config);
        }
 
-       if (cfg.listhours<0) {
+       if (cfg.listhours < 0) {
                cfg.listhours = LISTHOURS;
                snprintf(errorstring, 1024, "%s ListHours, %s \"%d\".", invalidvalue, resettingto, cfg.listhours);
                printe(PT_Config);
        }
 
-       if (cfg.listdays<0) {
+       if (cfg.listdays < 0) {
                cfg.listdays = LISTDAYS;
                snprintf(errorstring, 1024, "%s ListDays, %s \"%d\".", invalidvalue, resettingto, cfg.listdays);
                printe(PT_Config);
        }
 
-       if (cfg.listmonths<0) {
+       if (cfg.listmonths < 0) {
                cfg.listmonths = LISTMONTHS;
                snprintf(errorstring, 1024, "%s ListMonths, %s \"%d\".", invalidvalue, resettingto, cfg.listmonths);
                printe(PT_Config);
        }
 
-       if (cfg.listyears<0) {
+       if (cfg.listyears < 0) {
                cfg.listyears = LISTYEARS;
                snprintf(errorstring, 1024, "%s ListYears, %s \"%d\".", invalidvalue, resettingto, cfg.listyears);
                printe(PT_Config);
        }
 
-       if (cfg.listtop<0) {
+       if (cfg.listtop < 0) {
                cfg.listtop = LISTTOP;
                snprintf(errorstring, 1024, "%s ListTop, %s \"%d\".", invalidvalue, resettingto, cfg.listtop);
                printe(PT_Config);
        }
 
-       if (cfg.fiveminutehours<-1) {
+       if (cfg.fiveminutehours < -1) {
                cfg.fiveminutehours = FIVEMINUTEHOURS;
                snprintf(errorstring, 1024, "%s 5MinuteHours, %s \"%d\".", invalidvalue, resettingto, cfg.fiveminutehours);
                printe(PT_Config);
        }
 
-       if (cfg.hourlydays<-1) {
+       if (cfg.hourlydays < -1) {
                cfg.hourlydays = HOURLYDAYS;
                snprintf(errorstring, 1024, "%s HourlyDays, %s \"%d\".", invalidvalue, resettingto, cfg.hourlydays);
                printe(PT_Config);
        }
 
-       if (cfg.dailydays<-1) {
+       if (cfg.dailydays < -1) {
                cfg.dailydays = DAILYDAYS;
                snprintf(errorstring, 1024, "%s DailyDays, %s \"%d\".", invalidvalue, resettingto, cfg.dailydays);
                printe(PT_Config);
        }
 
-       if (cfg.monthlymonths<-1) {
+       if (cfg.monthlymonths < -1) {
                cfg.monthlymonths = MONTHLYMONTHS;
                snprintf(errorstring, 1024, "%s MonthlyMonths, %s \"%d\".", invalidvalue, resettingto, cfg.monthlymonths);
                printe(PT_Config);
        }
 
-       if (cfg.yearlyyears<-1) {
+       if (cfg.yearlyyears < -1) {
                cfg.yearlyyears = YEARLYYEARS;
                snprintf(errorstring, 1024, "%s YearlyYears, %s \"%d\".", invalidvalue, resettingto, cfg.yearlyyears);
                printe(PT_Config);
        }
 
-       if (cfg.topdayentries<-1) {
+       if (cfg.topdayentries < -1) {
                cfg.topdayentries = TOPDAYENTRIES;
                snprintf(errorstring, 1024, "%s TopDayEntries, %s \"%d\".", invalidvalue, resettingto, cfg.topdayentries);
                printe(PT_Config);
        }
 
-       if (cfg.bwdetection<0 || cfg.bwdetection>1) {
+       if (cfg.bwdetection < 0 || cfg.bwdetection > 1) {
                cfg.bwdetection = BWDETECT;
                snprintf(errorstring, 1024, "%s BandwidthDetection, %s \"%d\".", invalidvalue, resettingto, cfg.bwdetection);
                printe(PT_Config);
        }
 
-       if (cfg.bwdetectioninterval<0 || cfg.bwdetectioninterval>30) {
+       if (cfg.bwdetectioninterval < 0 || cfg.bwdetectioninterval > 30) {
                cfg.bwdetectioninterval = BWDETECTINTERVAL;
                snprintf(errorstring, 1024, "%s BandwidthDetectionInterval, %s \"%d\".", invalidvalue, resettingto, cfg.bwdetectioninterval);
                printe(PT_Config);
@@ -510,17 +507,17 @@ int opencfgfile(const char *cfgfile, FILE **fd)
        int i, tryhome;
 
        /* clear buffer */
-       for (i=0; i<512; i++) {
+       for (i = 0; i < 512; i++) {
                buffer[i] = '\0';
        }
        cfg.cfgfile[0] = '\0';
 
        /* possible config files: 1) --config   2) $HOME/.vnstatrc   3) /etc/vnstat.conf   4) none */
 
-       if (cfgfile[0]!='\0') {
+       if (cfgfile[0] != '\0') {
 
                /* try to open given file */
-               if ((*fd=fopen(cfgfile, "r"))!=NULL) {
+               if ((*fd = fopen(cfgfile, "r")) != NULL) {
                        strncpy_nt(cfg.cfgfile, cfgfile, 512);
                        if (debug)
                                printf("Config file: --config\n");
@@ -541,11 +538,11 @@ int opencfgfile(const char *cfgfile, FILE **fd)
                }
 
                /* try to open first available config file */
-               if (tryhome && (*fd=fopen(buffer, "r"))!=NULL) {
+               if (tryhome && (*fd = fopen(buffer, "r")) != NULL) {
                        strncpy_nt(cfg.cfgfile, buffer, 512);
-               } else if ((*fd=fopen("/etc/vnstat.conf", "r"))!=NULL) {
+               } else if ((*fd = fopen("/etc/vnstat.conf", "r")) != NULL) {
                        snprintf(cfg.cfgfile, 512, "/etc/vnstat.conf");
-               } else if ((*fd=fopen("/usr/local/etc/vnstat.conf", "r"))!=NULL) {
+               } else if ((*fd = fopen("/usr/local/etc/vnstat.conf", "r")) != NULL) {
                        snprintf(cfg.cfgfile, 512, "/usr/local/etc/vnstat.conf");
                } else {
                        if (debug)
@@ -559,28 +556,29 @@ int opencfgfile(const char *cfgfile, FILE **fd)
        return 2;
 }
 
-int extractcfgvalue(char *value, const unsigned int valuelen, const char *cfgline, const unsigned int cfglen) {
+int extractcfgvalue(char *value, const unsigned int valuelen, const char *cfgline, const unsigned int cfglen)
+{
 
        unsigned int i, j, linelen;
 
        linelen = (unsigned int)strlen(cfgline);
 
-       for (i=0; i<valuelen; i++) {
-               value[i]='\0';
+       for (i = 0; i < valuelen; i++) {
+               value[i] = '\0';
        }
 
        i = 0;
-       for (j=cfglen; j<linelen; j++) {
-               if (cfgline[j]=='\n' || cfgline[j]=='\r') {
+       for (j = cfglen; j < linelen; j++) {
+               if (cfgline[j] == '\n' || cfgline[j] == '\r') {
                        break;
-               } else if (cfgline[j]=='\"') {
-                       if (i==0) {
+               } else if (cfgline[j] == '\"') {
+                       if (i == 0) {
                                continue;
                        } else {
                                break;
                        }
                } else {
-                       if (i==0 && (cfgline[j]==' ' || cfgline[j]=='=' || cfgline[j]=='\t')) {
+                       if (i == 0 && (cfgline[j] == ' ' || cfgline[j] == '=' || cfgline[j] == '\t')) {
                                continue;
                        } else {
                                value[i] = cfgline[j];
@@ -594,11 +592,11 @@ int extractcfgvalue(char *value, const unsigned int valuelen, const char *cfglin
 
 int setcfgvalue(const struct cfgsetting *cset, const char *value, const char *cfgline)
 {
-       if (cset->namelen>0) {
+       if (cset->namelen > 0) {
                strncpy_nt(cset->locc, value, (size_t)cset->namelen);
                if (debug)
                        printf("  c: %s   -> \"%s\": \"%s\"\n", cfgline, cset->name, cset->locc);
-       } else if ( ( strlen(value)>1 && isdigit(value[1]) ) || isdigit(value[0]) ) {
+       } else if ((strlen(value) > 1 && isdigit(value[1])) || isdigit(value[0])) {
                *cset->loci = (int32_t)strtol(value, (char **)NULL, 0);
                if (debug)
                        printf("  i: %s   -> \"%s\": %d\n", cfgline, cset->name, *cset->loci);
@@ -611,7 +609,7 @@ int setcfgvalue(const struct cfgsetting *cset, const char *value, const char *cf
 
 void configlocale(void)
 {
-       if (cfg.locale[0]!='-' && strlen(cfg.locale)>0) {
+       if (cfg.locale[0] != '-' && strlen(cfg.locale) > 0) {
                setlocale(LC_ALL, cfg.locale);
        } else {
                if (getenv("LC_ALL")) {
index 5a409093577b8ecebbcc7f70c24bde75038ff286..74946855a98e987ed432d5954e832849c387f43e 100644 (file)
@@ -193,5 +193,4 @@ void printcfgfile(void)
        printf("CTx             \"%s\"\n", cfg.ctx);
        printf("CRxD            \"%s\"\n", cfg.crxd);
        printf("CTxD            \"%s\"\n", cfg.ctxd);
-
 }
index 128a4470bb5c23849ad962aac3a6c4f52a5abd59..543cf502ed65558a432dcff33d4d7b06dcc122f2 100644 (file)
@@ -6,12 +6,11 @@ IFINFO ifinfo;
 char errorstring[1024];
 ibwnode *ifacebw;
 int debug;
-int noexit;      /* = running as daemon if 2 */
+int noexit; /* = running as daemon if 2 */
 int intsignal;
 int pidfile;
 int disableprints;
 
-
 int printe(const PrintType type)
 {
        int result = 1;
@@ -19,12 +18,12 @@ int printe(const PrintType type)
        if (disableprints) {
                return 1;
 
-       /* daemon running but log not enabled */
-       } else if (noexit==2 && cfg.uselogging==0) {
+               /* daemon running but log not enabled */
+       } else if (noexit == 2 && cfg.uselogging == 0) {
                return 1;
 
-       /* daemon running, log enabled */
-       } else if (noexit==2) {
+               /* daemon running, log enabled */
+       } else if (noexit == 2) {
 
                switch (type) {
                        case PT_Multiline:
@@ -38,7 +37,7 @@ int printe(const PrintType type)
                                break;
                }
 
-       /* daemon isn't running */
+               /* daemon isn't running */
        } else {
 
                switch (type) {
@@ -76,7 +75,7 @@ int logprint(const PrintType type)
        buffer[0] = '\0';
 
        /* logfile */
-       if (cfg.uselogging==1) {
+       if (cfg.uselogging == 1) {
 
                if (type == PT_Multiline) {
                        return 0;
@@ -107,7 +106,7 @@ int logprint(const PrintType type)
                                break;
                }
 
-               if (fwrite(buffer, strlen(buffer), 1, logfile)!=1) {
+               if (fwrite(buffer, strlen(buffer), 1, logfile) != 1) {
                        fclose(logfile);
                        return 0;
                }
@@ -115,8 +114,8 @@ int logprint(const PrintType type)
                fclose(logfile);
                return 1;
 
-       /* syslog */
-       } else if (cfg.uselogging==2) {
+               /* syslog */
+       } else if (cfg.uselogging == 2) {
 
                openlog("vnstatd", LOG_PID, LOG_DAEMON);
 
@@ -148,7 +147,7 @@ int verifylogaccess(void)
        FILE *logfile;
 
        /* only logfile logging can be verified */
-       if (cfg.uselogging==1) {
+       if (cfg.uselogging == 1) {
                if ((logfile = fopen(cfg.logfile, "a")) == NULL) {
                        return 0;
                }
@@ -164,7 +163,7 @@ int dmonth(const int month)
        time_t current;
 
        /* handle leap years */
-       if (month==1) {
+       if (month == 1) {
                current = time(NULL);
                year = localtime(&current)->tm_year + 1900;
                if (isleapyear(year)) {
@@ -200,8 +199,8 @@ time_t mosecs(time_t month, time_t updated)
        d.tm_mday = cfg.monthrotate;
        d.tm_hour = d.tm_min = d.tm_sec = 0;
 
-       if ((updated-month)>0) {
-               return updated-mktime(&d);
+       if ((updated - month) > 0) {
+               return updated - mktime(&d);
        } else {
                return 1;
        }
@@ -212,22 +211,22 @@ uint64_t countercalc(const uint64_t *a, const uint64_t *b, const short is64bit)
        /* no rollover */
        if (*b >= *a) {
                if (debug)
-                       printf("cc (%d): %"PRIu64" - %"PRIu64" = %"PRIu64"\n", is64bit, *b, *a, *b-*a);
-               return *b-*a;
+                       printf("cc (%d): %" PRIu64 " - %" PRIu64 " = %" PRIu64 "\n", is64bit, *b, *a, *b - *a);
+               return *b - *a;
 
-       /* rollover exists */
+               /* rollover exists */
        } else {
                /* counter is 64bit */
                if (*a > MAX32 || is64bit == 1) {
                        if (debug)
-                               printf("cc64 (%d): uint64 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", is64bit, *a, *b, (uint64_t)MAX64-*a+*b);
-                       return MAX64-*a+*b;
+                               printf("cc64 (%d): uint64 - %" PRIu64 " + %" PRIu64 " = %" PRIu64 "\n", is64bit, *a, *b, (uint64_t)MAX64 - *a + *b);
+                       return MAX64 - *a + *b;
 
-               /* counter is 32bit */
+                       /* counter is 32bit */
                } else {
                        if (debug)
-                               printf("cc32 (%d): uint32 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", is64bit, *a, *b, (uint64_t)MAX32-*a+*b);
-                       return MAX32-*a+*b;
+                               printf("cc32 (%d): uint32 - %" PRIu64 " + %" PRIu64 " = %" PRIu64 "\n", is64bit, *a, *b, (uint64_t)MAX32 - *a + *b);
+                       return MAX32 - *a + *b;
                }
        }
 }
@@ -236,7 +235,7 @@ uint64_t countercalc(const uint64_t *a, const uint64_t *b, const short is64bit)
 char *strncpy_nt(char *dest, const char *src, size_t n)
 {
        strncpy(dest, src, n);
-       dest[n-1] = '\0';
+       dest[n - 1] = '\0';
        return dest;
 }
 
@@ -248,7 +247,7 @@ int isnumeric(const char *s)
                return 0;
        }
 
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                if (!isdigit(s[i])) {
                        return 0;
                }
@@ -257,8 +256,7 @@ int isnumeric(const char *s)
        return 1;
 }
 
-__attribute__((noreturn))
-void panicexit(const char *sourcefile, const int sourceline)
+__attribute__((noreturn)) void panicexit(const char *sourcefile, const int sourceline)
 {
        snprintf(errorstring, 1024, "Unexpected error (%s), exiting. (%s:%d)", strerror(errno), sourcefile, sourceline);
        fprintf(stderr, "%s\n", errorstring);
@@ -271,7 +269,7 @@ char *getversion(void)
        int i;
        static char versionbuffer[16];
        strncpy_nt(versionbuffer, VERSION, 16);
-       for (i=0; i<(int)strlen(versionbuffer); i++) {
+       for (i = 0; i < (int)strlen(versionbuffer); i++) {
                if (versionbuffer[i] == '_') {
                        versionbuffer[i] = ' ';
                }
index 76182c3081f08b32247c32ec6939546e2d0ec8fa..a3b6a75d41ab39ee6ba22df3268d0ad088d3763d 100644 (file)
 
 /* OpenBSD and NetBSD don't support the ' character (decimal conversion) in printf formatting */
 #if !defined(__OpenBSD__) && !defined(__NetBSD__)
-  #define DECCONV "'"
+#define DECCONV "'"
 #else
-  #define DECCONV
+#define DECCONV
 #endif
 
 /* used in debug to get function name */
 #if __STDC_VERSION__ < 199901L
-  #if __GNUC__ >= 2
-    #define __func__ __FUNCTION__
-  #else
-    #define __func__ "function"
-  #endif
+#if __GNUC__ >= 2
+#define __func__ __FUNCTION__
+#else
+#define __func__ "function"
+#endif
 #endif
 
 /*
@@ -60,11 +60,11 @@ and most can be changed later from the config file.
 
 /* location of the database directory */
 #ifndef DATABASEDIR
-  #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
-    #define DATABASEDIR "/var/db/vnstat"
-  #else
-    #define DATABASEDIR "/var/lib/vnstat"
-  #endif
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+#define DATABASEDIR "/var/db/vnstat"
+#else
+#define DATABASEDIR "/var/lib/vnstat"
+#endif
 #endif
 
 /* database file name */
@@ -76,10 +76,10 @@ and most can be changed later from the config file.
 
 /* date output formats for -d, -m, -t and image header*/
 /* see 'man date' for control codes      1.x values     <1.8 values */
-#define DFORMAT "%Y-%m-%d"             /* "%x"         "%d.%m." */
-#define MFORMAT "%Y-%m"                /* "%b '%y"     "%b '%y" */
-#define TFORMAT "%Y-%m-%d"             /* "%x"         "%d.%m.%y" */
-#define HFORMAT "%Y-%m-%d %H:%M"       /* "%x %H:%M"   "%d.%m.%Y %H:%M" */
+#define DFORMAT "%Y-%m-%d"              /* "%x"         "%d.%m." */
+#define MFORMAT "%Y-%m"                         /* "%b '%y"     "%b '%y" */
+#define TFORMAT "%Y-%m-%d"              /* "%x"         "%d.%m.%y" */
+#define HFORMAT "%Y-%m-%d %H:%M" /* "%x %H:%M"   "%d.%m.%Y %H:%M" */
 
 #ifndef DATETIMEFORMAT
 #define DATETIMEFORMAT "%Y-%m-%d %H:%M:%S"
@@ -322,7 +322,7 @@ extern IFINFO ifinfo;
 extern char errorstring[1024];
 extern ibwnode *ifacebw;
 extern int debug;
-extern int noexit;      /* = running as daemon if 2 */
+extern int noexit; /* = running as daemon if 2 */
 extern int intsignal;
 extern int pidfile;
 extern int disableprints;
index 15644f00185b6967fc32c012f2d873fd8b13c898..56d8b668211d36c585513b1cf7c1447d0fe5a2e0 100644 (file)
@@ -15,17 +15,17 @@ void daemonize(void)
        int i;
        char str[10];
 
-       if (getppid()==1) {
+       if (getppid() == 1) {
                return; /* already a daemon */
        }
 
        i = (int)fork();
 
-       if (i<0) { /* fork error */
+       if (i < 0) { /* fork error */
                perror("Error: fork");
                exit(EXIT_FAILURE);
        }
-       if (i>0) { /* parent exits */
+       if (i > 0) { /* parent exits */
                exit(EXIT_SUCCESS);
        }
        /* child (daemon) continues */
@@ -38,14 +38,14 @@ void daemonize(void)
        }
 
        /* lock / pid file */
-       pidfile = open(cfg.pidfile, O_RDWR|O_CREAT, 0644);
-       if (pidfile<0) {
+       pidfile = open(cfg.pidfile, O_RDWR | O_CREAT, 0644);
+       if (pidfile < 0) {
                perror("Error: pidfile");
                snprintf(errorstring, 1024, "opening pidfile \"%s\" failed (%s), exiting.", cfg.pidfile, strerror(errno));
                printe(PT_Error);
                exit(EXIT_FAILURE); /* can't open */
        }
-       if (lockf(pidfile,F_TLOCK,0)<0) {
+       if (lockf(pidfile, F_TLOCK, 0) < 0) {
                perror("Error: pidfile lock");
                snprintf(errorstring, 1024, "pidfile \"%s\" lock failed (%s), exiting.", cfg.pidfile, strerror(errno));
                printe(PT_Error);
@@ -53,14 +53,14 @@ void daemonize(void)
        }
 
        /* close all descriptors except lock file */
-       for (i=getdtablesize();i>=0;--i) {
-               if (i!=pidfile) {
+       for (i = getdtablesize(); i >= 0; --i) {
+               if (i != pidfile) {
                        close(i);
                }
        }
 
        /* redirect standard i/o to null */
-       i=open("/dev/null",O_RDWR); /* stdin */
+       i = open("/dev/null", O_RDWR); /* stdin */
 
        if (i < 0) {
                perror("Error: open() /dev/null");
@@ -100,17 +100,17 @@ void daemonize(void)
        snprintf(str, 10, "%d\n", (int)getpid());
 
        /* record pid to pidfile */
-       if (write(pidfile,str,strlen(str)) < 0) {
+       if (write(pidfile, str, strlen(str)) < 0) {
                perror("Error: write(pidfile)");
                snprintf(errorstring, 1024, "writing to pidfile \"%s\" failed (%s), exiting.", cfg.pidfile, strerror(errno));
                printe(PT_Error);
                exit(EXIT_FAILURE);
        }
 
-       signal(SIGCHLD,SIG_IGN); /* ignore child */
-       signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
-       signal(SIGTTOU,SIG_IGN);
-       signal(SIGTTIN,SIG_IGN);
+       signal(SIGCHLD, SIG_IGN); /* ignore child */
+       signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
+       signal(SIGTTOU, SIG_IGN);
+       signal(SIGTTIN, SIG_IGN);
 }
 
 unsigned int addinterfaces(DSTATE *s)
@@ -122,12 +122,12 @@ unsigned int addinterfaces(DSTATE *s)
        timeused(__func__, 1);
 
        /* get list of currently visible interfaces */
-       if (getiflist(&ifacelist, 0)==0) {
+       if (getiflist(&ifacelist, 0) == 0) {
                free(ifacelist);
                return 0;
        }
 
-       if (strlen(ifacelist)<2) {
+       if (strlen(ifacelist) < 2) {
                free(ifacelist);
                return 0;
        }
@@ -135,14 +135,14 @@ unsigned int addinterfaces(DSTATE *s)
        if (debug)
                printf("Interface list: \"%s\"\n", ifacelist);
 
-       while (sscanf(ifacelist+index, "%31s", interface)!=EOF) {
+       while (sscanf(ifacelist + index, "%31s", interface) != EOF) {
                if (debug)
                        printf("Processing: \"%s\"\n", interface);
 
-               index += strlen(interface)+1;
+               index += strlen(interface) + 1;
 
                /* skip local interfaces */
-               if ((strcmp(interface,"lo")==0) || (strcmp(interface,"lo0")==0) || (strcmp(interface,"sit0")==0)) {
+               if ((strcmp(interface, "lo") == 0) || (strcmp(interface, "lo0") == 0) || (strcmp(interface, "sit0") == 0)) {
                        if (debug)
                                printf("skip\n");
                        continue;
@@ -174,7 +174,7 @@ unsigned int addinterfaces(DSTATE *s)
                count++;
                ibwget(interface, &bwlimit);
                if (bwlimit > 0) {
-                       snprintf(errorstring, 1024, "Interface \"%s\" added with %"PRIu32" Mbit bandwidth limit.", interface, bwlimit);
+                       snprintf(errorstring, 1024, "Interface \"%s\" added with %" PRIu32 " Mbit bandwidth limit.", interface, bwlimit);
                } else {
                        snprintf(errorstring, 1024, "Interface \"%s\" added. Warning: no bandwidth limit has been set.", interface);
                }
@@ -212,19 +212,19 @@ void detectboot(DSTATE *s)
        if (current_btime == 0) {
                return;
        } else if (strlen(btime_buffer) == 0) {
-               snprintf(buffer, 32, "%"PRIu64"", current_btime);
+               snprintf(buffer, 32, "%" PRIu64 "", current_btime);
                db_setinfo("btime", buffer, 1);
                return;
        }
        db_btime = strtoull(btime_buffer, (char **)NULL, 0);
 
-       if (db_btime < (current_btime-(uint32_t)cfg.bvar)) {
+       if (db_btime < (current_btime - (uint32_t)cfg.bvar)) {
                s->bootdetected = 1;
                if (debug)
-                       printf("System has been booted, %"PRIu64" < %"PRIu64" - %d\n", db_btime, current_btime, cfg.bvar);
+                       printf("System has been booted, %" PRIu64 " < %" PRIu64 " - %d\n", db_btime, current_btime, cfg.bvar);
        }
 
-       snprintf(buffer, 32, "%"PRIu64"", current_btime);
+       snprintf(buffer, 32, "%" PRIu64 "", current_btime);
        db_setinfo("btime", buffer, 1);
 }
 
@@ -240,8 +240,8 @@ void debugtimestamp(void)
 
 void initdstate(DSTATE *s)
 {
-       noexit = 1;        /* disable exits in functions */
-       debug = 0;         /* debug disabled by default */
+       noexit = 1;                /* disable exits in functions */
+       debug = 0;                 /* debug disabled by default */
        disableprints = 0; /* let prints be visible */
        s->rundaemon = 0;  /* daemon disabled by default */
 
@@ -277,7 +277,7 @@ void preparedatabases(DSTATE *s)
        }
 
        if (debug) {
-               printf("db if count: %"PRIu64"\n", s->dbifcount);
+               printf("db if count: %" PRIu64 "\n", s->dbifcount);
        }
 
        if (s->noadd) {
@@ -316,7 +316,7 @@ unsigned int importlegacydbs(DSTATE *s)
        struct dirent *di;
        unsigned int importcount = 0;
 
-       if ((dir=opendir(s->dirname))==NULL) {
+       if ((dir = opendir(s->dirname)) == NULL) {
                printf("Error: Unable to open database directory \"%s\": %s\n", s->dirname, strerror(errno));
                printf("Make sure it exists and is at least read enabled for current user.\n");
                printf("Exiting...\n");
@@ -324,8 +324,8 @@ unsigned int importlegacydbs(DSTATE *s)
        }
 
        s->dbifcount = 0;
-       while ((di=readdir(dir))) {
-               if ((di->d_name[0]!='.') && (strcmp(di->d_name, DATABASEFILE)!=0)) {
+       while ((di = readdir(dir))) {
+               if ((di->d_name[0] != '.') && (strcmp(di->d_name, DATABASEFILE) != 0)) {
                        /* ignore already known interfaces */
                        if (db_getinterfacecountbyname(di->d_name)) {
                                continue;
@@ -515,7 +515,7 @@ int processifinfo(DSTATE *s, datacache **dc)
        if ((*dc)->updated > ifinfo.timestamp) {
                /* skip update if previous update is less than a day in the future */
                /* otherwise exit with error message since the clock is problably messed */
-               if ((*dc)->updated > (ifinfo.timestamp+86400)) {
+               if ((*dc)->updated > (ifinfo.timestamp + 86400)) {
                        snprintf(errorstring, 1024, "Interface \"%s\" has previous update date too much in the future, exiting. (%u / %u)", (*dc)->interface, (unsigned int)(*dc)->updated, (unsigned int)ifinfo.timestamp);
                        printe(PT_Error);
                        errorexitdaemon(s, 1);
@@ -526,7 +526,7 @@ int processifinfo(DSTATE *s, datacache **dc)
        interval = ifinfo.timestamp - (*dc)->updated;
        /* maximum configurable update interval is 5 minutes, limit here is set to 6 minutes (360 seconds) */
        /* in order to be on the safe side and avoid discarding data in case there's some random extra delay */
-       if ( (interval >= 1) && (interval <= 360) ) {
+       if ((interval >= 1) && (interval <= 360)) {
 
                rxchange = countercalc(&(*dc)->currx, &ifinfo.rx, ifinfo.is64bit);
                txchange = countercalc(&(*dc)->curtx, &ifinfo.tx, ifinfo.is64bit);
@@ -538,14 +538,14 @@ int processifinfo(DSTATE *s, datacache **dc)
 
                        /* calculate maximum possible transfer since last update based on set maximum rate */
                        /* and add 10% in order to be on the safe side */
-                       maxtransfer = (uint64_t)(ceilf((maxbw/(float)8)*interval*(float)1.1)) * 1024 * 1024;
+                       maxtransfer = (uint64_t)(ceilf((maxbw / (float)8) * interval * (float)1.1)) * 1024 * 1024;
 
                        if (debug)
-                               printf("interval: %"PRIu64"  maxbw: %"PRIu32"  maxrate: %"PRIu64"  rxc: %"PRIu64"  txc: %"PRIu64"\n", (uint64_t)interval, maxbw, maxtransfer, rxchange, txchange);
+                               printf("interval: %" PRIu64 "  maxbw: %" PRIu32 "  maxrate: %" PRIu64 "  rxc: %" PRIu64 "  txc: %" PRIu64 "\n", (uint64_t)interval, maxbw, maxtransfer, rxchange, txchange);
 
                        /* sync counters if traffic is greater than set maximum */
-                       if ( (rxchange > maxtransfer) || (txchange > maxtransfer) ) {
-                               snprintf(errorstring, 1024, "Traffic rate for \"%s\" higher than set maximum %"PRIu32" Mbit (%"PRIu64"->%"PRIu64", r%"PRIu64" t%"PRIu64"), syncing.", (*dc)->interface, maxbw, (uint64_t)interval, maxtransfer, rxchange, txchange);
+                       if ((rxchange > maxtransfer) || (txchange > maxtransfer)) {
+                               snprintf(errorstring, 1024, "Traffic rate for \"%s\" higher than set maximum %" PRIu32 " Mbit (%" PRIu64 "->%" PRIu64 ", r%" PRIu64 " t%" PRIu64 "), syncing.", (*dc)->interface, maxbw, (uint64_t)interval, maxtransfer, rxchange, txchange);
                                printe(PT_Info);
                                rxchange = txchange = 0;
                        }
@@ -795,11 +795,11 @@ void datacache_status(datacache **dc)
        b = (unsigned int)strlen(buffer) + 1;
 
        while (iterator != NULL) {
-               if ((b+strlen(iterator->interface)+16) < 1020) {
+               if ((b + strlen(iterator->interface) + 16) < 1020) {
                        if (!ibwget(iterator->interface, &bwlimit) || bwlimit == 0) {
                                snprintf(bwtemp, 16, " (no limit) ");
                        } else {
-                               snprintf(bwtemp, 16, " (%"PRIu32" Mbit) ", bwlimit);
+                               snprintf(bwtemp, 16, " (%" PRIu32 " Mbit) ", bwlimit);
                        }
                        strcat(buffer, iterator->interface);
                        strcat(buffer, bwtemp);
@@ -831,7 +831,7 @@ void interfacechangecheck(DSTATE *s)
        timeused(__func__, 1);
 
        /* get list of currently visible interfaces */
-       if (getiflist(&ifacelist, 0)==0) {
+       if (getiflist(&ifacelist, 0) == 0) {
                free(ifacelist);
                s->iflisthash = 0;
                return;
@@ -859,7 +859,7 @@ void interfacechangecheck(DSTATE *s)
                found = offset = 0;
 
                while (offset <= (int)strlen(ifacelist)) {
-                       sscanf(ifacelist+offset, "%31s", interface);
+                       sscanf(ifacelist + offset, "%31s", interface);
                        if (strcmp(iterator->interface, interface) == 0) {
                                found = 1;
                                break;
@@ -916,8 +916,7 @@ uint32_t simplehash(const char *data, int len)
        return hash;
 }
 
-__attribute__((noreturn))
-void errorexitdaemon(DSTATE *s, const int fataldberror)
+__attribute__((noreturn)) void errorexitdaemon(DSTATE *s, const int fataldberror)
 {
        if (!fataldberror) {
                flushcachetodisk(s);
@@ -1016,7 +1015,7 @@ int waittimesync(DSTATE *s)
                        snprintf(errorstring, 1024, "Latest database update is in the future (db: %s > now: %s). Giving the system clock up to %d minutes to sync before continuing.", timestamp2, timestamp, cfg.timesyncwait);
                        printe(PT_Info);
                }
-               if (s->current - s->prevdbupdate >= cfg.timesyncwait*60) {
+               if (s->current - s->prevdbupdate >= cfg.timesyncwait * 60) {
                        strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current));
                        strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave));
                        snprintf(errorstring, 1024, "Latest database update is still in the future (db: %s > now: %s), continuing. Some errors may follow.", timestamp2, timestamp);
index 63804e75ab43caea66b71bbaeb9e430f7317ce47..40c1899edfca4ade11e0e18a66555b3f2d1a0d4f 100644 (file)
@@ -181,7 +181,7 @@ void xferlog_debug(xferlog **log, const int newline)
                printf("  xferlog: ");
        }
        while (logiterator != NULL) {
-               printf("%d: %"PRIu64" - %"PRIu64" / %"PRIu64"", i, (uint64_t)logiterator->timestamp, logiterator->rx, logiterator->tx);
+               printf("%d: %" PRIu64 " - %" PRIu64 " / %" PRIu64 "", i, (uint64_t)logiterator->timestamp, logiterator->rx, logiterator->tx);
                if (logiterator->next != NULL) {
                        printf(", ");
                }
index 680a16792b5698a893766ace98088d500338af49..3f08f51478acfa0ea317ea5fc1b549a8617507e4 100644 (file)
@@ -60,8 +60,8 @@ int insertlegacydata(DATA *data, const char *iface)
        }
 
        for (i = 23; i >= 0; i--) {
-               if (data->hour[i].date > 0 && ( data->hour[i].rx > 0 || data->hour[i].tx > 0 )) {
-                       if (!db_insertdata("hour", iface, data->hour[i].rx*1024, data->hour[i].tx*1024, (uint64_t)data->hour[i].date)) {
+               if (data->hour[i].date > 0 && (data->hour[i].rx > 0 || data->hour[i].tx > 0)) {
+                       if (!db_insertdata("hour", iface, data->hour[i].rx * 1024, data->hour[i].tx * 1024, (uint64_t)data->hour[i].date)) {
                                db_rollbacktransaction();
                                return 0;
                        }
@@ -69,7 +69,7 @@ int insertlegacydata(DATA *data, const char *iface)
        }
        for (i = 29; i >= 0; i--) {
                if (data->day[i].used) {
-                       if (!db_insertdata("day", iface, data->day[i].rx*1024*1024+(uint64_t)data->day[i].rxk*1024, data->day[i].tx*1024*1024+(uint64_t)data->day[i].txk*1024, (uint64_t)data->day[i].date)) {
+                       if (!db_insertdata("day", iface, data->day[i].rx * 1024 * 1024 + (uint64_t)data->day[i].rxk * 1024, data->day[i].tx * 1024 * 1024 + (uint64_t)data->day[i].txk * 1024, (uint64_t)data->day[i].date)) {
                                db_rollbacktransaction();
                                return 0;
                        }
@@ -77,7 +77,7 @@ int insertlegacydata(DATA *data, const char *iface)
        }
        for (i = 11; i >= 0; i--) {
                if (data->month[i].used) {
-                       if (!db_insertdata("month", iface, data->month[i].rx*1024*1024+(uint64_t)data->month[i].rxk*1024, data->month[i].tx*1024*1024+(uint64_t)data->month[i].txk*1024, (uint64_t)data->month[i].month)) {
+                       if (!db_insertdata("month", iface, data->month[i].rx * 1024 * 1024 + (uint64_t)data->month[i].rxk * 1024, data->month[i].tx * 1024 * 1024 + (uint64_t)data->month[i].txk * 1024, (uint64_t)data->month[i].month)) {
                                db_rollbacktransaction();
                                return 0;
                        }
@@ -85,7 +85,7 @@ int insertlegacydata(DATA *data, const char *iface)
        }
        for (i = 9; i >= 0; i--) {
                if (data->top10[i].used) {
-                       if (!db_insertdata("top", iface, data->top10[i].rx*1024*1024+(uint64_t)data->top10[i].rxk*1024, data->top10[i].tx*1024*1024+(uint64_t)data->top10[i].txk*1024, (uint64_t)data->top10[i].date)) {
+                       if (!db_insertdata("top", iface, data->top10[i].rx * 1024 * 1024 + (uint64_t)data->top10[i].rxk * 1024, data->top10[i].tx * 1024 * 1024 + (uint64_t)data->top10[i].txk * 1024, (uint64_t)data->top10[i].date)) {
                                db_rollbacktransaction();
                                return 0;
                        }
@@ -103,11 +103,11 @@ int insertlegacydata(DATA *data, const char *iface)
                }
                stm = localtime(&data->month[i].month);
                /* sanity check for possible invalid data */
-               if (stm->tm_year+1900 <= 1980 || stm->tm_year+1900 >= 2050) {
+               if (stm->tm_year + 1900 <= 1980 || stm->tm_year + 1900 >= 2050) {
                        continue;
                }
-               if (stm->tm_year+1900 != year) {
-                       if (year != 0 && ( rx > 0 || tx > 0 )) {
+               if (stm->tm_year + 1900 != year) {
+                       if (year != 0 && (rx > 0 || tx > 0)) {
                                if (!db_insertdata("year", iface, rx, tx, (uint64_t)yeartime)) {
                                        db_rollbacktransaction();
                                        return 0;
@@ -118,17 +118,17 @@ int insertlegacydata(DATA *data, const char *iface)
                        rx = 0;
                        tx = 0;
                }
-               rx += data->month[i].rx*1024*1024+(uint64_t)data->month[i].rxk*1024;
-               tx += data->month[i].tx*1024*1024+(uint64_t)data->month[i].txk*1024;
+               rx += data->month[i].rx * 1024 * 1024 + (uint64_t)data->month[i].rxk * 1024;
+               tx += data->month[i].tx * 1024 * 1024 + (uint64_t)data->month[i].txk * 1024;
        }
-       if (year != 0 && ( rx > 0 || tx > 0 )) {
+       if (year != 0 && (rx > 0 || tx > 0)) {
                if (!db_insertdata("year", iface, rx, tx, (uint64_t)yeartime)) {
                        db_rollbacktransaction();
                        return 0;
                }
        }
 
-       if (!db_settotal(iface, data->totalrx*1024*1024+(uint64_t)data->totalrxk*1024, data->totaltx*1024*1024+(uint64_t)data->totaltxk*1024)) {
+       if (!db_settotal(iface, data->totalrx * 1024 * 1024 + (uint64_t)data->totalrxk * 1024, data->totaltx * 1024 * 1024 + (uint64_t)data->totaltxk * 1024)) {
                db_rollbacktransaction();
                return 0;
        }
@@ -144,7 +144,7 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
        snprintf(file, 512, "%s/%s", dirname, iface);
        snprintf(backup, 512, "%s/.%s", dirname, iface);
 
-       if ((legacydb=fopen(file,"r"))==NULL) {
+       if ((legacydb = fopen(file, "r")) == NULL) {
                snprintf(errorstring, 1024, "Unable to read database \"%s\": %s", file, strerror(errno));
                printe(PT_Error);
 
@@ -155,8 +155,8 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
                return 1;
        }
 
-       if (fread(data,sizeof(DATA),1,legacydb)!=1 || ferror(legacydb)) {
-               data->version=-1;
+       if (fread(data, sizeof(DATA), 1, legacydb) != 1 || ferror(legacydb)) {
+               data->version = -1;
                if (debug) {
                        printf("db: Database read failed for file \"%s\".\n", file);
                }
@@ -171,7 +171,7 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
 
        if (data->version == LEGACYDBVERSION) {
                if (!validatedb(data) && !force) {
-                       data->version=-1;
+                       data->version = -1;
                        if (debug) {
                                printf("db: Database for interface \"%s\" fails to validate, trying with backup\n", data->interface);
                        }
@@ -179,12 +179,12 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
        }
 
        /* convert old database to new format if necessary */
-       if (data->version<LEGACYDBVERSION) {
-               if (data->version==-1) {
+       if (data->version < LEGACYDBVERSION) {
+               if (data->version == -1) {
 
                        /* close current db and try using backup if database conversion failed */
                        fclose(legacydb);
-                       if ((legacydb=fopen(backup,"r"))==NULL) {
+                       if ((legacydb = fopen(backup, "r")) == NULL) {
                                snprintf(errorstring, 1024, "Unable to open backup database \"%s\": %s", backup, strerror(errno));
                                printe(PT_Error);
                                if (noexit) {
@@ -194,7 +194,7 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
                                }
                        }
 
-                       if (fread(data,sizeof(DATA),1,legacydb)!=1 || ferror(legacydb)) {
+                       if (fread(data, sizeof(DATA), 1, legacydb) != 1 || ferror(legacydb)) {
                                snprintf(errorstring, 1024, "Database load failed even when using backup (%s). Aborting.", strerror(errno));
                                printe(PT_Error);
                                fclose(legacydb);
@@ -215,15 +215,15 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
 
                        if (data->version == LEGACYDBVERSION) {
                                if (!validatedb(data)) {
-                                       data->version=-1;
+                                       data->version = -1;
                                        if (debug) {
                                                printf("db: Backup database for interface \"%s\" fails to validate\n", data->interface);
                                        }
                                }
                        }
 
-                       if (data->version!=LEGACYDBVERSION) {
-                               if (data->version==-1) {
+                       if (data->version != LEGACYDBVERSION) {
+                               if (data->version == -1) {
                                        snprintf(errorstring, 1024, "Unable to use database \"%s\" or its backup.", file);
                                        printe(PT_Error);
                                        fclose(legacydb);
@@ -239,7 +239,7 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
                        printe(PT_Info);
                }
 
-       } else if (data->version>LEGACYDBVERSION) {
+       } else if (data->version > LEGACYDBVERSION) {
                snprintf(errorstring, 1024, "Downgrading database \"%s\" (v%d) is not supported.", file, data->version);
                printe(PT_Error);
                fclose(legacydb);
@@ -253,16 +253,16 @@ int readdb(DATA *data, const char *iface, const char *dirname, const int force)
 
        fclose(legacydb);
 
-       if (strcmp(data->interface,iface)) {
-               snprintf(errorstring, 1024, "Warning:\nThe previous interface for this file was \"%s\".",data->interface);
+       if (strcmp(data->interface, iface)) {
+               snprintf(errorstring, 1024, "Warning:\nThe previous interface for this file was \"%s\".", data->interface);
                printe(PT_Multiline);
-               snprintf(errorstring, 1024, "It has now been replaced with \"%s\".",iface);
+               snprintf(errorstring, 1024, "It has now been replaced with \"%s\".", iface);
                printe(PT_Multiline);
                snprintf(errorstring, 1024, "You can ignore this message if you renamed the filename.");
                printe(PT_Multiline);
                snprintf(errorstring, 1024, "Interface name mismatch, renamed \"%s\" -> \"%s\"", data->interface, iface);
                printe(PT_ShortMultiline);
-               if (strcmp(data->interface, data->nick)==0) {
+               if (strcmp(data->interface, data->nick) == 0) {
                        strncpy_nt(data->nick, iface, 32);
                }
                strncpy_nt(data->interface, iface, 32);
@@ -277,73 +277,73 @@ void initdb(DATA *data)
        time_t current;
        struct tm *d;
 
-       current=time(NULL);
-       d=localtime(&current);
+       current = time(NULL);
+       d = localtime(&current);
 
        /* set default values for a new database */
-       data->version=LEGACYDBVERSION;
-       data->active=1;
-       data->totalrx=0;
-       data->totaltx=0;
-       data->currx=0;
-       data->curtx=0;
-       data->totalrxk=0;
-       data->totaltxk=0;
-       data->lastupdated=current;
-       data->created=current;
+       data->version = LEGACYDBVERSION;
+       data->active = 1;
+       data->totalrx = 0;
+       data->totaltx = 0;
+       data->currx = 0;
+       data->curtx = 0;
+       data->totalrxk = 0;
+       data->totaltxk = 0;
+       data->lastupdated = current;
+       data->created = current;
 
        /* days */
-       for (i=0;i<=29;i++) {
-               data->day[i].rx=0;
-               data->day[i].tx=0;
-               data->day[i].rxk=0;
-               data->day[i].txk=0;
-               data->day[i].date=0;
-               data->day[i].used=0;
+       for (i = 0; i <= 29; i++) {
+               data->day[i].rx = 0;
+               data->day[i].tx = 0;
+               data->day[i].rxk = 0;
+               data->day[i].txk = 0;
+               data->day[i].date = 0;
+               data->day[i].used = 0;
        }
 
        /* months */
-       for (i=0;i<=11;i++) {
-               data->month[i].rx=0;
-               data->month[i].tx=0;
-               data->month[i].rxk=0;
-               data->month[i].txk=0;
-               data->month[i].month=0;
-               data->month[i].used=0;
+       for (i = 0; i <= 11; i++) {
+               data->month[i].rx = 0;
+               data->month[i].tx = 0;
+               data->month[i].rxk = 0;
+               data->month[i].txk = 0;
+               data->month[i].month = 0;
+               data->month[i].used = 0;
        }
 
        /* top10 */
-       for (i=0;i<=9;i++) {
-               data->top10[i].rx=0;
-               data->top10[i].tx=0;
-               data->top10[i].rxk=0;
-               data->top10[i].txk=0;
-               data->top10[i].date=0;
-               data->top10[i].used=0;
+       for (i = 0; i <= 9; i++) {
+               data->top10[i].rx = 0;
+               data->top10[i].tx = 0;
+               data->top10[i].rxk = 0;
+               data->top10[i].txk = 0;
+               data->top10[i].date = 0;
+               data->top10[i].used = 0;
        }
 
        /* hours */
-       for (i=0;i<=23;i++) {
-               data->hour[i].rx=0;
-               data->hour[i].tx=0;
-               data->hour[i].date=0;
+       for (i = 0; i <= 23; i++) {
+               data->hour[i].rx = 0;
+               data->hour[i].tx = 0;
+               data->hour[i].date = 0;
        }
 
-       data->day[0].used=data->month[0].used=1;
-       data->day[0].date=current;
+       data->day[0].used = data->month[0].used = 1;
+       data->day[0].date = current;
 
        /* calculate new date for current month if current day is less
            than the set monthrotate value so that new databases begin
            from the right month */
        if (d->tm_mday < cfg.monthrotate) {
-               d->tm_mday=cfg.monthrotate;
+               d->tm_mday = cfg.monthrotate;
                d->tm_mon--;
-               data->month[0].month=mktime(d);
+               data->month[0].month = mktime(d);
        } else {
-               data->month[0].month=current;
+               data->month[0].month = current;
        }
 
-       data->btime=MAX32;
+       data->btime = MAX32;
 }
 
 int removedb(const char *iface, const char *dirname)
@@ -355,7 +355,7 @@ int removedb(const char *iface, const char *dirname)
        unlink(file);
 
        snprintf(file, 512, "%s/%s", dirname, iface);
-       if (unlink(file)!=0) {
+       if (unlink(file) != 0) {
                return 0;
        }
 
@@ -373,16 +373,16 @@ int validatedb(DATA *data)
        }
 
        /* enforce string termination */
-       data->interface[sizeof(data->interface)-1] = '\0';
-       data->nick[sizeof(data->nick)-1] = '\0';
+       data->interface[sizeof(data->interface) - 1] = '\0';
+       data->nick[sizeof(data->nick) - 1] = '\0';
 
-       if (data->version>LEGACYDBVERSION) {
+       if (data->version > LEGACYDBVERSION) {
                snprintf(errorstring, 1024, "%s: %s version: %d", data->interface, invaliddb, data->version);
                printe(PT_Error);
                return 0;
        }
 
-       if (data->active<0 || data->active>1) {
+       if (data->active < 0 || data->active > 1) {
                snprintf(errorstring, 1024, "%s: %s activity status: %d", data->interface, invaliddb, data->active);
                printe(PT_Error);
                return 0;
@@ -402,13 +402,13 @@ int validatedb(DATA *data)
 
        rxsum = txsum = 0;
        used = 1;
-       for (i=0; i<30; i++) {
-               if (data->day[i].used<0 || data->day[i].used>1) {
+       for (i = 0; i < 30; i++) {
+               if (data->day[i].used < 0 || data->day[i].used > 1) {
                        snprintf(errorstring, 1024, "%s: %s daily use information: %d %d", data->interface, invaliddb, i, data->day[i].used);
                        printe(PT_Error);
                        return 0;
                }
-               if (data->day[i].rxk<0 || data->day[i].txk<0) {
+               if (data->day[i].rxk < 0 || data->day[i].txk < 0) {
                        snprintf(errorstring, 1024, "%s: %s daily traffic: %d", data->interface, invaliddb, i);
                        printe(PT_Error);
                        return 0;
@@ -426,12 +426,12 @@ int validatedb(DATA *data)
                }
        }
 
-       for (i=1; i<30; i++) {
+       for (i = 1; i < 30; i++) {
                if (!data->day[i].used) {
                        break;
                }
-               if (data->day[i-1].date < data->day[i].date) {
-                       snprintf(errorstring, 1024, "%s: %s daily date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->day[i-1].date, i-1, (unsigned int)data->day[i].date, i);
+               if (data->day[i - 1].date < data->day[i].date) {
+                       snprintf(errorstring, 1024, "%s: %s daily date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->day[i - 1].date, i - 1, (unsigned int)data->day[i].date, i);
                        printe(PT_Error);
                        return 0;
                }
@@ -445,13 +445,13 @@ int validatedb(DATA *data)
 
        rxsum = txsum = 0;
        used = 1;
-       for (i=0; i<12; i++) {
-               if (data->month[i].used<0 || data->month[i].used>1) {
+       for (i = 0; i < 12; i++) {
+               if (data->month[i].used < 0 || data->month[i].used > 1) {
                        snprintf(errorstring, 1024, "%s: %s monthly use information: %d %d", data->interface, invaliddb, i, data->month[i].used);
                        printe(PT_Error);
                        return 0;
                }
-               if (data->month[i].rxk<0 || data->month[i].txk<0) {
+               if (data->month[i].rxk < 0 || data->month[i].txk < 0) {
                        snprintf(errorstring, 1024, "%s: %s monthly traffic: %d", data->interface, invaliddb, i);
                        printe(PT_Error);
                        return 0;
@@ -469,12 +469,12 @@ int validatedb(DATA *data)
                }
        }
 
-       for (i=1; i<12; i++) {
+       for (i = 1; i < 12; i++) {
                if (!data->month[i].used) {
                        break;
                }
-               if (data->month[i-1].month < data->month[i].month) {
-                       snprintf(errorstring, 1024, "%s: %s monthly date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->month[i-1].month, i-1, (unsigned int)data->month[i].month, i);
+               if (data->month[i - 1].month < data->month[i].month) {
+                       snprintf(errorstring, 1024, "%s: %s monthly date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->month[i - 1].month, i - 1, (unsigned int)data->month[i].month, i);
                        printe(PT_Error);
                        return 0;
                }
@@ -487,13 +487,13 @@ int validatedb(DATA *data)
        }
 
        used = 1;
-       for (i=0; i<10; i++) {
-               if (data->top10[i].used<0 || data->top10[i].used>1) {
+       for (i = 0; i < 10; i++) {
+               if (data->top10[i].used < 0 || data->top10[i].used > 1) {
                        snprintf(errorstring, 1024, "%s: %s top10 use information: %d %d", data->interface, invaliddb, i, data->top10[i].used);
                        printe(PT_Error);
                        return 0;
                }
-               if (data->top10[i].rxk<0 || data->top10[i].txk<0) {
+               if (data->top10[i].rxk < 0 || data->top10[i].txk < 0) {
                        snprintf(errorstring, 1024, "%s: %s top10 traffic: %d", data->interface, invaliddb, i);
                        printe(PT_Error);
                        return 0;
index e84a8d411274832585959bffe215206f1be97884..40a93b43fe181892044a97c21e7a3c0761a50c49 100644 (file)
@@ -10,8 +10,8 @@
 /* from the legacy database format => don't modify  */
 
 #if defined(__clang__)
-  #pragma clang diagnostic push
-  #pragma clang diagnostic ignored "-Wpadded"
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
 #endif
 typedef struct {
        time_t date;
@@ -48,7 +48,7 @@ typedef struct {
        uint64_t btime;
 } DATA;
 #if defined(__clang__)
-  #pragma clang diagnostic pop
+#pragma clang diagnostic pop
 #endif
 
 int importlegacydb(const char *iface, const char *dirname);
index 07d77c696a5571baf6e75192cf913662a3941c10..757a732cc65f175d828132d6bd0f18a7a19580b6 100644 (file)
@@ -31,7 +31,7 @@ void showjson(const char *interface, const int ifcount, const char mode, const c
        printf("},");
 
        printf("\"traffic\":");
-       printf("{\"total\":{\"rx\":%"PRIu64",\"tx\":%"PRIu64"},", info.rxtotal, info.txtotal);
+       printf("{\"total\":{\"rx\":%" PRIu64 ",\"tx\":%" PRIu64 "},", info.rxtotal, info.txtotal);
 
        switch (mode) {
                case 'd':
@@ -92,9 +92,9 @@ void jsondump(const interfaceinfo *interface, const char *tablename, const int d
                } else {
                        first = 0;
                }
-               printf("{\"id\":%"PRId64",", datalist_i->rowid);
+               printf("{\"id\":%" PRId64 ",", datalist_i->rowid);
                jsondate(&datalist_i->timestamp, datetype);
-               printf(",\"rx\":%"PRIu64",\"tx\":%"PRIu64"}", datalist_i->rx, datalist_i->tx);
+               printf(",\"rx\":%" PRIu64 ",\"tx\":%" PRIu64 "}", datalist_i->rx, datalist_i->tx);
                datalist_i = datalist_i->next;
        }
        dbdatalistfree(&datalist);
@@ -109,20 +109,20 @@ void jsondate(const time_t *date, const int type)
 
        switch (type) {
                case 1:
-                       printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d}", \
-                                       1900+d->tm_year, 1+d->tm_mon, d->tm_mday);
+                       printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d}",
+                                  1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday);
                        break;
                case 2:
-                       printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d},\"time\":{\"hour\":%d,\"minute\":%d}", \
-                                       1900+d->tm_year, 1+d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
+                       printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d},\"time\":{\"hour\":%d,\"minute\":%d}",
+                                  1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
                        break;
                case 3:
-                       printf("\"date\":{\"year\":%d,\"month\":%d}", \
-                                       1900+d->tm_year, 1+d->tm_mon);
+                       printf("\"date\":{\"year\":%d,\"month\":%d}",
+                                  1900 + d->tm_year, 1 + d->tm_mon);
                        break;
                case 4:
-                       printf("\"date\":{\"year\":%d}", \
-                                       1900+d->tm_year);
+                       printf("\"date\":{\"year\":%d}",
+                                  1900 + d->tm_year);
                        break;
                default:
                        break;
index 4d2350fb92dc30fc9139c8696c79e4431d2101ba..5c42438869f5cd7ff6ffe38831b7177c7577feb4 100644 (file)
@@ -20,7 +20,7 @@ void showdb(const char *interface, int qmode, const char *databegin, const char
                return;
        }
 
-       switch(qmode) {
+       switch (qmode) {
                case 0:
                        showsummary(&info, 0);
                        break;
@@ -70,10 +70,10 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
 
        timeused(__func__, 1);
 
-       current=time(NULL);
-       yesterday=current-86400;
+       current = time(NULL);
+       yesterday = current - 86400;
 
-       e_rx=e_tx=0;
+       e_rx = e_tx = 0;
 
        if (interface->updated && !shortmode) {
                strftime(datebuff, DATEBUFFLEN, DATETIMEFORMAT, localtime(&interface->updated));
@@ -101,7 +101,7 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
                printf(":\n");
        } else {
                /* get formatted date for creation date */
-               d=localtime(&interface->created);
+               d = localtime(&interface->created);
                strftime(datebuff, DATEBUFFLEN, cfg.tformat, d);
                printf(" since %s\n\n", datebuff);
 
@@ -110,7 +110,7 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
                indent(3);
                printf("   tx:  %s", getvalue(interface->txtotal, 1, RT_Normal));
                indent(3);
-               printf("   total:  %s\n\n", getvalue(interface->rxtotal+interface->txtotal, 1, RT_Normal));
+               printf("   total:  %s\n\n", getvalue(interface->rxtotal + interface->txtotal, 1, RT_Normal));
 
                indent(3);
                printf("monthly\n");
@@ -137,28 +137,28 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
        while (datalist_i != NULL) {
                indent(5);
                d = localtime(&datalist_i->timestamp);
-               if (strftime(datebuff, DATEBUFFLEN, cfg.mformat, d)<=8) {
+               if (strftime(datebuff, DATEBUFFLEN, cfg.mformat, d) <= 8) {
                        printf("%*s   %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
                } else {
                        printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
                }
                printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal));
-               printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
+               printf("%s%s", fieldseparator, getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal));
                if (cfg.ostyle >= 2) {
                        if (datalist_i->next == NULL) {
-                               if ( datalist_i->rx == 0 || datalist_i->tx == 0 || (interface->updated-datalist_i->timestamp) == 0 ) {
+                               if (datalist_i->rx == 0 || datalist_i->tx == 0 || (interface->updated - datalist_i->timestamp) == 0) {
                                        e_rx = e_tx = 0;
                                } else {
-                                       e_rx = (uint64_t)(datalist_i->rx/(float)(mosecs(datalist_i->timestamp, interface->updated)))*(uint64_t)(dmonth(d->tm_mon)*86400);
-                                       e_tx = (uint64_t)(datalist_i->tx/(float)(mosecs(datalist_i->timestamp, interface->updated)))*(uint64_t)(dmonth(d->tm_mon)*86400);
+                                       e_rx = (uint64_t)(datalist_i->rx / (float)(mosecs(datalist_i->timestamp, interface->updated))) * (uint64_t)(dmonth(d->tm_mon) * 86400);
+                                       e_tx = (uint64_t)(datalist_i->tx / (float)(mosecs(datalist_i->timestamp, interface->updated))) * (uint64_t)(dmonth(d->tm_mon) * 86400);
                                }
                                if (shortmode && cfg.ostyle != 0) {
-                                       printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, RT_Estimate));
+                                       printf("%s%s", fieldseparator, getvalue(e_rx + e_tx, 11, RT_Estimate));
                                } else if (!shortmode) {
-                                       printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx+datalist_i->tx, mosecs(datalist_i->timestamp, interface->updated), 14));
+                                       printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx + datalist_i->tx, mosecs(datalist_i->timestamp, interface->updated), 14));
                                }
                        } else if (!shortmode) {
-                               printf(" | %s", gettrafficrate(datalist_i->rx+datalist_i->tx, dmonth(d->tm_mon)*86400, 14));
+                               printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, dmonth(d->tm_mon) * 86400, 14));
                        }
                }
                printf("\n");
@@ -175,7 +175,7 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
                indent(5);
                printf("estimated   %s", getvalue(e_rx, 11, RT_Estimate));
                printf(" | %s", getvalue(e_tx, 11, RT_Estimate));
-               printf(" | %s", getvalue(e_rx+e_tx, 11, RT_Estimate));
+               printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate));
                if (cfg.ostyle >= 2) {
                        printf(" |\n\n");
                } else {
@@ -230,23 +230,23 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
                        printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
                }
                printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal));
-               printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
+               printf("%s%s", fieldseparator, getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal));
                if (cfg.ostyle >= 2) {
                        if (datalist_i->next == NULL) {
                                d = localtime(&interface->updated);
-                               if ( datalist_i->rx == 0 || datalist_i->tx == 0 || (d->tm_hour*60+d->tm_min) == 0 ) {
+                               if (datalist_i->rx == 0 || datalist_i->tx == 0 || (d->tm_hour * 60 + d->tm_min) == 0) {
                                        e_rx = e_tx = 0;
                                } else {
-                                       e_rx = (uint64_t)((datalist_i->rx)/(float)(d->tm_hour*60+d->tm_min))*1440;
-                                       e_tx = (uint64_t)((datalist_i->tx)/(float)(d->tm_hour*60+d->tm_min))*1440;
+                                       e_rx = (uint64_t)((datalist_i->rx) / (float)(d->tm_hour * 60 + d->tm_min)) * 1440;
+                                       e_tx = (uint64_t)((datalist_i->tx) / (float)(d->tm_hour * 60 + d->tm_min)) * 1440;
                                }
                                if (shortmode && cfg.ostyle != 0) {
-                                       printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, RT_Estimate));
+                                       printf("%s%s", fieldseparator, getvalue(e_rx + e_tx, 11, RT_Estimate));
                                } else if (!shortmode) {
-                                       printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx+datalist_i->tx, d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600), 14));
+                                       printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx + datalist_i->tx, d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600), 14));
                                }
                        } else if (!shortmode) {
-                               printf(" | %s", gettrafficrate(datalist_i->rx+datalist_i->tx, 86400, 14));
+                               printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, 86400, 14));
                        }
                }
                printf("\n");
@@ -263,7 +263,7 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
                indent(5);
                printf("estimated   %s", getvalue(e_rx, 11, RT_Estimate));
                printf(" | %s", getvalue(e_tx, 11, RT_Estimate));
-               printf(" | %s", getvalue(e_rx+e_tx, 11, RT_Estimate));
+               printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate));
                if (cfg.ostyle >= 2) {
                        printf(" |\n");
                } else {
@@ -444,26 +444,26 @@ void showlist(const interfaceinfo *interface, const char *listname, const char *
                        }
                }
 
-               if (strlen(datebuff)<=9 && listtype != 4) {
+               if (strlen(datebuff) <= 9 && listtype != 4) {
                        printf(" %*s   %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
                } else {
                        printf(" %-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
                }
                printf(" | %s", getvalue(datalist_i->tx, 11, RT_Normal));
-               printf(" | %s", getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
+               printf(" | %s", getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal));
                if (cfg.ostyle == 3) {
                        if (datalist_i->next == NULL) {
                                d = localtime(&interface->updated);
                                if (listtype == 1) { // day
-                                       e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+                                       e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
                                } else if (listtype == 2) { // month
                                        e_secs = (uint64_t)mosecs(datalist_i->timestamp, interface->updated);
                                } else if (listtype == 3) { // year
-                                       e_secs = (uint64_t)(d->tm_yday*86400+d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+                                       e_secs = (uint64_t)(d->tm_yday * 86400 + d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
                                } else if (listtype == 4) { // top
                                        e_secs = 86400;
                                } else if (listtype == 5) { // hour
-                                       e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60));
+                                       e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60));
                                } else if (listtype == 6) { // 5min
                                        e_secs = 300;
                                }
@@ -473,16 +473,16 @@ void showlist(const interfaceinfo *interface, const char *listname, const char *
                                } else if (listtype == 2) { // month
                                        e_secs = (uint64_t)(dmonth(d->tm_mon) * 86400);
                                } else if (listtype == 3) { // year
-                                       e_secs = (uint64_t)((365 + isleapyear(d->tm_year+1900)) * 86400);
+                                       e_secs = (uint64_t)((365 + isleapyear(d->tm_year + 1900)) * 86400);
                                } else if (listtype == 5) { // hour
                                        e_secs = 3600;
                                } else if (listtype == 6) { // 5min
                                        e_secs = 300;
                                }
                        }
-                       printf(" | %s", gettrafficrate(datalist_i->rx+datalist_i->tx, (time_t)e_secs, 14));
+                       printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, (time_t)e_secs, 14));
                } else if (cfg.ostyle != 0) {
-                       showbar(datalist_i->rx, datalist_i->tx, datainfo.max, 24-offset);
+                       showbar(datalist_i->rx, datalist_i->tx, datainfo.max, 24 - offset);
                }
                printf("\n");
                if (datalist_i->next == NULL) {
@@ -521,7 +521,7 @@ void showlist(const interfaceinfo *interface, const char *listname, const char *
        if ((strlen(dataend) == 0 && datainfo.count > 0 && listtype < 4) || (strlen(dataend) > 0 && datainfo.count > 1 && listtype != 4)) {
                /* use database update time for estimates */
                d = localtime(&interface->updated);
-               if ( datalist_i->rx==0 || datalist_i->tx==0 || strlen(dataend)>0 ) {
+               if (datalist_i->rx == 0 || datalist_i->tx == 0 || strlen(dataend) > 0) {
                        e_rx = e_tx = 0;
                } else {
                        div = 0;
@@ -552,7 +552,7 @@ void showlist(const interfaceinfo *interface, const char *listname, const char *
                        printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate));
                } else {
                        if (datainfo.count < 100) {
-                               snprintf(datebuff, DATEBUFFLEN, "sum of %"PRIu32"", datainfo.count);
+                               snprintf(datebuff, DATEBUFFLEN, "sum of %" PRIu32 "", datainfo.count);
                        } else {
                                snprintf(datebuff, DATEBUFFLEN, "sum");
                        }
@@ -607,19 +607,19 @@ void showoneline(const interfaceinfo *interface)
 
                /* daily */
                if (cfg.ostyle == 4) {
-                       printf("%"PRIu64";", datalist->rx);
-                       printf("%"PRIu64";", datalist->tx);
-                       printf("%"PRIu64";", datalist->rx+datalist->tx);
-                       div = (uint64_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+                       printf("%" PRIu64 ";", datalist->rx);
+                       printf("%" PRIu64 ";", datalist->tx);
+                       printf("%" PRIu64 ";", datalist->rx + datalist->tx);
+                       div = (uint64_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
                        if (!div) {
                                div = 1;
                        }
-                       printf("%"PRIu64";", (datalist->rx+datalist->tx)/div);
+                       printf("%" PRIu64 ";", (datalist->rx + datalist->tx) / div);
                } else {
                        printf("%s;", getvalue(datalist->rx, 1, RT_Normal));
                        printf("%s;", getvalue(datalist->tx, 1, RT_Normal));
-                       printf("%s;", getvalue(datalist->rx+datalist->tx, 1, RT_Normal));
-                       printf("%s;", gettrafficrate(datalist->rx+datalist->tx, (time_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600)), 1));
+                       printf("%s;", getvalue(datalist->rx + datalist->tx, 1, RT_Normal));
+                       printf("%s;", gettrafficrate(datalist->rx + datalist->tx, (time_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600)), 1));
                }
        } else {
                printf(";;;;;");
@@ -638,19 +638,19 @@ void showoneline(const interfaceinfo *interface)
 
                /* monthly */
                if (cfg.ostyle == 4) {
-                       printf("%"PRIu64";", datalist->rx);
-                       printf("%"PRIu64";", datalist->tx);
-                       printf("%"PRIu64";", datalist->rx+datalist->tx);
+                       printf("%" PRIu64 ";", datalist->rx);
+                       printf("%" PRIu64 ";", datalist->tx);
+                       printf("%" PRIu64 ";", datalist->rx + datalist->tx);
                        div = (uint64_t)(mosecs(datalist->timestamp, interface->updated));
                        if (!div) {
                                div = 1;
                        }
-                       printf("%"PRIu64";", (datalist->rx+datalist->tx)/div);
+                       printf("%" PRIu64 ";", (datalist->rx + datalist->tx) / div);
                } else {
                        printf("%s;", getvalue(datalist->rx, 1, RT_Normal));
                        printf("%s;", getvalue(datalist->tx, 1, RT_Normal));
-                       printf("%s;", getvalue(datalist->rx+datalist->tx, 1, RT_Normal));
-                       printf("%s;", gettrafficrate(datalist->rx+datalist->tx, mosecs(datalist->timestamp, interface->updated), 1));
+                       printf("%s;", getvalue(datalist->rx + datalist->tx, 1, RT_Normal));
+                       printf("%s;", gettrafficrate(datalist->rx + datalist->tx, mosecs(datalist->timestamp, interface->updated), 1));
                }
        } else {
                printf(";;;;;");
@@ -659,22 +659,22 @@ void showoneline(const interfaceinfo *interface)
 
        /* all time total */
        if (cfg.ostyle == 4) {
-               printf("%"PRIu64";", interface->rxtotal);
-               printf("%"PRIu64";", interface->txtotal);
-               printf("%"PRIu64"\n", interface->rxtotal+interface->txtotal);
+               printf("%" PRIu64 ";", interface->rxtotal);
+               printf("%" PRIu64 ";", interface->txtotal);
+               printf("%" PRIu64 "\n", interface->rxtotal + interface->txtotal);
        } else {
                printf("%s;", getvalue(interface->rxtotal, 1, RT_Normal));
                printf("%s;", getvalue(interface->txtotal, 1, RT_Normal));
-               printf("%s\n", getvalue(interface->rxtotal+interface->txtotal, 1, RT_Normal));
+               printf("%s\n", getvalue(interface->rxtotal + interface->txtotal, 1, RT_Normal));
        }
        timeused(__func__, 0);
 }
 
 void showhours(const interfaceinfo *interface)
 {
-       int i, s=0, hour, minute, declen=cfg.hourlydecimals, div=1;
-       unsigned int j, k, tmax=0, dots=0;
-       uint64_t max=1;
+       int i, s = 0, hour, minute, declen = cfg.hourlydecimals, div = 1;
+       unsigned int j, k, tmax = 0, dots = 0;
+       uint64_t max = 1;
        char matrix[24][81]; /* width is one over 80 so that snprintf can write the end char */
        char unit[4];
        struct tm *d;
@@ -684,7 +684,7 @@ void showhours(const interfaceinfo *interface)
 
        timeused(__func__, 1);
 
-       for (i=0; i<24; i++) {
+       for (i = 0; i < 24; i++) {
                hourdata[i].rx = hourdata[i].tx = 0;
                hourdata[i].date = 0;
        }
@@ -702,7 +702,7 @@ void showhours(const interfaceinfo *interface)
 
        while (datalist_i != NULL) {
                d = localtime(&datalist_i->timestamp);
-               if (hourdata[d->tm_hour].date != 0 || interface->updated-datalist_i->timestamp > 86400) {
+               if (hourdata[d->tm_hour].date != 0 || interface->updated - datalist_i->timestamp > 86400) {
                        datalist_i = datalist_i->next;
                        continue;
                }
@@ -720,7 +720,7 @@ void showhours(const interfaceinfo *interface)
        hour = d->tm_hour;
        minute = d->tm_min;
 
-       for (i=0; i<24; i++) {
+       for (i = 0; i < 24; i++) {
                if (hourdata[i].date >= hourdata[tmax].date) {
                        tmax = (unsigned int)i;
                }
@@ -733,34 +733,34 @@ void showhours(const interfaceinfo *interface)
        }
 
        /* mr. proper */
-       for (i=0; i<24; i++) {
-               for (j=0; j<81; j++) {
+       for (i = 0; i < 24; i++) {
+               for (j = 0; j < 81; j++) {
                        matrix[i][j] = ' ';
                }
        }
 
        /* unit selection */
-       while (max/(pow(1024, div)) >= 100 && div < UNITPREFIXCOUNT) {
+       while (max / (pow(1024, div)) >= 100 && div < UNITPREFIXCOUNT) {
                div++;
        }
        strncpy_nt(unit, getunitprefix(div), 4);
-       div = (int)(pow(1024, div-1));
+       div = (int)(pow(1024, div - 1));
        if (div == 1) {
                declen = 0;
        }
 
        /* structure */
        snprintf(matrix[11], 81, " -+--------------------------------------------------------------------------->");
-       for (i=0; i<3; i++) {
-               snprintf(matrix[14]+(i*28), 14, " h %*srx (%s)", 1+cfg.unitmode, " ", unit);
-               snprintf(matrix[14]+(i*28)+15+cfg.unitmode, 10, "tx (%s)", unit);
+       for (i = 0; i < 3; i++) {
+               snprintf(matrix[14] + (i * 28), 14, " h %*srx (%s)", 1 + cfg.unitmode, " ", unit);
+               snprintf(matrix[14] + (i * 28) + 15 + cfg.unitmode, 10, "tx (%s)", unit);
        }
 
-       for (i=10;i>1;i--)
-               matrix[i][2]='|';
+       for (i = 10; i > 1; i--)
+               matrix[i][2] = '|';
 
-       matrix[1][2]='^';
-       matrix[12][2]='|';
+       matrix[1][2] = '^';
+       matrix[12][2] = '|';
 
        /* title */
        if (strcmp(interface->name, interface->alias) == 0 || strlen(interface->alias) == 0) {
@@ -769,63 +769,63 @@ void showhours(const interfaceinfo *interface)
                i = snprintf(matrix[0], 81, " %s (%s)", interface->alias, interface->name);
        }
        if (interface->active == 0) {
-               snprintf(matrix[0]+i+1, 81, " [disabled]");
+               snprintf(matrix[0] + i + 1, 81, " [disabled]");
        }
 
        /* time to the corner */
-       snprintf(matrix[0]+74, 7, "%02d:%02d", hour, minute);
+       snprintf(matrix[0] + 74, 7, "%02d:%02d", hour, minute);
 
        /* numbers under x-axis and graphics :) */
        k = 5;
-       for (i=23; i>=0; i--) {
+       for (i = 23; i >= 0; i--) {
                s = (int)tmax - i;
                if (s < 0)
                        s += 24;
 
-               snprintf(matrix[12]+k, 81-k, "%02d ", s);
+               snprintf(matrix[12] + k, 81 - k, "%02d ", s);
 
                dots = (unsigned int)(10 * (hourdata[s].rx / (float)max));
-               for (j=0; j<dots; j++)
-                       matrix[10-j][k] = cfg.rxhourchar[0];
+               for (j = 0; j < dots; j++)
+                       matrix[10 - j][k] = cfg.rxhourchar[0];
 
                dots = (unsigned int)(10 * (hourdata[s].tx / (float)max));
-               for (j=0; j<dots; j++)
-                       matrix[10-j][k+1] = cfg.txhourchar[0];
+               for (j = 0; j < dots; j++)
+                       matrix[10 - j][k + 1] = cfg.txhourchar[0];
 
                k = k + 3;
        }
 
        /* hours and traffic */
-       for (i=0; i<=7; i++) {
+       for (i = 0; i <= 7; i++) {
                s = (int)tmax + i + 1;
-               for (j=0; j<3; j++) {
-                       snprintf(matrix[15+i]+(j*28), 25, "%02d %"DECCONV"10.*f %"DECCONV"10.*f", \
-                       ((unsigned int)s+(j*8))%24, declen, hourdata[((unsigned int)s+(j*8))%24].rx/(double)div, \
-                                                                               declen, hourdata[((unsigned int)s+(j*8))%24].tx/(double)div);
+               for (j = 0; j < 3; j++) {
+                       snprintf(matrix[15 + i] + (j * 28), 25, "%02d %" DECCONV "10.*f %" DECCONV "10.*f",
+                                        ((unsigned int)s + (j * 8)) % 24, declen, hourdata[((unsigned int)s + (j * 8)) % 24].rx / (double)div,
+                                        declen, hourdata[((unsigned int)s + (j * 8)) % 24].tx / (double)div);
                }
        }
 
        /* section separators */
        if (cfg.hourlystyle) {
-               for (i=0;i<9;i++) {
+               for (i = 0; i < 9; i++) {
                        if (cfg.hourlystyle == 1) {
-                               matrix[14+i][26]='|';
-                               matrix[14+i][54]='|';
+                               matrix[14 + i][26] = '|';
+                               matrix[14 + i][54] = '|';
                        } else if (cfg.hourlystyle == 2) {
-                               matrix[14+i][25]=']';
-                               matrix[14+i][26]='[';
-                               matrix[14+i][53]=']';
-                               matrix[14+i][54]='[';
+                               matrix[14 + i][25] = ']';
+                               matrix[14 + i][26] = '[';
+                               matrix[14 + i][53] = ']';
+                               matrix[14 + i][54] = '[';
                        } else if (cfg.hourlystyle == 3) {
-                               matrix[14+i][26]='[';
-                               matrix[14+i][53]=']';
+                               matrix[14 + i][26] = '[';
+                               matrix[14 + i][53] = ']';
                        }
                }
        }
 
        /* clean \0 */
-       for (i=0; i<23; i++) {
-               for (j=0; j<80; j++) {
+       for (i = 0; i < 23; i++) {
+               for (j = 0; j < 80; j++) {
                        if (matrix[i][j] == '\0') {
                                matrix[i][j] = ' ';
                        }
@@ -833,9 +833,9 @@ void showhours(const interfaceinfo *interface)
        }
 
        /* show matrix (yes, the last line isn't shown) */
-       for (i=0; i<23; i++) {
-               for (j=0; j<80; j++) {
-                       printf("%c",matrix[i][j]);
+       for (i = 0; i < 23; i++) {
+               for (j = 0; j < 80; j++) {
+                       printf("%c", matrix[i][j]);
                }
                printf("\n");
        }
@@ -846,8 +846,8 @@ int showbar(const uint64_t rx, const uint64_t tx, const uint64_t max, const int
 {
        int i, l, width = len;
 
-       if ( (rx + tx) < max) {
-               width = (int)( ((rx + tx) / (float)max) * len );
+       if ((rx + tx) < max) {
+               width = (int)(((rx + tx) / (float)max) * len);
        } else if ((rx + tx) > max || max == 0) {
                return 0;
        }
@@ -859,21 +859,21 @@ int showbar(const uint64_t rx, const uint64_t tx, const uint64_t max, const int
        printf("  ");
 
        if (tx > rx) {
-               l = (int)(rintf((rx/(float)(rx+tx)*width)));
+               l = (int)(rintf((rx / (float)(rx + tx) * width)));
 
-               for (i=0; i<l; i++) {
+               for (i = 0; i < l; i++) {
                        printf("%c", cfg.rxchar[0]);
                }
-               for (i=0; i<(width-l); i++) {
+               for (i = 0; i < (width - l); i++) {
                        printf("%c", cfg.txchar[0]);
                }
        } else {
-               l = (int)(rintf((tx/(float)(rx+tx)*width)));
+               l = (int)(rintf((tx / (float)(rx + tx) * width)));
 
-               for (i=0; i<(width-l); i++) {
+               for (i = 0; i < (width - l); i++) {
                        printf("%c", cfg.rxchar[0]);
                }
-               for (i=0; i<l; i++) {
+               for (i = 0; i < l; i++) {
                        printf("%c", cfg.txchar[0]);
                }
        }
index a2580403744268ac4f826e0b3ce351addc29e2be..e25c91fc49c36795c723eec8eb1e9894ccf0c47b 100644 (file)
@@ -92,7 +92,6 @@ int db_open(const int createifnotfound, const int readonly)
                                return 0;
                        }
                }
-
        }
 
        /* set pragmas */
@@ -255,42 +254,43 @@ int db_create(void)
                return 0;
        }
 
-       sql = "CREATE TABLE info(\n" \
-               "  id       INTEGER PRIMARY KEY,\n" \
-               "  name     TEXT UNIQUE NOT NULL,\n" \
-               "  value    TEXT NOT NULL)";
+       sql = "CREATE TABLE info(\n"
+                 "  id       INTEGER PRIMARY KEY,\n"
+                 "  name     TEXT UNIQUE NOT NULL,\n"
+                 "  value    TEXT NOT NULL)";
 
        if (!db_exec(sql)) {
                db_rollbacktransaction();
                return 0;
        }
 
-       sql = "CREATE TABLE interface(\n" \
-               "  id           INTEGER PRIMARY KEY,\n" \
-               "  name         TEXT UNIQUE NOT NULL,\n" \
-               "  alias        TEXT,\n" \
-               "  active       INTEGER NOT NULL,\n" \
-               "  created      DATE NOT NULL,\n" \
-               "  updated      DATE NOT NULL,\n" \
-               "  rxcounter    INTEGER NOT NULL,\n" \
-               "  txcounter    INTEGER NOT NULL,\n" \
-               "  rxtotal      INTEGER NOT NULL,\n" \
-               "  txtotal      INTEGER NOT NULL)";
+       sql = "CREATE TABLE interface(\n"
+                 "  id           INTEGER PRIMARY KEY,\n"
+                 "  name         TEXT UNIQUE NOT NULL,\n"
+                 "  alias        TEXT,\n"
+                 "  active       INTEGER NOT NULL,\n"
+                 "  created      DATE NOT NULL,\n"
+                 "  updated      DATE NOT NULL,\n"
+                 "  rxcounter    INTEGER NOT NULL,\n"
+                 "  txcounter    INTEGER NOT NULL,\n"
+                 "  rxtotal      INTEGER NOT NULL,\n"
+                 "  txtotal      INTEGER NOT NULL)";
 
        if (!db_exec(sql)) {
                db_rollbacktransaction();
                return 0;
        }
 
-       sql = malloc(sizeof(char)*512);
-       for (i=0; i<6; i++) {
-               sqlite3_snprintf(512, sql, "CREATE TABLE %s(\n" \
-                       "  id           INTEGER PRIMARY KEY,\n" \
-                       "  interface    INTEGER REFERENCES interface(id) ON DELETE CASCADE,\n" \
-                       "  date         DATE NOT NULL,\n" \
-                       "  rx           INTEGER NOT NULL,\n" \
-                       "  tx           INTEGER NOT NULL,\n" \
-                       "  CONSTRAINT u UNIQUE (interface, date))", datatables[i]);
+       sql = malloc(sizeof(char) * 512);
+       for (i = 0; i < 6; i++) {
+               sqlite3_snprintf(512, sql, "CREATE TABLE %s(\n"
+                                                                  "  id           INTEGER PRIMARY KEY,\n"
+                                                                  "  interface    INTEGER REFERENCES interface(id) ON DELETE CASCADE,\n"
+                                                                  "  date         DATE NOT NULL,\n"
+                                                                  "  rx           INTEGER NOT NULL,\n"
+                                                                  "  tx           INTEGER NOT NULL,\n"
+                                                                  "  CONSTRAINT u UNIQUE (interface, date))",
+                                                datatables[i]);
 
                if (!db_exec(sql)) {
                        free(sql);
@@ -300,7 +300,7 @@ int db_create(void)
        }
        free(sql);
 
-       snprintf(buffer, 32, "%"PRIu64"", (uint64_t)MAX32);
+       snprintf(buffer, 32, "%" PRIu64 "", (uint64_t)MAX32);
        if (!db_setinfo("btime", buffer, 1)) {
                db_rollbacktransaction();
                return 0;
@@ -331,7 +331,7 @@ int db_removeinterface(const char *iface)
                return 0;
        }
 
-       sqlite3_snprintf(64, sql, "delete from interface where id=%"PRId64"", (int64_t)ifaceid);
+       sqlite3_snprintf(64, sql, "delete from interface where id=%" PRId64 "", (int64_t)ifaceid);
        return db_exec(sql);
 }
 
@@ -458,7 +458,7 @@ int db_setactive(const char *iface, const int active)
                return 0;
        }
 
-       sqlite3_snprintf(64, sql, "update interface set active=%d where id=%"PRId64"", active, (int64_t)ifaceid);
+       sqlite3_snprintf(64, sql, "update interface set active=%d where id=%" PRId64 "", active, (int64_t)ifaceid);
        return db_exec(sql);
 }
 
@@ -472,7 +472,7 @@ int db_setupdated(const char *iface, const time_t timestamp)
                return 0;
        }
 
-       sqlite3_snprintf(256, sql, "update interface set updated=datetime(%"PRIu64", 'unixepoch', 'localtime') where id=%"PRId64"", (uint64_t)timestamp, (int64_t)ifaceid);
+       sqlite3_snprintf(256, sql, "update interface set updated=datetime(%" PRIu64 ", 'unixepoch', 'localtime') where id=%" PRId64 "", (uint64_t)timestamp, (int64_t)ifaceid);
        return db_exec(sql);
 }
 
@@ -486,7 +486,7 @@ int db_setcounters(const char *iface, const uint64_t rxcounter, const uint64_t t
                return 0;
        }
 
-       sqlite3_snprintf(256, sql, "update interface set rxcounter=%"PRIu64", txcounter=%"PRIu64" where id=%"PRId64"", rxcounter, txcounter, (int64_t)ifaceid);
+       sqlite3_snprintf(256, sql, "update interface set rxcounter=%" PRIu64 ", txcounter=%" PRIu64 " where id=%" PRId64 "", rxcounter, txcounter, (int64_t)ifaceid);
        return db_exec(sql);
 }
 
@@ -504,7 +504,7 @@ int db_getcounters(const char *iface, uint64_t *rxcounter, uint64_t *txcounter)
                return 0;
        }
 
-       sqlite3_snprintf(128, sql, "select rxcounter, txcounter from interface where id=%"PRId64"", (int64_t)ifaceid);
+       sqlite3_snprintf(128, sql, "select rxcounter, txcounter from interface where id=%" PRId64 "", (int64_t)ifaceid);
        rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL);
        if (rc != SQLITE_OK) {
                db_errcode = rc;
@@ -537,7 +537,7 @@ int db_getinterfaceinfo(const char *iface, interfaceinfo *info)
                if (ifaceid == 0) {
                        return 0;
                }
-               sqlite3_snprintf(512, sql, "select name, alias, active, strftime('%%s', created, 'utc'), strftime('%%s', updated, 'utc'), rxcounter, txcounter, rxtotal, txtotal from interface where id=%"PRId64"", (int64_t)ifaceid);
+               sqlite3_snprintf(512, sql, "select name, alias, active, strftime('%%s', created, 'utc'), strftime('%%s', updated, 'utc'), rxcounter, txcounter, rxtotal, txtotal from interface where id=%" PRId64 "", (int64_t)ifaceid);
        } else {
                ifaceidin = db_getinterfaceidin(iface);
                if (ifaceidin == NULL || strlen(ifaceidin) < 1) {
@@ -591,7 +591,7 @@ int db_setalias(const char *iface, const char *alias)
                return 0;
        }
 
-       sqlite3_snprintf(128, sql, "update interface set alias='%q' where id=%"PRId64"", alias, (int64_t)ifaceid);
+       sqlite3_snprintf(128, sql, "update interface set alias='%q' where id=%" PRId64 "", alias, (int64_t)ifaceid);
        return db_exec(sql);
 }
 
@@ -648,7 +648,7 @@ int db_getiflist(dbiflist **dbifl)
        sql = "select name from interface order by name desc";
 
        rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL);
-       if (rc != SQLITE_OK ) {
+       if (rc != SQLITE_OK) {
                db_errcode = rc;
                snprintf(errorstring, 1024, "Failed to get interface list from database (%d): %s", rc, sqlite3_errmsg(db));
                printe(PT_Error);
@@ -691,14 +691,14 @@ char *db_get_date_generator(const int range, const short direct, const char *now
                        if (direct || cfg.monthrotate == 1) {
                                snprintf(dgen, 512, "strftime('%%Y-%%m-01', %s, 'localtime')", nowdate);
                        } else {
-                               snprintf(dgen, 512, "strftime('%%Y-%%m-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate-1);
+                               snprintf(dgen, 512, "strftime('%%Y-%%m-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate - 1);
                        }
                        break;
                case 4: /* year */
                        if (direct || cfg.monthrotate == 1 || cfg.monthrotateyears == 0) {
                                snprintf(dgen, 512, "strftime('%%Y-01-01', %s, 'localtime')", nowdate);
                        } else {
-                               snprintf(dgen, 512, "strftime('%%Y-01-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate-1);
+                               snprintf(dgen, 512, "strftime('%%Y-01-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate - 1);
                        }
                        break;
                default:
@@ -727,13 +727,13 @@ int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx,
        }
 
        if (timestamp > 0) {
-               snprintf(nowdate, 64, "datetime(%"PRIu64", 'unixepoch')", timestamp);
+               snprintf(nowdate, 64, "datetime(%" PRIu64 ", 'unixepoch')", timestamp);
        } else {
                snprintf(nowdate, 64, "'now'");
        }
 
        if (debug)
-               printf("db add %s (%"PRId64") %"PRIu64": rx %"PRIu64" - tx %"PRIu64"\n", iface, (int64_t)ifaceid, timestamp, rx, tx);
+               printf("db add %s (%" PRId64 ") %" PRIu64 ": rx %" PRIu64 " - tx %" PRIu64 "\n", iface, (int64_t)ifaceid, timestamp, rx, tx);
 
        if (!intransaction) {
                if (!db_begintransaction()) {
@@ -743,9 +743,9 @@ int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx,
 
        /* change updated only if more recent than previous when timestamp provided */
        if (timestamp > 0) {
-               sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%"PRId64" and updated < datetime(%s, 'localtime')", nowdate, (int64_t)ifaceid, nowdate);
+               sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%" PRId64 " and updated < datetime(%s, 'localtime')", nowdate, (int64_t)ifaceid, nowdate);
        } else {
-               sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%"PRId64"", nowdate, (int64_t)ifaceid);
+               sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%" PRId64 "", nowdate, (int64_t)ifaceid);
        }
        if (!db_exec(sql)) {
                /* no transaction rollback needed here as failure of the first step results in no transaction being active */
@@ -754,7 +754,7 @@ int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx,
 
        /* total */
        if (rx > 0 || tx > 0) {
-               sqlite3_snprintf(1024, sql, "update interface set rxtotal=rxtotal+%"PRIu64", txtotal=txtotal+%"PRIu64" where id=%"PRId64"", rx, tx, (int64_t)ifaceid);
+               sqlite3_snprintf(1024, sql, "update interface set rxtotal=rxtotal+%" PRIu64 ", txtotal=txtotal+%" PRIu64 " where id=%" PRId64 "", rx, tx, (int64_t)ifaceid);
                if (!db_exec(sql)) {
                        db_rollbacktransaction();
                        return 0;
@@ -762,16 +762,16 @@ int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx,
        }
 
        /* time specific */
-       for (i=0; i<6; i++) {
+       for (i = 0; i < 6; i++) {
                if (featurecfg[i] == 0) {
                        continue;
                }
-               sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%"PRId64", %s, 0, 0)", datatables[i], (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
+               sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%" PRId64 ", %s, 0, 0)", datatables[i], (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
                if (!db_exec(sql)) {
                        db_rollbacktransaction();
                        return 0;
                }
-               sqlite3_snprintf(1024, sql, "update %s set rx=rx+%"PRIu64", tx=tx+%"PRIu64" where interface=%"PRId64" and date=%s", datatables[i], rx, tx, (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
+               sqlite3_snprintf(1024, sql, "update %s set rx=rx+%" PRIu64 ", tx=tx+%" PRIu64 " where interface=%" PRId64 " and date=%s", datatables[i], rx, tx, (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
                if (!db_exec(sql)) {
                        db_rollbacktransaction();
                        return 0;
@@ -794,7 +794,7 @@ int db_setcreation(const char *iface, const time_t timestamp)
                return 0;
        }
 
-       sqlite3_snprintf(256, sql, "update interface set created=datetime(%"PRIu64", 'unixepoch', 'localtime') where id=%"PRId64"", (uint64_t)timestamp, (int64_t)ifaceid);
+       sqlite3_snprintf(256, sql, "update interface set created=datetime(%" PRIu64 ", 'unixepoch', 'localtime') where id=%" PRId64 "", (uint64_t)timestamp, (int64_t)ifaceid);
        return db_exec(sql);
 }
 
@@ -808,7 +808,7 @@ int db_settotal(const char *iface, const uint64_t rx, const uint64_t tx)
                return 0;
        }
 
-       sqlite3_snprintf(256, sql, "update interface set rxtotal=%"PRIu64", txtotal=%"PRIu64" where id=%"PRId64"", rx, tx, (int64_t)ifaceid);
+       sqlite3_snprintf(256, sql, "update interface set rxtotal=%" PRIu64 ", txtotal=%" PRIu64 " where id=%" PRId64 "", rx, tx, (int64_t)ifaceid);
        return db_exec(sql);
 }
 
@@ -820,7 +820,7 @@ int db_insertdata(const char *table, const char *iface, const uint64_t rx, const
 
        const char *datatables[] = {"hour", "day", "month", "year", "top"};
 
-       for (i=0; i<5; i++) {
+       for (i = 0; i < 5; i++) {
                if (strcmp(table, datatables[i]) == 0) {
                        index = i;
                        break;
@@ -836,9 +836,9 @@ int db_insertdata(const char *table, const char *iface, const uint64_t rx, const
                return 0;
        }
 
-       snprintf(nowdate, 64, "datetime(%"PRIu64", 'unixepoch')", timestamp);
+       snprintf(nowdate, 64, "datetime(%" PRIu64 ", 'unixepoch')", timestamp);
 
-       sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%"PRId64", %s, %"PRIu64", %"PRIu64")", table, (int64_t)ifaceid, db_get_date_generator(index+1, 1, nowdate), rx, tx);
+       sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%" PRId64 ", %s, %" PRIu64 ", %" PRIu64 ")", table, (int64_t)ifaceid, db_get_date_generator(index + 1, 1, nowdate), rx, tx);
        return db_exec(sql);
 }
 
@@ -945,7 +945,7 @@ int db_removeoldentries_top(void)
                        continue;
                }
 
-               sqlite3_snprintf(512, sql, "delete from top where id in ( select id from top where interface=%"PRId64" and date!=date('now', 'localtime') order by rx+tx desc limit -1 offset %d )", (int64_t)ifaceid, cfg.topdayentries);
+               sqlite3_snprintf(512, sql, "delete from top where id in ( select id from top where interface=%" PRId64 " and date!=date('now', 'localtime') order by rx+tx desc limit -1 offset %d )", (int64_t)ifaceid, cfg.topdayentries);
 
                if (!db_exec(sql)) {
                        errorcount++;
@@ -1081,7 +1081,7 @@ int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *
        }
 
        ret = 0;
-       for (i=0; i<6; i++) {
+       for (i = 0; i < 6; i++) {
                if (strcmp(table, datatables[i]) == 0) {
                        ret = 1;
                        break;
@@ -1106,8 +1106,8 @@ int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *
        }
 
        limit[0] = '\0';
-       if (resultlimit > 0 && ( !strlen(dbegin) || !strlen(dend) )) {
-               snprintf(limit, 64, "limit %"PRIu32"", resultlimit);
+       if (resultlimit > 0 && (!strlen(dbegin) || !strlen(dend))) {
+               snprintf(limit, 64, "limit %" PRIu32 "", resultlimit);
        }
 
        /* note that using the linked list reverses the order */
@@ -1116,7 +1116,7 @@ int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *
                /* 'top' entries, requires different query due to rx+tx ordering */
                if (strlen(dbegin)) {
                        if (resultlimit > 0) {
-                               snprintf(limit, 64, "limit %"PRIu32"", resultlimit);
+                               snprintf(limit, 64, "limit %" PRIu32 "", resultlimit);
                        }
                        sqlite3_snprintf(512, sql, "select * from (select id, strftime('%%s', date, 'utc'), sum(rx) as rx, sum(tx) as tx from day where interface in (%q) %s %s group by date order by rx+tx desc %s) order by rx+tx asc", ifaceidin, dbegin, dend, limit);
                } else {
@@ -1244,20 +1244,19 @@ void dbdatalistfree(dbdatalist **dbdata)
                *dbdata = (*dbdata)->next;
                free(dbdata_prev);
        }
-
 }
 
 unsigned int getqueryinterfacecount(const char *input)
 {
        unsigned int i, ifacecount = 1;
 
-       if (input[0] == '+' || input[strlen(input)-1] == '+' || !strlen(input)) {
+       if (input[0] == '+' || input[strlen(input) - 1] == '+' || !strlen(input)) {
                return 0;
        }
 
        for (i = 0; i < (unsigned int)strlen(input); i++) {
                if (input[i] == '+') {
-                       if (i > 0 && input[i-1] == '+') {
+                       if (i > 0 && input[i - 1] == '+') {
                                return 0;
                        } else {
                                ifacecount++;
index 041f9e818f0a0886bc2cb60759c443466d84db4f..2a0c816568a3842abece00f20372ef53ca2659fe 100644 (file)
@@ -29,7 +29,7 @@ void showxml(const char *interface, const char mode, const char *databegin, cons
        printf("</updated>\n");
 
        printf("  <traffic>\n");
-       printf("   <total><rx>%"PRIu64"</rx><tx>%"PRIu64"</tx></total>\n", info.rxtotal, info.txtotal);
+       printf("   <total><rx>%" PRIu64 "</rx><tx>%" PRIu64 "</tx></total>\n", info.rxtotal, info.txtotal);
 
        switch (mode) {
                case 'd':
@@ -80,9 +80,9 @@ void xmldump(const interfaceinfo *interface, const char *tablename, const int da
        printf("   <%ss>\n", tablename);
        datalist_i = datalist;
        while (datalist_i != NULL) {
-               printf("    <%s id=\"%"PRId64"\">", tablename, datalist_i->rowid);
+               printf("    <%s id=\"%" PRId64 "\">", tablename, datalist_i->rowid);
                xmldate(&datalist_i->timestamp, datetype);
-               printf("<rx>%"PRIu64"</rx><tx>%"PRIu64"</tx></%s>\n", datalist_i->rx, datalist_i->tx, tablename);
+               printf("<rx>%" PRIu64 "</rx><tx>%" PRIu64 "</tx></%s>\n", datalist_i->rx, datalist_i->tx, tablename);
                datalist_i = datalist_i->next;
        }
        dbdatalistfree(&datalist);
@@ -97,20 +97,20 @@ void xmldate(const time_t *date, const int type)
 
        switch (type) {
                case 1:
-                       printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date>", \
-                                       1900+d->tm_year, 1+d->tm_mon, d->tm_mday);
+                       printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date>",
+                                  1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday);
                        break;
                case 2:
-                       printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date><time><hour>%02d</hour><minute>%02d</minute></time>", \
-                                       1900+d->tm_year, 1+d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
+                       printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date><time><hour>%02d</hour><minute>%02d</minute></time>",
+                                  1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
                        break;
                case 3:
-                       printf("<date><year>%d</year><month>%02d</month></date>", \
-                                       1900+d->tm_year, 1+d->tm_mon);
+                       printf("<date><year>%d</year><month>%02d</month></date>",
+                                  1900 + d->tm_year, 1 + d->tm_mon);
                        break;
                case 4:
-                       printf("<date><year>%d</year></date>", \
-                                       1900+d->tm_year);
+                       printf("<date><year>%d</year></date>",
+                                  1900 + d->tm_year);
                        break;
                default:
                        break;
index b1918c6a6b5f4c83abcc10d786bcc0f8a6bfe77e..599114136077895776f60f30372a2d7a8fb49b41 100644 (file)
--- a/src/fs.c
+++ b/src/fs.c
@@ -11,8 +11,8 @@ int fileexists(const char *file)
 {
        struct stat statbuf;
 
-       if (stat(file, &statbuf)!=0) {
-               if (errno==ENOENT) {
+       if (stat(file, &statbuf) != 0) {
+               if (errno == ENOENT) {
                        return 0;
                }
                if (debug)
@@ -49,19 +49,19 @@ int mkpath(const char *dir, const mode_t mode)
        }
 
        len = strlen(tmp);
-       if (tmp[len-1] == '/') {
-               tmp[len-1] = '\0';
+       if (tmp[len - 1] == '/') {
+               tmp[len - 1] = '\0';
        }
 
        if (tmp[0] == '/') {
                i++;
        }
 
-       for (; i<len; i++) {
+       for (; i < len; i++) {
                if (tmp[i] == '/') {
                        tmp[i] = '\0';
                        if (!direxists(tmp)) {
-                               if (mkdir(tmp, mode)!=0) {
+                               if (mkdir(tmp, mode) != 0) {
                                        if (debug)
                                                printf("Error: mkdir() \"%s\": %s\n", tmp, strerror(errno));
                                        ret = 0;
@@ -72,7 +72,7 @@ int mkpath(const char *dir, const mode_t mode)
                }
        }
        if (ret) {
-               if (mkdir(tmp, mode)!=0) {
+               if (mkdir(tmp, mode) != 0) {
                        if (debug)
                                printf("Error: mkdir() \"%s\": %s\n", tmp, strerror(errno));
                        ret = 0;
@@ -87,7 +87,7 @@ int mkpath(const char *dir, const mode_t mode)
 
 void preparevnstatdir(const char *dir, const char *user, const char *group)
 {
-       size_t i, len, lastslash=0;
+       size_t i, len, lastslash = 0;
        char *path, *base;
 
        if (dir == NULL) {
@@ -95,11 +95,11 @@ void preparevnstatdir(const char *dir, const char *user, const char *group)
        }
 
        len = strlen(dir);
-       if (len<2) {
+       if (len < 2) {
                return;
        }
 
-       if (dir[len-1] == '/') {
+       if (dir[len - 1] == '/') {
                return;
        }
 
@@ -110,7 +110,7 @@ void preparevnstatdir(const char *dir, const char *user, const char *group)
 
        /* verify that path ends with vnstat or vnstatd */
        base = basename(dirname(path));
-       if (strcmp(base, "vnstat")!=0 && strcmp(base, "vnstatd")!=0) {
+       if (strcmp(base, "vnstat") != 0 && strcmp(base, "vnstatd") != 0) {
                free(path);
                return;
        }
@@ -122,7 +122,7 @@ void preparevnstatdir(const char *dir, const char *user, const char *group)
        }
 
        /* extract path */
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                if (path[i] == '/') {
                        lastslash = i;
                }
@@ -181,7 +181,7 @@ void updatedirownerid(const char *dir, const uid_t uid, const gid_t gid)
 
        if ((dir_fd = open(dir, FS_OPEN_RO_FLAGS)) == -1)
                return;
-       if (fstat(dir_fd, &statbuf)!=0) {
+       if (fstat(dir_fd, &statbuf) != 0) {
                close(dir_fd);
                return;
        }
@@ -198,21 +198,21 @@ void updatedirownerid(const char *dir, const uid_t uid, const gid_t gid)
                }
        }
 
-       if ((d=fdopendir(dir_fd))==NULL) {
+       if ((d = fdopendir(dir_fd)) == NULL) {
                if (debug)
                        printf("Error: updatedirowner() diropen() \"%s\": %s\n", dir, strerror(errno));
                close(dir_fd);
                return;
        }
 
-       while ((di=readdir(d))) {
+       while ((di = readdir(d))) {
                if (di->d_type != DT_REG) {
                        continue;
                }
                snprintf(entryname, 512, "%s/%s", dir, di->d_name);
                if ((file_fd = open(entryname, FS_OPEN_RO_FLAGS)) == -1)
                        continue;
-               if (fstat(file_fd, &statbuf)!=0) {
+               if (fstat(file_fd, &statbuf) != 0) {
                        close(file_fd);
                        continue;
                }
@@ -271,7 +271,7 @@ int getdirowner(const char *dir, uid_t *uid, gid_t *gid)
                return 0;
        }
 
-       if (stat(dir, &statbuf)!=0) {
+       if (stat(dir, &statbuf) != 0) {
                if (debug)
                        printf("Error: stat() \"%s\": %s\n", dir, strerror(errno));
                return 0;
index 35e878edf548194c503ba4edb68dfc7c6c478937..d33fd74bb3b0bdd1687b3f34f478bc2e10756ce3 100644 (file)
--- a/src/ibw.c
+++ b/src/ibw.c
@@ -49,7 +49,7 @@ int ibwadd(const char *iface, const uint32_t limit)
 
                /* update previous value if already in list */
                while (p != NULL) {
-                       if (strcmp(p->interface, iface)==0) {
+                       if (strcmp(p->interface, iface) == 0) {
                                p->limit = limit;
                                return 1;
                        }
@@ -57,7 +57,7 @@ int ibwadd(const char *iface, const uint32_t limit)
                }
 
                /* add new node if not found */
-               n =  (ibwnode *)malloc(sizeof(ibwnode));
+               n = (ibwnode *)malloc(sizeof(ibwnode));
 
                if (n == NULL) {
                        return 0;
@@ -77,7 +77,7 @@ int ibwadd(const char *iface, const uint32_t limit)
 
 void ibwlist(void)
 {
-       int i=1;
+       int i = 1;
        ibwnode *p = ifacebw;
 
        if (p == NULL) {
@@ -105,7 +105,7 @@ int ibwget(const char *iface, uint32_t *limit)
 
        /* search for interface specific limit */
        while (p != NULL) {
-               if (strcasecmp(p->interface, iface)==0) {
+               if (strcasecmp(p->interface, iface) == 0) {
 
                        if (cfg.bwdetection && p->retries < 5) {
                                if (cfg.bwdetectioninterval > 0 && (current - p->detected) > (cfg.bwdetectioninterval * 60)) {
@@ -121,7 +121,7 @@ int ibwget(const char *iface, uint32_t *limit)
                                }
                        }
 
-                       if (p->limit>0) {
+                       if (p->limit > 0) {
                                *limit = p->limit;
                                return 1;
                        } else {
@@ -149,7 +149,7 @@ int ibwget(const char *iface, uint32_t *limit)
        }
 
        /* return default limit if specified */
-       if (cfg.maxbw>0) {
+       if (cfg.maxbw > 0) {
                *limit = (uint32_t)cfg.maxbw;
                return 1;
        }
@@ -161,7 +161,7 @@ ibwnode *ibwgetnode(const char *iface)
        ibwnode *p = ifacebw;
 
        while (p != NULL) {
-               if (strcasecmp(p->interface, iface)==0) {
+               if (strcasecmp(p->interface, iface) == 0) {
                        return p;
                }
                p = p->next;
@@ -197,70 +197,70 @@ int ibwcfgread(FILE *fd)
                cfgline[0] = '\0';
 
                /* get current line */
-               if (fgets(cfgline, 512, fd)==NULL) {
+               if (fgets(cfgline, 512, fd) == NULL) {
                        break;
                }
 
                linelen = (int)strlen(cfgline);
 
-               if (linelen<=8 || cfgline[0]=='#') {
+               if (linelen <= 8 || cfgline[0] == '#') {
                        continue;
                }
 
-               if (strncasecmp(cfgline, "MaxBW", 5)!=0) {
+               if (strncasecmp(cfgline, "MaxBW", 5) != 0) {
                        continue;
                }
 
                /* clear name and value buffers */
-               for (j=0; j<512; j++) {
-                       name[j]=value[j]='\0';
+               for (j = 0; j < 512; j++) {
+                       name[j] = value[j] = '\0';
                }
 
                /* get interface name */
-               j=0;
-               for (i=5; i<linelen; i++) {
-                       if (cfgline[i]==' ' || cfgline[i]=='=' || cfgline[i]=='\t' || cfgline[i]=='\n' || cfgline[i]=='\r') {
+               j = 0;
+               for (i = 5; i < linelen; i++) {
+                       if (cfgline[i] == ' ' || cfgline[i] == '=' || cfgline[i] == '\t' || cfgline[i] == '\n' || cfgline[i] == '\r') {
                                break;
                        } else {
-                               name[j]=cfgline[i];
+                               name[j] = cfgline[i];
                                j++;
                        }
                }
 
                /* get new line if no usable name was found */
-               if (strlen(name)==0) {
+               if (strlen(name) == 0) {
                        continue;
                }
 
                /* search value */
-               j=0;
-               for (i++; i<linelen; i++) {
-                       if (cfgline[i]=='\n' || cfgline[i]=='\r') {
+               j = 0;
+               for (i++; i < linelen; i++) {
+                       if (cfgline[i] == '\n' || cfgline[i] == '\r') {
                                break;
-                       } else if (cfgline[i]=='\"') {
-                               if (j==0) {
+                       } else if (cfgline[i] == '\"') {
+                               if (j == 0) {
                                        continue;
                                } else {
                                        break;
                                }
                        } else {
-                               if (j==0 && (cfgline[i]==' ' || cfgline[i]=='=' || cfgline[i]=='\t')) {
+                               if (j == 0 && (cfgline[i] == ' ' || cfgline[i] == '=' || cfgline[i] == '\t')) {
                                        continue;
                                } else {
-                                       value[j]=cfgline[i];
+                                       value[j] = cfgline[i];
                                        j++;
                                }
                        }
                }
 
                /* get new line if no usable value was found */
-               if ((strlen(value)==0) || (!isdigit(value[0])) ) {
+               if ((strlen(value) == 0) || (!isdigit(value[0]))) {
                        continue;
                }
 
                /* add interface and limit to list if value is within limits */
                ivalue = strtol(value, (char **)NULL, 0);
-               if (ivalue<0 || ivalue>BWMAX) {
+               if (ivalue < 0 || ivalue > BWMAX) {
                        snprintf(errorstring, 1024, "Invalid value \"%ld\" for MaxBW%s, ignoring parameter.", ivalue, name);
                        printe(PT_Config);
                } else {
index 03f43540ea2f435b017b789d1ae92f7c78d074dc..b531661e39c72c8765a5005ad64c9f2ee8097fcf 100644 (file)
@@ -15,11 +15,11 @@ int getifinfo(const char *iface)
 
 #if defined(__linux__)
        if (cfg.is64bit == -2) {
-  #if HAVE_DECL_IFLA_STATS64
+#if HAVE_DECL_IFLA_STATS64
                ifinfo.is64bit = 1;
-  #else
+#else
                ifinfo.is64bit = 0;
-  #endif
+#endif
        } else {
                ifinfo.is64bit = (short)cfg.is64bit;
        }
@@ -31,7 +31,7 @@ int getifinfo(const char *iface)
        }
 #endif
 
-       if (strcmp(iface, "default")==0) {
+       if (strcmp(iface, "default") == 0) {
                strncpy_nt(inface, cfg.iface, 32);
        } else {
                strncpy_nt(inface, iface, 32);
@@ -39,7 +39,7 @@ int getifinfo(const char *iface)
 
 #if defined(__linux__) || defined(CHECK_VNSTAT)
        /* try getting interface info from /proc */
-       if (readproc(inface)==1) {
+       if (readproc(inface) == 1) {
                ifinfo.timestamp = time(NULL);
                return 1;
        } else {
@@ -48,13 +48,13 @@ int getifinfo(const char *iface)
        }
 
        /* try getting interface info from /sys */
-       if (readsysclassnet(inface)==1) {
+       if (readsysclassnet(inface) == 1) {
                ifinfo.timestamp = time(NULL);
                return 1;
        }
 
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)  || defined(__FreeBSD_kernel__)
-       if (readifaddrs(inface)==1) {
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
+       if (readifaddrs(inface) == 1) {
                ifinfo.timestamp = time(NULL);
                return 1;
        }
@@ -87,14 +87,14 @@ int getiflist(char **ifacelist, int showspeed)
        *ifacelist[0] = '\0';
 
 #if defined(__linux__) || defined(CHECK_VNSTAT)
-       if ((fp=fopen(PROCNETDEV, "r"))!=NULL) {
+       if ((fp = fopen(PROCNETDEV, "r")) != NULL) {
 
                /* make list of interfaces */
-               while (fgets(procline, 512, fp)!=NULL) {
+               while (fgets(procline, 512, fp) != NULL) {
                        sscanf(procline, "%63s", temp);
-                       if (strlen(temp)>0 && (isdigit(temp[(strlen(temp)-1)]) || temp[(strlen(temp)-1)]==':')) {
+                       if (strlen(temp) > 0 && (isdigit(temp[(strlen(temp) - 1)]) || temp[(strlen(temp) - 1)] == ':')) {
                                sscanf(temp, "%31[^':']s", interface);
-                               *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(interface) + 2 ) * sizeof(char)) );
+                               *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(interface) + 2) * sizeof(char)));
                                if (*ifacelist == NULL) {
                                        panicexit(__FILE__, __LINE__);
                                }
@@ -106,7 +106,7 @@ int getiflist(char **ifacelist, int showspeed)
                                speed = getifspeed(interface);
                                if (speed > 0) {
                                        snprintf(temp, 64, "(%u Mbit) ", speed);
-                                       *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) );
+                                       *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(temp) + 1) * sizeof(char)));
                                        if (*ifacelist == NULL) {
                                                panicexit(__FILE__, __LINE__);
                                        }
@@ -120,14 +120,14 @@ int getiflist(char **ifacelist, int showspeed)
 
        } else {
 
-               if ((dp=opendir(SYSCLASSNET))!=NULL) {
+               if ((dp = opendir(SYSCLASSNET)) != NULL) {
 
                        /* make list of interfaces */
-                       while ((di=readdir(dp))) {
+                       while ((di = readdir(dp))) {
                                if (di->d_name[0] == '.' || strlen(di->d_name) > 31) {
                                        continue;
                                }
-                               *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(di->d_name) + 2 ) * sizeof(char)) );
+                               *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(di->d_name) + 2) * sizeof(char)));
                                if (*ifacelist == NULL) {
                                        panicexit(__FILE__, __LINE__);
                                }
@@ -139,7 +139,7 @@ int getiflist(char **ifacelist, int showspeed)
                                speed = getifspeed(di->d_name);
                                if (speed > 0) {
                                        snprintf(temp, 64, "(%u Mbit) ", speed);
-                                       *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) );
+                                       *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(temp) + 1) * sizeof(char)));
                                        if (*ifacelist == NULL) {
                                                panicexit(__FILE__, __LINE__);
                                        }
@@ -160,7 +160,7 @@ int getiflist(char **ifacelist, int showspeed)
                        if (ifa->ifa_addr->sa_family != AF_LINK || strlen(ifa->ifa_name) > 31) {
                                continue;
                        }
-                       *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(ifa->ifa_name) + 2 ) * sizeof(char)) );
+                       *ifacelist = realloc(*ifacelist, ((strlen(*ifacelist) + strlen(ifa->ifa_name) + 2) * sizeof(char)));
                        if (*ifacelist == NULL) {
                                panicexit(__FILE__, __LINE__);
                        }
@@ -172,7 +172,7 @@ int getiflist(char **ifacelist, int showspeed)
                        speed = getifspeed(ifa->ifa_name);
                        if (speed > 0) {
                                snprintf(temp, 64, "(%u Mbit) ", speed);
-                               *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) );
+                               *ifacelist = realloc(*ifacelist, ((strlen(*ifacelist) + strlen(temp) + 1) * sizeof(char)));
                                if (*ifacelist == NULL) {
                                        panicexit(__FILE__, __LINE__);
                                }
@@ -195,7 +195,7 @@ int readproc(const char *iface)
        char temp[4][64], procline[512], *proclineptr, ifaceid[33];
        int check;
 
-       if ((fp=fopen(PROCNETDEV, "r"))==NULL) {
+       if ((fp = fopen(PROCNETDEV, "r")) == NULL) {
                if (debug)
                        printf("Error: Unable to read %s: %s\n", PROCNETDEV, strerror(errno));
                return 0;
@@ -205,9 +205,9 @@ int readproc(const char *iface)
        strcat(ifaceid, ":");
 
        check = 0;
-       while (fgets(procline, 512, fp)!=NULL) {
+       while (fgets(procline, 512, fp) != NULL) {
                sscanf(procline, "%63s", temp[0]);
-               if (strncmp(ifaceid, temp[0], strlen(ifaceid))==0) {
+               if (strncmp(ifaceid, temp[0], strlen(ifaceid)) == 0) {
                        /* if (debug)
                                printf("\n%s\n", procline); */
                        check = 1;
@@ -216,7 +216,7 @@ int readproc(const char *iface)
        }
        fclose(fp);
 
-       if (check==0) {
+       if (check == 0) {
                if (debug)
                        printf("Requested interface \"%s\" not found.\n", iface);
                return 0;
@@ -226,7 +226,7 @@ int readproc(const char *iface)
 
                /* get rx and tx from procline */
                proclineptr = strchr(procline, ':');
-               sscanf(proclineptr+1, "%63s %63s %*s %*s %*s %*s %*s %*s %63s %63s", temp[0], temp[1], temp[2], temp[3]);
+               sscanf(proclineptr + 1, "%63s %63s %*s %*s %*s %*s %*s %*s %63s %63s", temp[0], temp[1], temp[2], temp[3]);
 
                ifinfo.rx = strtoull(temp[0], (char **)NULL, 0);
                ifinfo.tx = strtoull(temp[2], (char **)NULL, 0);
@@ -257,12 +257,12 @@ int readsysclassnet(const char *iface)
 
        /* rx bytes */
        snprintf(file, 76, "%s/rx_bytes", path);
-       if ((fp=fopen(file, "r"))==NULL) {
+       if ((fp = fopen(file, "r")) == NULL) {
                if (debug)
                        printf("Unable to read: %s - %s\n", file, strerror(errno));
                return 0;
        } else {
-               if (fgets(buffer, 64, fp)!=NULL) {
+               if (fgets(buffer, 64, fp) != NULL) {
                        ifinfo.rx = strtoull(buffer, (char **)NULL, 0);
                } else {
                        fclose(fp);
@@ -273,12 +273,12 @@ int readsysclassnet(const char *iface)
 
        /* tx bytes */
        snprintf(file, 76, "%s/tx_bytes", path);
-       if ((fp=fopen(file, "r"))==NULL) {
+       if ((fp = fopen(file, "r")) == NULL) {
                if (debug)
                        printf("Unable to read: %s - %s\n", file, strerror(errno));
                return 0;
        } else {
-               if (fgets(buffer, 64, fp)!=NULL) {
+               if (fgets(buffer, 64, fp) != NULL) {
                        ifinfo.tx = strtoull(buffer, (char **)NULL, 0);
                } else {
                        fclose(fp);
@@ -292,12 +292,12 @@ int readsysclassnet(const char *iface)
 
                /* rx packets */
                snprintf(file, 76, "%s/rx_packets", path);
-               if ((fp=fopen(file, "r"))==NULL) {
+               if ((fp = fopen(file, "r")) == NULL) {
                        if (debug)
                                printf("Unable to read: %s - %s\n", file, strerror(errno));
                        return 0;
                } else {
-                       if (fgets(buffer, 64, fp)!=NULL) {
+                       if (fgets(buffer, 64, fp) != NULL) {
                                ifinfo.rxp = strtoull(buffer, (char **)NULL, 0);
                        } else {
                                fclose(fp);
@@ -308,12 +308,12 @@ int readsysclassnet(const char *iface)
 
                /* tx packets */
                snprintf(file, 76, "%s/tx_packets", path);
-               if ((fp=fopen(file, "r"))==NULL) {
+               if ((fp = fopen(file, "r")) == NULL) {
                        if (debug)
                                printf("Unable to read: %s - %s\n", file, strerror(errno));
                        return 0;
                } else {
-                       if (fgets(buffer, 64, fp)!=NULL) {
+                       if (fgets(buffer, 64, fp) != NULL) {
                                ifinfo.txp = strtoull(buffer, (char **)NULL, 0);
                        } else {
                                fclose(fp);
@@ -392,12 +392,12 @@ uint32_t getifspeed(const char *iface)
 
        snprintf(file, 64, "%s/%s/speed", SYSCLASSNET, iface);
 
-       if ((fp=fopen(file, "r"))==NULL) {
+       if ((fp = fopen(file, "r")) == NULL) {
                if (debug)
                        printf("Unable to open: %s - %s\n", file, strerror(errno));
                return 0;
        } else {
-               if (fgets(buffer, 64, fp)!=NULL) {
+               if (fgets(buffer, 64, fp) != NULL) {
                        speed = strtoull(buffer, (char **)NULL, 0);
                } else {
                        if (debug)
@@ -408,7 +408,7 @@ uint32_t getifspeed(const char *iface)
        }
        fclose(fp);
 
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)  || defined(__FreeBSD_kernel__)
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
 
        struct if_data ifd;
 
@@ -422,7 +422,7 @@ uint32_t getifspeed(const char *iface)
 
 #endif
        if (debug)
-               printf("getifspeed: \"%s\": %"PRIu64"\n", iface, speed);
+               printf("getifspeed: \"%s\": %" PRIu64 "\n", iface, speed);
 
        if (speed > 1000000) {
                speed = 0;
index 1c93a6a672effdfac144cdd7bc905cb5b1119176..165ad78dbee933adb23ea6ac905f43462b8135d6 100644 (file)
@@ -131,7 +131,7 @@ void colorinit(IMAGECONTENT *ic)
 
 void colorinitcheck(const char *color, const int value, const char *cfgtext, const int *rgb)
 {
-       if (value==-1) {
+       if (value == -1) {
                printf("Error: ImageColorAllocate failed.\n");
                printf("       C: \"%s\" T: \"%s\" RGB: %d/%d/%d\n", color, cfgtext, rgb[0], rgb[1], rgb[2]);
                exit(EXIT_FAILURE);
@@ -150,24 +150,24 @@ void layoutinit(IMAGECONTENT *ic, char *title, const int width, const int height
        /* background, edges */
        gdImageFill(ic->im, 0, 0, ic->cbackground);
        if (ic->showedge) {
-               gdImageRectangle(ic->im, 0, 0, width-1, height-1, ic->cedge);
+               gdImageRectangle(ic->im, 0, 0, width - 1, height - 1, ic->cedge);
        }
 
        /* titlebox with title */
        if (ic->showheader) {
-               gdImageFilledRectangle(ic->im, 2+ic->showedge, 2+ic->showedge, width-3-ic->showedge, 24, ic->cheader);
-               gdImageString(ic->im, gdFontGetGiant(), 12, 5+ic->showedge, (unsigned char*)title, ic->cheadertitle);
+               gdImageFilledRectangle(ic->im, 2 + ic->showedge, 2 + ic->showedge, width - 3 - ic->showedge, 24, ic->cheader);
+               gdImageString(ic->im, gdFontGetGiant(), 12, 5 + ic->showedge, (unsigned char *)title, ic->cheadertitle);
        }
 
        /* date */
        if (!ic->showheader || ic->altdate) {
-               gdImageString(ic->im, gdFontGetTiny(), 5+ic->showedge, height-12-ic->showedge, (unsigned char*)datestring, ic->cvnstat);
+               gdImageString(ic->im, gdFontGetTiny(), 5 + ic->showedge, height - 12 - ic->showedge, (unsigned char *)datestring, ic->cvnstat);
        } else {
-               gdImageString(ic->im, gdFontGetTiny(), width-(((int)strlen(datestring))*gdFontGetTiny()->w+12), 9+ic->showedge, (unsigned char*)datestring, ic->cheaderdate);
+               gdImageString(ic->im, gdFontGetTiny(), width - (((int)strlen(datestring)) * gdFontGetTiny()->w + 12), 9 + ic->showedge, (unsigned char *)datestring, ic->cheaderdate);
        }
 
        /* generator */
-       gdImageString(ic->im, gdFontGetTiny(), width-114-ic->showedge, height-12-ic->showedge, (unsigned char*)"vnStat / Teemu Toivola", ic->cvnstat);
+       gdImageString(ic->im, gdFontGetTiny(), width - 114 - ic->showedge, height - 12 - ic->showedge, (unsigned char *)"vnStat / Teemu Toivola", ic->cvnstat);
 }
 
 void drawlegend(IMAGECONTENT *ic, const int x, const int y)
@@ -177,20 +177,20 @@ void drawlegend(IMAGECONTENT *ic, const int x, const int y)
        }
 
        /* color legend */
-       gdImageString(ic->im, gdFontGetSmall(), x, y, (unsigned char*)"rx     tx", ic->ctext);
-       gdImageFilledRectangle(ic->im, x-12, y+4, x-6, y+10, ic->crx);
-       gdImageRectangle(ic->im, x-12, y+4, x-6, y+10, ic->ctext);
-       gdImageFilledRectangle(ic->im, x+30, y+4, x+36, y+10, ic->ctx);
-       gdImageRectangle(ic->im, x+30, y+4, x+36, y+10, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), x, y, (unsigned char *)"rx     tx", ic->ctext);
+       gdImageFilledRectangle(ic->im, x - 12, y + 4, x - 6, y + 10, ic->crx);
+       gdImageRectangle(ic->im, x - 12, y + 4, x - 6, y + 10, ic->ctext);
+       gdImageFilledRectangle(ic->im, x + 30, y + 4, x + 36, y + 10, ic->ctx);
+       gdImageRectangle(ic->im, x + 30, y + 4, x + 36, y + 10, ic->ctext);
 }
 
 void drawbar(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max)
 {
        int l, width = len;
 
-       if ((rx+tx) < max) {
-               width=(int)(((rx+tx)/(float)max)*len);
-       } else if ((rx+tx) > max || max == 0) {
+       if ((rx + tx) < max) {
+               width = (int)(((rx + tx) / (float)max) * len);
+       } else if ((rx + tx) > max || max == 0) {
                return;
        }
 
@@ -199,25 +199,25 @@ void drawbar(IMAGECONTENT *ic, const int x, const int y, const int len, const ui
        }
 
        if (tx > rx) {
-               l=(int)(rintf((rx/(float)(rx+tx)*width)));
+               l = (int)(rintf((rx / (float)(rx + tx) * width)));
 
                if (l > 0) {
-                       gdImageFilledRectangle(ic->im, x, y+YBEGINOFFSET, x+l, y+YENDOFFSET, ic->crx);
-                       gdImageRectangle(ic->im, x, y+YBEGINOFFSET, x+l, y+YENDOFFSET, ic->crxd);
+                       gdImageFilledRectangle(ic->im, x, y + YBEGINOFFSET, x + l, y + YENDOFFSET, ic->crx);
+                       gdImageRectangle(ic->im, x, y + YBEGINOFFSET, x + l, y + YENDOFFSET, ic->crxd);
                }
 
-               gdImageFilledRectangle(ic->im, x+l, y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctx);
-               gdImageRectangle(ic->im, x+l, y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctxd);
+               gdImageFilledRectangle(ic->im, x + l, y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctx);
+               gdImageRectangle(ic->im, x + l, y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctxd);
 
        } else {
-               l=(int)(rintf((tx/(float)(rx+tx)*width)));
+               l = (int)(rintf((tx / (float)(rx + tx) * width)));
 
-               gdImageFilledRectangle(ic->im, x, y+YBEGINOFFSET, x+(width-l), y+YENDOFFSET, ic->crx);
-               gdImageRectangle(ic->im, x, y+YBEGINOFFSET, x+(width-l), y+YENDOFFSET, ic->crxd);
+               gdImageFilledRectangle(ic->im, x, y + YBEGINOFFSET, x + (width - l), y + YENDOFFSET, ic->crx);
+               gdImageRectangle(ic->im, x, y + YBEGINOFFSET, x + (width - l), y + YENDOFFSET, ic->crxd);
 
                if (l > 0) {
-                       gdImageFilledRectangle(ic->im, x+(width-l), y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctx);
-                       gdImageRectangle(ic->im, x+(width-l), y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctxd);
+                       gdImageFilledRectangle(ic->im, x + (width - l), y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctx);
+                       gdImageRectangle(ic->im, x + (width - l), y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctxd);
                }
        }
 }
@@ -226,14 +226,14 @@ void drawpole(IMAGECONTENT *ic, const int x, const int y, const int len, const u
 {
        int l;
 
-       l = (int)((rx/(float)max)*len);
+       l = (int)((rx / (float)max) * len);
        if (l > 0) {
-               gdImageFilledRectangle(ic->im, x, y+(len-l), x+7, y+len, ic->crx);
+               gdImageFilledRectangle(ic->im, x, y + (len - l), x + 7, y + len, ic->crx);
        }
 
-       l = (int)((tx/(float)max)*len);
+       l = (int)((tx / (float)max) * len);
        if (l > 0) {
-               gdImageFilledRectangle(ic->im, x+5, y+(len-l), x+12, y+len, ic->ctx);
+               gdImageFilledRectangle(ic->im, x + 5, y + (len - l), x + 12, y + len, ic->ctx);
        }
 }
 
@@ -241,9 +241,9 @@ void drawdonut(IMAGECONTENT *ic, const int x, const int y, const float rxp, cons
 {
        int rxarc = 0, txarc = 0;
 
-       if ( (int)(rxp + txp) > 0 ) {
+       if ((int)(rxp + txp) > 0) {
                rxarc = (int)(360 * (rxp / (float)100));
-               if ( (int)(rxp + txp) == 100 ) {
+               if ((int)(rxp + txp) == 100) {
                        txarc = 360 - rxarc;
                } else {
                        txarc = (int)(360 * (txp / (float)100));
@@ -254,32 +254,32 @@ void drawdonut(IMAGECONTENT *ic, const int x, const int y, const float rxp, cons
        gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
 
        if (txarc) {
-               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
                if (txarc >= 5) {
-                       gdImageFill(ic->im, x+1, y-(DOUTRAD/2-3), ic->ctx);
+                       gdImageFill(ic->im, x + 1, y - (DOUTRAD / 2 - 3), ic->ctx);
                }
-               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
        }
 
        if (rxarc) {
-               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
                if (rxarc >= 5) {
-                       gdImageFill(ic->im, (int)(x+(DOUTRAD/2-3)*cos(((270*2+2*txarc+rxarc)/2)*M_PI/180)), (int)(y+(DOUTRAD/2-3)*sin(((270*2+2*txarc+rxarc)/2)*M_PI/180)), ic->crx);
+                       gdImageFill(ic->im, (int)(x + (DOUTRAD / 2 - 3) * cos(((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), (int)(y + (DOUTRAD / 2 - 3) * sin(((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), ic->crx);
                }
-               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
        }
 
        // remove center from background filled circle, making it a donut
-       gdImageFilledArc(ic->im, x, y, DINRAD-2, DINRAD-2, 0, 360, ic->cbackground, 0);
+       gdImageFilledArc(ic->im, x, y, DINRAD - 2, DINRAD - 2, 0, 360, ic->cbackground, 0);
 }
 
 void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp)
 {
        int rxarc = 0, txarc = 0;
 
-       if ( (int)(rxp + txp) > 0 ) {
+       if ((int)(rxp + txp) > 0) {
                rxarc = (int)(360 * (rxp / (float)100));
-               if ( (int)(rxp + txp) == 100 ) {
+               if ((int)(rxp + txp) == 100) {
                        txarc = 360 - rxarc;
                } else {
                        txarc = (int)(360 * (txp / (float)100));
@@ -290,33 +290,33 @@ void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const fl
        gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
 
        if (txarc) {
-               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctx, 0);
-               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
-               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270 + txarc, ic->ctx, 0);
+               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
        }
 
        if (rxarc) {
-               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crx, 0);
-               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
-               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270 + txarc, 270 + txarc + rxarc, ic->crx, 0);
+               gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
+               gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
        }
 
        // remove center from background filled circle, making it a donut
-       gdImageFilledArc(ic->im, x, y, DINRAD-2, DINRAD-2, 0, 360, ic->cbackground, 0);
+       gdImageFilledArc(ic->im, x, y, DINRAD - 2, DINRAD - 2, 0, 360, ic->cbackground, 0);
 }
 
 void drawhours(IMAGECONTENT *ic, const int x, const int y, const int rate)
 {
-       int i, tmax=0, s=0, step, prev=0, diff=0, chour;
+       int i, tmax = 0, s = 0, step, prev = 0, diff = 0, chour;
        float ratediv;
-       uint64_t max=1, scaleunit=0;
+       uint64_t max = 1, scaleunit = 0;
        char buffer[32];
        struct tm *d;
        dbdatalist *datalist = NULL, *datalist_i = NULL;
        dbdatalistinfo datainfo;
        HOURDATA hourdata[24];
 
-       for (i=0; i<24; i++) {
+       for (i = 0; i < 24; i++) {
                hourdata[i].rx = hourdata[i].tx = 0;
                hourdata[i].date = 0;
        }
@@ -334,7 +334,7 @@ void drawhours(IMAGECONTENT *ic, const int x, const int y, const int rate)
 
        while (datalist_i != NULL) {
                d = localtime(&datalist_i->timestamp);
-               if (hourdata[d->tm_hour].date != 0 || ic->interface.updated-datalist_i->timestamp > 86400) {
+               if (hourdata[d->tm_hour].date != 0 || ic->interface.updated - datalist_i->timestamp > 86400) {
                        datalist_i = datalist_i->next;
                        continue;
                }
@@ -349,7 +349,7 @@ void drawhours(IMAGECONTENT *ic, const int x, const int y, const int rate)
        chour = localtime(&ic->current)->tm_hour;
 
        if (cfg.rateunit) {
-               ratediv = 450;      /* x * 8 / 3600 */
+               ratediv = 450; /* x * 8 / 3600 */
        } else {
                ratediv = 3600;
        }
@@ -360,7 +360,7 @@ void drawhours(IMAGECONTENT *ic, const int x, const int y, const int rate)
        for (i = 0; i < 24; i++) {
                /* convert hourly transfer to hourly rate if needed */
                if (rate) {
-                       if ((ic->current-hourdata[i].date) > 3600) {
+                       if ((ic->current - hourdata[i].date) > 3600) {
                                hourdata[i].rx = (uint64_t)(hourdata[i].rx / ratediv);
                                hourdata[i].tx = (uint64_t)(hourdata[i].tx / ratediv);
                        } else {
@@ -404,45 +404,45 @@ void drawhours(IMAGECONTENT *ic, const int x, const int y, const int rate)
                step = 1;
        }
 
-       for (i=step; (uint64_t)(scaleunit*(unsigned int)i) <= max; i=i+step) {
+       for (i = step; (uint64_t)(scaleunit * (unsigned int)i) <= max; i = i + step) {
                s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
-               gdImageLine(ic->im, x+36, y+124-s, x+460, y+124-s, ic->cline);
-               gdImageLine(ic->im, x+36, y+124-((s+prev)/2), x+460, y+124-((s+prev)/2), ic->clinel);
-               gdImageString(ic->im, gdFontGetTiny(), x+16, y+121-s, (unsigned char*)getimagevalue(scaleunit*(unsigned int)i, 3, rate), ic->ctext);
+               gdImageLine(ic->im, x + 36, y + 124 - s, x + 460, y + 124 - s, ic->cline);
+               gdImageLine(ic->im, x + 36, y + 124 - ((s + prev) / 2), x + 460, y + 124 - ((s + prev) / 2), ic->clinel);
+               gdImageString(ic->im, gdFontGetTiny(), x + 16, y + 121 - s, (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext);
                prev = s;
        }
        s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
-       if ( ((s+prev)/2) <= 128 ) {
-               gdImageLine(ic->im, x+36, y+124-((s+prev)/2), x+460, y+124-((s+prev)/2), ic->clinel);
+       if (((s + prev) / 2) <= 128) {
+               gdImageLine(ic->im, x + 36, y + 124 - ((s + prev) / 2), x + 460, y + 124 - ((s + prev) / 2), ic->clinel);
        } else {
                i = i - step;
        }
 
        /* scale text */
-       gdImageStringUp(ic->im, gdFontGetTiny(), x-2, y+60+(rate*10), (unsigned char*)getimagescale(scaleunit * (unsigned int)i, rate), ic->ctext);
+       gdImageStringUp(ic->im, gdFontGetTiny(), x - 2, y + 60 + (rate * 10), (unsigned char *)getimagescale(scaleunit * (unsigned int)i, rate), ic->ctext);
 
        /* x-axis values and poles */
        for (i = 0; i < 24; i++) {
-               s = tmax-i;
-               if (s<0) {
-                       s+=24;
+               s = tmax - i;
+               if (s < 0) {
+                       s += 24;
                }
                snprintf(buffer, 32, "%02d ", s);
-               gdImageString(ic->im, gdFontGetTiny(), x+440-(i*17), y+128, (unsigned char*)buffer, ic->ctext);
-               drawpole(ic, x+438-(i*17), y, 124, hourdata[s].rx, hourdata[s].tx, max);
+               gdImageString(ic->im, gdFontGetTiny(), x + 440 - (i * 17), y + 128, (unsigned char *)buffer, ic->ctext);
+               drawpole(ic, x + 438 - (i * 17), y, 124, hourdata[s].rx, hourdata[s].tx, max);
        }
 
        /* axis */
-       gdImageLine(ic->im, x+36-4, y+124, x+466, y+124, ic->ctext);
-       gdImageLine(ic->im, x+36, y-10, x+36, y+124+4, ic->ctext);
+       gdImageLine(ic->im, x + 36 - 4, y + 124, x + 466, y + 124, ic->ctext);
+       gdImageLine(ic->im, x + 36, y - 10, x + 36, y + 124 + 4, ic->ctext);
 
        /* arrows */
-       gdImageLine(ic->im, x+465, y+124, x+462, y+122, ic->ctext);
-       gdImageLine(ic->im, x+465, y+124, x+462, y+126, ic->ctext);
-       gdImageLine(ic->im, x+462, y+122, x+462, y+126, ic->ctext);
-       gdImageLine(ic->im, x+36, y-9, x+38, y-6, ic->ctext);
-       gdImageLine(ic->im, x+36, y-9, x+34, y-6, ic->ctext);
-       gdImageLine(ic->im, x+34, y-6, x+38, y-6, ic->ctext);
+       gdImageLine(ic->im, x + 465, y + 124, x + 462, y + 122, ic->ctext);
+       gdImageLine(ic->im, x + 465, y + 124, x + 462, y + 126, ic->ctext);
+       gdImageLine(ic->im, x + 462, y + 122, x + 462, y + 126, ic->ctext);
+       gdImageLine(ic->im, x + 36, y - 9, x + 38, y - 6, ic->ctext);
+       gdImageLine(ic->im, x + 36, y - 9, x + 34, y - 6, ic->ctext);
+       gdImageLine(ic->im, x + 34, y - 6, x + 38, y - 6, ic->ctext);
 }
 
 void drawhourly(IMAGECONTENT *ic, const int rate)
@@ -475,8 +475,8 @@ void drawhourly(IMAGECONTENT *ic, const int rate)
        }
 
        layoutinit(ic, buffer, width, height);
-       drawlegend(ic, 242, 183-headermod);
-       drawhours(ic, 12, 46-headermod, rate);
+       drawlegend(ic, 242, 183 - headermod);
+       drawhours(ic, 12, 46 - headermod, rate);
 }
 
 void drawlist(IMAGECONTENT *ic, const char *listname)
@@ -611,23 +611,23 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
 
        if (datainfo.count) {
                if (listtype == 4) { // top
-                       if (cfg.ostyle<=2) {
-                               drawlegend(ic, 398, 40-headermod);
+                       if (cfg.ostyle <= 2) {
+                               drawlegend(ic, 398, 40 - headermod);
                        }
                        current = time(NULL);
                        d = localtime(&current);
                        strftime(daybuff, 16, stampformat, d);
                } else { // everything else
-                       if (cfg.ostyle>2) {
-                               drawlegend(ic, 432, 40-headermod);
+                       if (cfg.ostyle > 2) {
+                               drawlegend(ic, 432, 40 - headermod);
                        } else {
-                               drawlegend(ic, 385, 40-headermod);
+                               drawlegend(ic, 385, 40 - headermod);
                        }
                }
        }
 
        textx = 10;
-       texty = 40-headermod;
+       texty = 40 - headermod;
 
        if (listtype == 4) { // top
                snprintf(buffer, 512, "   #      day        rx           tx          total");
@@ -636,15 +636,15 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
        }
        if (cfg.ostyle > 2) {
                strcat(buffer, "       avg. rate");
-               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
-               gdImageLine(ic->im, textx+2, texty+16, textx+392+offsetx, texty+16, ic->cline);
-               gdImageLine(ic->im, textx+300+offsetx, texty+2, textx+300+offsetx, texty+40+offsety+(12*rowcount), ic->cline);
+               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
+               gdImageLine(ic->im, textx + 2, texty + 16, textx + 392 + offsetx, texty + 16, ic->cline);
+               gdImageLine(ic->im, textx + 300 + offsetx, texty + 2, textx + 300 + offsetx, texty + 40 + offsety + (12 * rowcount), ic->cline);
        } else {
-               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
-               gdImageLine(ic->im, textx+2, texty+16, textx+296+offsetx, texty+16, ic->cline);
+               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
+               gdImageLine(ic->im, textx + 2, texty + 16, textx + 296 + offsetx, texty + 16, ic->cline);
        }
-       gdImageLine(ic->im, textx+144+offsetx, texty+2, textx+144+offsetx, texty+40+offsety+(12*rowcount), ic->cline);
-       gdImageLine(ic->im, textx+222+offsetx, texty+2, textx+222+offsetx, texty+40+offsety+(12*rowcount), ic->cline);
+       gdImageLine(ic->im, textx + 144 + offsetx, texty + 2, textx + 144 + offsetx, texty + 40 + offsety + (12 * rowcount), ic->cline);
+       gdImageLine(ic->im, textx + 222 + offsetx, texty + 2, textx + 222 + offsetx, texty + 40 + offsety + (12 * rowcount), ic->cline);
 
        texty += 20;
 
@@ -655,14 +655,14 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                        strftime(datebuff, 16, cfg.dformat, d);
                        if (strcmp(daybuff, datebuff) != 0) {
                                snprintf(buffer, 32, " %s", datebuff);
-                               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
+                               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
                                texty += 12;
                                strcpy(daybuff, datebuff);
                        }
                }
 
                if (listtype == 4) {
-                       if (strftime(datebuff, 16, stampformat, d)<=8) {
+                       if (strftime(datebuff, 16, stampformat, d) <= 8) {
                                snprintf(buffer, 32, "  %2d   %*s", i, getpadding(8, datebuff), datebuff);
                                strcat(buffer, "   ");
                        } else {
@@ -670,13 +670,13 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                        }
                        if (strcmp(datebuff, daybuff) == 0) {
                                if (cfg.ostyle > 2) {
-                                       gdImageFilledRectangle(ic->im, textx+2, texty+2, textx+422, texty+12, ic->cbgoffset);
+                                       gdImageFilledRectangle(ic->im, textx + 2, texty + 2, textx + 422, texty + 12, ic->cbgoffset);
                                } else {
-                                       gdImageFilledRectangle(ic->im, textx+2, texty+2, textx+326, texty+12, ic->cbgoffset);
+                                       gdImageFilledRectangle(ic->im, textx + 2, texty + 2, textx + 326, texty + 12, ic->cbgoffset);
                                }
                        }
                } else {
-                       if (strftime(datebuff, 16, stampformat, d)<=8) {
+                       if (strftime(datebuff, 16, stampformat, d) <= 8) {
                                snprintf(buffer, 32, "  %*s", getpadding(8, datebuff), datebuff);
                                strcat(buffer, "   ");
                        } else {
@@ -687,21 +687,21 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                strcat(buffer, "   ");
                strncat(buffer, getvalue(datalist_i->tx, 10, RT_Normal), 32);
                strcat(buffer, "   ");
-               strncat(buffer, getvalue(datalist_i->rx+datalist_i->tx, 10, RT_Normal), 32);
-               if (cfg.ostyle>2) {
+               strncat(buffer, getvalue(datalist_i->rx + datalist_i->tx, 10, RT_Normal), 32);
+               if (cfg.ostyle > 2) {
                        strcat(buffer, "  ");
                        if (datalist_i->next == NULL) {
                                d = localtime(&ic->interface.updated);
                                if (listtype == 1) { // day
-                                       e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+                                       e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
                                } else if (listtype == 2) { // month
                                        e_secs = (uint64_t)mosecs(datalist_i->timestamp, ic->interface.updated);
                                } else if (listtype == 3) { // year
-                                       e_secs = (uint64_t)(d->tm_yday*86400+d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+                                       e_secs = (uint64_t)(d->tm_yday * 86400 + d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
                                } else if (listtype == 4) { // top
                                        e_secs = 86400;
                                } else if (listtype == 5) { // hour
-                                       e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60));
+                                       e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60));
                                } else if (listtype == 6) { // 5min
                                        e_secs = 300;
                                }
@@ -711,27 +711,27 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                                } else if (listtype == 2) { // month
                                        e_secs = (uint64_t)(dmonth(d->tm_mon) * 86400);
                                } else if (listtype == 3) { // year
-                                       e_secs = (uint64_t)((365 + isleapyear(d->tm_year+1900)) * 86400);
+                                       e_secs = (uint64_t)((365 + isleapyear(d->tm_year + 1900)) * 86400);
                                } else if (listtype == 5) { // hour
                                        e_secs = 3600;
                                } else if (listtype == 6) { // 5min
                                        e_secs = 300;
                                }
                        }
-                       strncat(buffer, gettrafficrate(datalist_i->rx+datalist_i->tx, (time_t)e_secs, 14), 32);
+                       strncat(buffer, gettrafficrate(datalist_i->rx + datalist_i->tx, (time_t)e_secs, 14), 32);
                }
-               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
                if (listtype == 4) { // top
-                       if (cfg.ostyle>2) {
-                               drawbar(ic, textx+428, texty+4, 52, datalist_i->rx, datalist_i->tx, datainfo.max);
+                       if (cfg.ostyle > 2) {
+                               drawbar(ic, textx + 428, texty + 4, 52, datalist_i->rx, datalist_i->tx, datainfo.max);
                        } else {
-                               drawbar(ic, textx+336, texty+4, 140, datalist_i->rx, datalist_i->tx, datainfo.max);
+                               drawbar(ic, textx + 336, texty + 4, 140, datalist_i->rx, datalist_i->tx, datainfo.max);
                        }
                } else { // everything else
-                       if (cfg.ostyle>2) {
-                               drawbar(ic, textx+400, texty+4, 78, datalist_i->rx, datalist_i->tx, datainfo.max);
+                       if (cfg.ostyle > 2) {
+                               drawbar(ic, textx + 400, texty + 4, 78, datalist_i->rx, datalist_i->tx, datainfo.max);
                        } else {
-                               drawbar(ic, textx+304, texty+4, 170, datalist_i->rx, datalist_i->tx, datainfo.max);
+                               drawbar(ic, textx + 304, texty + 4, 170, datalist_i->rx, datalist_i->tx, datainfo.max);
                        }
                }
                texty += 12;
@@ -747,20 +747,20 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                if (cfg.ostyle > 2) {
                        i += 46;
                }
-               gdImageString(ic->im, gdFontGetSmall(), textx+i, texty, (unsigned char*)"no data available", ic->ctext);
+               gdImageString(ic->im, gdFontGetSmall(), textx + i, texty, (unsigned char *)"no data available", ic->ctext);
                texty += 12;
        }
 
        if (cfg.ostyle > 2) {
-               gdImageLine(ic->im, textx+2, texty+5, textx+392+offsetx, texty+5, ic->cline);
+               gdImageLine(ic->im, textx + 2, texty + 5, textx + 392 + offsetx, texty + 5, ic->cline);
        } else {
-               gdImageLine(ic->im, textx+2, texty+5, textx+296+offsetx, texty+5, ic->cline);
+               gdImageLine(ic->im, textx + 2, texty + 5, textx + 296 + offsetx, texty + 5, ic->cline);
        }
 
        if ((strlen(ic->dataend) == 0 && datainfo.count > 0 && listtype < 4) || (strlen(ic->dataend) > 0 && datainfo.count > 1 && listtype != 4)) {
 
                d = localtime(&ic->interface.updated);
-               if ( datalist_i->rx==0 || datalist_i->tx==0 || strlen(ic->dataend)>0) {
+               if (datalist_i->rx == 0 || datalist_i->tx == 0 || strlen(ic->dataend) > 0) {
                        e_rx = e_tx = 0;
                } else {
                        div = 0;
@@ -788,10 +788,10 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                        strcat(buffer, "   ");
                        strncat(buffer, getvalue(e_tx, 10, RT_Estimate), 32);
                        strcat(buffer, "   ");
-                       strncat(buffer, getvalue(e_rx+e_tx, 10, RT_Estimate), 32);
+                       strncat(buffer, getvalue(e_rx + e_tx, 10, RT_Estimate), 32);
                } else {
                        if (datainfo.count < 100) {
-                               snprintf(datebuff, 16, "sum of %"PRIu32"", datainfo.count);
+                               snprintf(datebuff, 16, "sum of %" PRIu32 "", datainfo.count);
                        } else {
                                snprintf(datebuff, 16, "sum");
                        }
@@ -803,7 +803,7 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                        strncat(buffer, getvalue(datainfo.sumrx + datainfo.sumtx, 10, RT_Normal), 32);
                }
 
-               gdImageString(ic->im, gdFontGetSmall(), textx, texty+8, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetSmall(), textx, texty + 8, (unsigned char *)buffer, ic->ctext);
        }
 
        dbdatalistfree(&datalist);
@@ -843,7 +843,7 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
                headermod = 0;
        }
 
-       yesterday=ic->current-86400;
+       yesterday = ic->current - 86400;
 
        ic->im = gdImageCreate(width, height);
 
@@ -874,15 +874,15 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
        }
 
        /* today / latest day */
-       if ( data_current->rx + data_current->tx == 0 ) {
+       if (data_current->rx + data_current->tx == 0) {
                rxp = txp = 0;
        } else {
-               rxp = data_current->rx / (float)( data_current->rx + data_current->tx ) * 100;
+               rxp = data_current->rx / (float)(data_current->rx + data_current->tx) * 100;
                txp = (float)100 - rxp;
        }
 
        /* do scaling if needed */
-       if ( data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx) ) {
+       if (data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx)) {
                mod = (data_current->rx + data_current->tx) / (float)(data_previous->rx + data_previous->tx);
                rxp = rxp * mod;
                txp = txp * mod;
@@ -893,10 +893,10 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
                offset = 85;
        }
 
-       drawdonut(ic, 150+offset, 75-headermod, rxp, txp);
+       drawdonut(ic, 150 + offset, 75 - headermod, rxp, txp);
 
-       textx = 100+offset;
-       texty = 30-headermod;
+       textx = 100 + offset;
+       texty = 30 - headermod;
 
        /* get formated date for today */
        d = localtime(&ic->current);
@@ -907,51 +907,51 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
        strftime(daytemp, 16, cfg.dformat, d);
 
        /* change daytemp to today if formated days match */
-       if (strcmp(datebuff, daytemp)==0) {
+       if (strcmp(datebuff, daytemp) == 0) {
                strncpy_nt(daytemp, "today", 32);
        }
 
        snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
-       gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
 
        if (cfg.summaryrate) {
                d = localtime(&ic->interface.updated);
-               snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx+data_current->tx, d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600), 15));
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+               snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx + data_current->tx, d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600), 15));
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
        } else {
                texty += 7;
        }
 
        snprintf(buffer, 4, "rx ");
        strncat(buffer, getvalue(data_current->rx, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
        snprintf(buffer, 4, "tx ");
        strncat(buffer, getvalue(data_current->tx, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
        snprintf(buffer, 4, " = ");
-       strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+       strncat(buffer, getvalue(data_current->rx + data_current->tx, 12, RT_Normal), 32);
+       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
 
        /* yesterday */
        if (data_previous != NULL) {
-               if ( data_previous->rx + data_previous->tx == 0 ) {
+               if (data_previous->rx + data_previous->tx == 0) {
                        rxp = txp = 0;
                } else {
-                       rxp = data_previous->rx / (float)( data_previous->rx + data_previous->tx ) * 100;
+                       rxp = data_previous->rx / (float)(data_previous->rx + data_previous->tx) * 100;
                        txp = (float)100 - rxp;
                }
 
                /* do scaling if needed */
-               if ( (data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx) ) {
+               if ((data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx)) {
                        mod = (data_previous->rx + data_previous->tx) / (float)(data_current->rx + data_current->tx);
                        rxp = rxp * mod;
                        txp = txp * mod;
                }
 
-               drawdonut(ic, 330, 75-headermod, rxp, txp);
+               drawdonut(ic, 330, 75 - headermod, rxp, txp);
 
                textx = 280;
-               texty = 30-headermod;
+               texty = 30 - headermod;
 
                /* get formated date for yesterday */
                d = localtime(&yesterday);
@@ -962,29 +962,29 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
                strftime(daytemp, 16, cfg.dformat, d);
 
                /* change daytemp to yesterday if formated days match */
-               if (strcmp(datebuff, daytemp)==0) {
+               if (strcmp(datebuff, daytemp) == 0) {
                        strncpy_nt(daytemp, "yesterday", 32);
                }
 
                snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
-               gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
 
                if (cfg.summaryrate) {
-                       snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx+data_previous->tx, 86400, 15));
-                       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+                       snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx + data_previous->tx, 86400, 15));
+                       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
                } else {
                        texty += 7;
                }
 
                snprintf(buffer, 4, "rx ");
                strncat(buffer, getvalue(data_previous->rx, 12, RT_Normal), 32);
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
                snprintf(buffer, 4, "tx ");
                strncat(buffer, getvalue(data_previous->tx, 12, RT_Normal), 32);
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
                snprintf(buffer, 4, " = ");
-               strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, RT_Normal), 32);
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+               strncat(buffer, getvalue(data_previous->rx + data_previous->tx, 12, RT_Normal), 32);
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
        }
 
        data_current = NULL;
@@ -1004,15 +1004,15 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
        }
 
        /* current month */
-       if ( data_current->rx + data_current->tx == 0 ) {
+       if (data_current->rx + data_current->tx == 0) {
                rxp = txp = 0;
        } else {
-               rxp = data_current->rx / (float)( data_current->rx + data_current->tx ) * 100;
+               rxp = data_current->rx / (float)(data_current->rx + data_current->tx) * 100;
                txp = (float)100 - rxp;
        }
 
        /* do scaling if needed */
-       if ( data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx) ) {
+       if (data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx)) {
                mod = (data_current->rx + data_current->tx) / (float)(data_previous->rx + data_previous->tx);
                rxp = rxp * mod;
                txp = txp * mod;
@@ -1025,77 +1025,77 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
                offset = 0;
        }
 
-       drawdonut(ic, 150+offset, 163-headermod, rxp, txp);
+       drawdonut(ic, 150 + offset, 163 - headermod, rxp, txp);
 
-       textx = 100+offset;
-       texty = 118-headermod;
+       textx = 100 + offset;
+       texty = 118 - headermod;
 
        d = localtime(&data_current->timestamp);
        strftime(daytemp, 16, cfg.mformat, d);
 
        snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
-       gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
 
        if (cfg.summaryrate) {
-               snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx+data_current->tx, mosecs(data_current->timestamp, ic->interface.updated), 15));
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+               snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx + data_current->tx, mosecs(data_current->timestamp, ic->interface.updated), 15));
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
        } else {
                texty += 7;
        }
 
        snprintf(buffer, 4, "rx ");
        strncat(buffer, getvalue(data_current->rx, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
        snprintf(buffer, 4, "tx ");
        strncat(buffer, getvalue(data_current->tx, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
        snprintf(buffer, 4, " = ");
-       strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+       strncat(buffer, getvalue(data_current->rx + data_current->tx, 12, RT_Normal), 32);
+       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
 
        /* previous month */
        if (data_previous != NULL) {
-               if ( data_previous->rx + data_previous->tx == 0 ) {
+               if (data_previous->rx + data_previous->tx == 0) {
                        rxp = txp = 0;
                } else {
-                       rxp = data_previous->rx / (float)( data_previous->rx + data_previous->tx ) * 100;
+                       rxp = data_previous->rx / (float)(data_previous->rx + data_previous->tx) * 100;
                        txp = (float)100 - rxp;
                }
 
                /* do scaling if needed */
-               if ( (data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx) ) {
+               if ((data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx)) {
                        mod = (data_previous->rx + data_previous->tx) / (float)(data_current->rx + data_current->tx);
                        rxp = rxp * mod;
                        txp = txp * mod;
                }
 
-               drawdonut(ic, 330, 163-headermod, rxp, txp);
+               drawdonut(ic, 330, 163 - headermod, rxp, txp);
 
                textx = 280;
-               texty = 118-headermod;
+               texty = 118 - headermod;
 
                d = localtime(&data_previous->timestamp);
                strftime(daytemp, 16, cfg.mformat, d);
 
                snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
-               gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
 
                if (cfg.summaryrate) {
-                       snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx+data_previous->tx, dmonth(d->tm_mon)*86400, 15));
-                       gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+                       snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx + data_previous->tx, dmonth(d->tm_mon) * 86400, 15));
+                       gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
                } else {
                        texty += 7;
                }
 
                snprintf(buffer, 4, "rx ");
                strncat(buffer, getvalue(data_previous->rx, 12, RT_Normal), 32);
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
                snprintf(buffer, 4, "tx ");
                strncat(buffer, getvalue(data_previous->tx, 12, RT_Normal), 32);
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
                snprintf(buffer, 4, " = ");
-               strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, RT_Normal), 32);
-               gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+               strncat(buffer, getvalue(data_previous->rx + data_previous->tx, 12, RT_Normal), 32);
+               gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
        }
 
        data_current = NULL;
@@ -1104,33 +1104,33 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate)
 
        /* all time */
        textx = 385;
-       texty = 57-headermod;
+       texty = 57 - headermod;
 
-       gdImageString(ic->im, gdFontGetLarge(), textx+12, texty, (unsigned char*)"all time", ic->ctext);
+       gdImageString(ic->im, gdFontGetLarge(), textx + 12, texty, (unsigned char *)"all time", ic->ctext);
        snprintf(buffer, 4, "rx ");
        strncat(buffer, getvalue(ic->interface.rxtotal, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx, texty+24, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), textx, texty + 24, (unsigned char *)buffer, ic->ctext);
        snprintf(buffer, 4, "tx ");
        strncat(buffer, getvalue(ic->interface.txtotal, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx, texty+36, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), textx, texty + 36, (unsigned char *)buffer, ic->ctext);
        snprintf(buffer, 4, " = ");
-       strncat(buffer, getvalue(ic->interface.rxtotal+ic->interface.txtotal, 12, RT_Normal), 32);
-       gdImageString(ic->im, gdFontGetSmall(), textx, texty+50, (unsigned char*)buffer, ic->ctext);
+       strncat(buffer, getvalue(ic->interface.rxtotal + ic->interface.txtotal, 12, RT_Normal), 32);
+       gdImageString(ic->im, gdFontGetSmall(), textx, texty + 50, (unsigned char *)buffer, ic->ctext);
        d = localtime(&ic->interface.created);
        strftime(datebuff, 16, cfg.tformat, d);
        snprintf(daytemp, 24, "since %s", datebuff);
        snprintf(buffer, 32, "%23s", daytemp);
-       gdImageString(ic->im, gdFontGetSmall(), textx-48, texty+70, (unsigned char*)buffer, ic->ctext);
+       gdImageString(ic->im, gdFontGetSmall(), textx - 48, texty + 70, (unsigned char *)buffer, ic->ctext);
 
-       drawlegend(ic, 410, 155-headermod);
+       drawlegend(ic, 410, 155 - headermod);
 
        /* hours if requested */
        switch (type) {
                case 1:
-                       drawhours(ic, 500, 46-headermod, rate);
+                       drawhours(ic, 500, 46 - headermod, rate);
                        break;
                case 2:
-                       drawhours(ic, 12, 215-headermod, rate);
+                       drawhours(ic, 12, 215 - headermod, rate);
                        break;
                default:
                        break;
@@ -1148,13 +1148,13 @@ void hextorgb(char *input, int *rgb)
                offset = 0;
        }
 
-       snprintf(hex, 3, "%c%c", input[(0+offset)], input[(1+offset)]);
+       snprintf(hex, 3, "%c%c", input[(0 + offset)], input[(1 + offset)]);
        snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16));
        rgb[0] = atoi(dec);
-       snprintf(hex, 3, "%c%c", input[(2+offset)], input[(3+offset)]);
+       snprintf(hex, 3, "%c%c", input[(2 + offset)], input[(3 + offset)]);
        snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16));
        rgb[1] = atoi(dec);
-       snprintf(hex, 3, "%c%c", input[(4+offset)], input[(5+offset)]);
+       snprintf(hex, 3, "%c%c", input[(4 + offset)], input[(5 + offset)]);
        snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16));
        rgb[2] = atoi(dec);
 
@@ -1171,27 +1171,27 @@ void modcolor(int *rgb, const int offset, const int force)
                printf("m%d (%d): %d, %d, %d -> ", offset, force, rgb[0], rgb[1], rgb[2]);
        }
 
-       for (i=0; i<3; i++) {
-               if ((rgb[i]+offset)>255 || (rgb[i]+offset)<0) {
+       for (i = 0; i < 3; i++) {
+               if ((rgb[i] + offset) > 255 || (rgb[i] + offset) < 0) {
                        overflow++;
                }
        }
 
        /* positive offset gives lighter color, negative darker if forced */
        /* otherwise the direction is changed depending on possible overflows */
-       for (i=0; i<3; i++) {
-               if (overflow<2 || force) {
-                       if ((rgb[i]+offset)>255) {
+       for (i = 0; i < 3; i++) {
+               if (overflow < 2 || force) {
+                       if ((rgb[i] + offset) > 255) {
                                rgb[i] = 255;
-                       } else if ((rgb[i]+offset)<0) {
+                       } else if ((rgb[i] + offset) < 0) {
                                rgb[i] = 0;
                        } else {
                                rgb[i] += offset;
                        }
                } else {
-                       if ((rgb[i]-offset)<0) {
+                       if ((rgb[i] - offset) < 0) {
                                rgb[i] = 0;
-                       } else if ((rgb[i]-offset)>255) {
+                       } else if ((rgb[i] - offset) > 255) {
                                rgb[i] = 255;
                        } else {
                                rgb[i] -= offset;
@@ -1210,21 +1210,21 @@ char *getimagevalue(const uint64_t b, const int len, const int rate)
        int i, declen = 0, unit = 0, p = 1024;
        uint64_t limit;
 
-       if (b==0){
+       if (b == 0) {
                snprintf(buffer, 64, "%*s", len, "--");
        } else {
                if (rate && (getunit() == 2 || getunit() == 4)) {
                        p = 1000;
                        unit = getunit();
                }
-               for (i=UNITPREFIXCOUNT-1; i>0; i--) {
-                       limit = (uint64_t)(pow(p, i-1)) * 1000;
+               for (i = UNITPREFIXCOUNT - 1; i > 0; i--) {
+                       limit = (uint64_t)(pow(p, i - 1)) * 1000;
                        if (b >= limit) {
-                               snprintf(buffer, 64, "%*.*f", len, declen, b/(double)(getunitdivisor(unit, i+1)));
+                               snprintf(buffer, 64, "%*.*f", len, declen, b / (double)(getunitdivisor(unit, i + 1)));
                                return buffer;
                        }
                }
-               snprintf(buffer, 64, "%*"PRIu64"", len, b);
+               snprintf(buffer, 64, "%*" PRIu64 "", len, b);
        }
 
        return buffer;
@@ -1237,19 +1237,19 @@ char *getimagescale(const uint64_t b, const int rate)
 
        unit = getunit();
 
-       if (b==0) {
+       if (b == 0) {
                snprintf(buffer, 8, "--");
        } else {
                if (rate) {
                        if (unit == 2 || unit == 4) {
                                p = 1000;
                        }
-                       while (div < UNITPREFIXCOUNT && b >= (pow(p, div-1) * 1000)) {
+                       while (div < UNITPREFIXCOUNT && b >= (pow(p, div - 1) * 1000)) {
                                div++;
                        }
                        snprintf(buffer, 8, "%s", getrateunitprefix(unit, div));
                } else {
-                       while (div < UNITPREFIXCOUNT && b >= (pow(p, div-1) * 1000)) {
+                       while (div < UNITPREFIXCOUNT && b >= (pow(p, div - 1) * 1000)) {
                                div++;
                        }
                        snprintf(buffer, 8, "%s", getunitprefix(div));
@@ -1271,17 +1271,17 @@ uint64_t getscale(const uint64_t input, const int rate)
        }
 
        /* get unit */
-       for (i=0; result>=div; i++) {
+       for (i = 0; result >= div; i++) {
                result = result / div;
        }
 
        /* round result depending of scale */
-       if (result>=300) {
-               result = result/4 + (100 - ((result/4) % 100));
-       } else if (result>20) {
-               result = result/4 + (10 - ((result/4) % 10));
+       if (result >= 300) {
+               result = result / 4 + (100 - ((result / 4) % 100));
+       } else if (result > 20) {
+               result = result / 4 + (10 - ((result / 4) % 10));
        } else {
-               result = result/4;
+               result = result / 4;
        }
 
        /* put unit back */
index bb7d130c4034d2fe03dc62c9c99148d01f2baa38..1842e7cb2e954fb4ed655426e287a655a944ef3a 100644 (file)
@@ -1,12 +1,12 @@
 #ifndef IMAGE_H
 #define IMAGE_H
 
-#include <gd.h>        /* libgd2-dev libgd2 */
-#include <gdfontt.h>   /* gdFontGetTiny() */
-#include <gdfonts.h>   /* gdFontGetSmall() */
-#include <gdfontmb.h>  /* gdFontGetMediumBold() */
-#include <gdfontl.h>   /* gdFontGetLarge() */
-#include <gdfontg.h>   /* gdFontGetGiant() */
+#include <gd.h>                  /* libgd2-dev libgd2 */
+#include <gdfontt.h>  /* gdFontGetTiny() */
+#include <gdfonts.h>  /* gdFontGetSmall() */
+#include <gdfontmb.h> /* gdFontGetMediumBold() */
+#include <gdfontl.h>  /* gdFontGetLarge() */
+#include <gdfontg.h>  /* gdFontGetGiant() */
 
 /* rectangle size */
 #define YBEGINOFFSET (-1)
index f5348cc483c95274785dda29559b8131212e4fd2..19027de698f11a4ca735d54628005eded86fdbaf 100644 (file)
@@ -1,16 +1,16 @@
 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__FreeBSD_kernel__)
-  #if defined(__clang__)
-    #pragma clang diagnostic push
-    #pragma clang diagnostic ignored "-Wreserved-id-macro"
-  #endif
-  #define _XOPEN_SOURCE 600
-  #if defined(__clang__)
-    #pragma clang diagnostic pop
-  #endif
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreserved-id-macro"
+#endif
+#define _XOPEN_SOURCE 600
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
 #endif
 /* enable wcswidth on kFreeBSD */
 #if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
-  #define __USE_XOPEN
+#define __USE_XOPEN
 #endif
 #include "common.h"
 #include "misc.h"
@@ -36,7 +36,7 @@ int spacecheck(const char *path)
                }
        }
 
-       free = (uint64_t)(buf.f_bavail/(float)1024) * buf.f_bsize;
+       free = (uint64_t)(buf.f_bavail / (float)1024) * buf.f_bsize;
 
        if (debug) {
                printf("bsize %d\n", (int)buf.f_bsize);
@@ -44,13 +44,13 @@ int spacecheck(const char *path)
                printf("bfree %lu\n", (unsigned long int)buf.f_bfree);
                printf("bavail %lu\n", (unsigned long int)buf.f_bavail);
                printf("ffree %lu\n", (unsigned long int)buf.f_ffree);
-               printf("%"PRIu64" free space left\n", free);
+               printf("%" PRIu64 " free space left\n", free);
        }
 
-       /* the database is less than 3kB but let's require */
-       /* 1MB to be on the safe side, anyway, the filesystem should */
+       /* the database is likely to be less than 200 kiB but let's require */
+       /* 1 MiB to be on the safe side, anyway, the filesystem should */
        /* always have more free space than that */
-       if (free<=1024) {
+       if (free <= 1024) {
                return 0;
        } else {
                return 1;
@@ -80,7 +80,6 @@ void sighandler(int sig)
                        default:
                                snprintf(errorstring, 1024, "DEBUG: Unknown signal %d", sig);
                                break;
-
                }
                printe(PT_Info);
        }
@@ -88,13 +87,13 @@ void sighandler(int sig)
 
 uint64_t getbtime(void)
 {
-       uint64_t result=0;
+       uint64_t result = 0;
 #if defined(__linux__)
        FILE *fp;
        int check;
        char temp[64], statline[128];
 
-       if ((fp=fopen("/proc/stat","r"))==NULL) {
+       if ((fp = fopen("/proc/stat", "r")) == NULL) {
                snprintf(errorstring, 1024, "Unable to read /proc/stat: %s", strerror(errno));
                printe(PT_Error);
                if (noexit) {
@@ -104,19 +103,19 @@ uint64_t getbtime(void)
                }
        }
 
-       check=0;
-       while (fgets(statline,128,fp)!=NULL) {
-               sscanf(statline,"%63s",temp);
-               if (strcmp(temp,"btime")==0) {
+       check = 0;
+       while (fgets(statline, 128, fp) != NULL) {
+               sscanf(statline, "%63s", temp);
+               if (strcmp(temp, "btime") == 0) {
                        /* if (debug)
                                printf("\n%s\n",statline); */
-                       check=1;
+                       check = 1;
                        break;
                }
        }
        fclose(fp);
 
-       if (check==0) {
+       if (check == 0) {
                snprintf(errorstring, 1024, "btime missing from /proc/stat.");
                printe(PT_Error);
                if (noexit) {
@@ -126,7 +125,7 @@ uint64_t getbtime(void)
                }
        }
 
-       result = strtoull(statline+6, (char **)NULL, 0);
+       result = strtoull(statline + 6, (char **)NULL, 0);
 
 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
        struct timeval btm;
@@ -159,28 +158,28 @@ char *getvalue(const uint64_t bytes, const int len, const RequestType type)
                p = 1000;
        }
 
-       if ( (type == RT_Estimate) && (bytes == 0) ) {
-               declen = len-(int)strlen(getunitprefix(2))-2;
+       if ((type == RT_Estimate) && (bytes == 0)) {
+               declen = len - (int)strlen(getunitprefix(2)) - 2;
                if (declen < 2) {
                        declen = 2;
                }
                snprintf(buffer, 64, "%*s  %*s", declen, "--", (int)strlen(getunitprefix(2)), " ");
        } else {
-               for (i=UNITPREFIXCOUNT-1; i>0; i--) {
-                       limit = (uint64_t)(pow(p, i-1)) * 1000;
+               for (i = UNITPREFIXCOUNT - 1; i > 0; i--) {
+                       limit = (uint64_t)(pow(p, i - 1)) * 1000;
                        if (bytes >= limit) {
-                               if (i>1) {
-                                       snprintf(buffer, 64, "%"DECCONV"*.*f %s", getunitspacing(len, 5), declen, bytes/(double)(getunitdivisor(cfg.unitmode, i+1)), getunitprefix(i+1));
+                               if (i > 1) {
+                                       snprintf(buffer, 64, "%" DECCONV "*.*f %s", getunitspacing(len, 5), declen, bytes / (double)(getunitdivisor(cfg.unitmode, i + 1)), getunitprefix(i + 1));
                                } else {
                                        if (type == RT_Estimate) {
                                                declen = 0;
                                        }
-                                       snprintf(buffer, 64, "%"DECCONV"*.*f %s", getunitspacing(len, 2), declen, bytes/(double)(getunitdivisor(cfg.unitmode, i+1)), getunitprefix(i+1));
+                                       snprintf(buffer, 64, "%" DECCONV "*.*f %s", getunitspacing(len, 2), declen, bytes / (double)(getunitdivisor(cfg.unitmode, i + 1)), getunitprefix(i + 1));
                                }
                                return buffer;
                        }
                }
-               snprintf(buffer, 64, "%"DECCONV"*"PRIu64" %s", getunitspacing(len, 1), bytes, getunitprefix(1));
+               snprintf(buffer, 64, "%" DECCONV "*" PRIu64 " %s", getunitspacing(len, 1), bytes, getunitprefix(1));
        }
 
        return buffer;
@@ -206,7 +205,7 @@ char *gettrafficrate(const uint64_t bytes, const time_t interval, const int len)
        int declen = cfg.defaultdecimals;
        uint64_t b;
 
-       if (interval==0) {
+       if (interval == 0) {
                snprintf(buffer, 64, "%*s", len, "n/a");
                return buffer;
        }
@@ -219,7 +218,7 @@ char *gettrafficrate(const uint64_t bytes, const time_t interval, const int len)
                }
        } else {
                b = bytes;
-               if (interval < 5 && ( b / (uint64_t)interval ) < 1000) {
+               if (interval < 5 && (b / (uint64_t)interval) < 1000) {
                        declen = 0;
                }
        }
@@ -229,43 +228,47 @@ char *gettrafficrate(const uint64_t bytes, const time_t interval, const int len)
 
 const char *getunitprefix(const int index)
 {
+       /* clang-format off */
     static const char *unitprefix[] = { "na",
         "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB",  /* IEC   - 1024^n */
         "B", "KB",  "MB",  "GB",  "TB",  "PB",  "EB",   /* JEDEC - 1024^n */
         "B", "kB",  "MB",  "GB",  "TB",  "PB",  "EB" }; /* SI    - 1000^n */
+       /* clang-format on */
 
-       if (index>UNITPREFIXCOUNT) {
+       if (index > UNITPREFIXCOUNT) {
                return unitprefix[0];
        } else {
-               return unitprefix[(cfg.unitmode*UNITPREFIXCOUNT)+index];
+               return unitprefix[(cfg.unitmode * UNITPREFIXCOUNT) + index];
        }
 }
 
 const char *getrateunitprefix(const int unitmode, const int index)
 {
+       /* clang-format off */
     static const char *rateunitprefix[] = { "na",
         "B/s",     "KiB/s",   "MiB/s",   "GiB/s",   "TiB/s",   "PiB/s",   "EiB/s",    /* IEC   - 1024^n */
         "B/s",     "KB/s",    "MB/s",    "GB/s",    "TB/s",    "PB/s",    "EB/s",     /* JEDEC - 1024^n */
         "B/s",     "kB/s",    "MB/s",    "GB/s",    "TB/s",    "PB/s",    "EB/s",     /* SI    - 1000^n */
         "bit/s",   "Kibit/s", "Mibit/s", "Gibit/s", "Tibit/s", "Pibit/s", "Eibit/s",  /* IEC   - 1024^n */
         "bit/s",   "kbit/s",  "Mbit/s",  "Gbit/s",  "Tbit/s",  "Pbit/s",  "Ebit/s" }; /* SI    - 1000^n */
+       /* clang-format on */
 
-       if (index>UNITPREFIXCOUNT) {
+       if (index > UNITPREFIXCOUNT) {
                return rateunitprefix[0];
        } else {
-               return rateunitprefix[(unitmode*UNITPREFIXCOUNT)+index];
+               return rateunitprefix[(unitmode * UNITPREFIXCOUNT) + index];
        }
 }
 
 uint64_t getunitdivisor(const int unitmode, const int index)
 {
-       if (index>UNITPREFIXCOUNT) {
+       if (index > UNITPREFIXCOUNT) {
                return 1;
        } else {
                if (unitmode == 2 || unitmode == 4) {
-                       return (uint64_t)(pow(1000, index-1));
+                       return (uint64_t)(pow(1000, index - 1));
                } else {
-                       return (uint64_t)(pow(1024, index-1));
+                       return (uint64_t)(pow(1024, index - 1));
                }
        }
 }
@@ -295,18 +298,17 @@ char *getratestring(const uint64_t rate, const int len, const int declen)
                p = 1000;
        }
 
-       for (i=UNITPREFIXCOUNT-1; i>0; i--)
-       {
-               limit = (uint64_t)(pow(p, i-1)) * 1000;
+       for (i = UNITPREFIXCOUNT - 1; i > 0; i--) {
+               limit = (uint64_t)(pow(p, i - 1)) * 1000;
                if (rate >= limit) {
-                       l = getratespacing(len, unit, i+1);
-                       snprintf(buffer, 64, "%"DECCONV"*.2f %s", l, rate/(double)(getunitdivisor(unit, i+1)), getrateunitprefix(unit, i+1));
+                       l = getratespacing(len, unit, i + 1);
+                       snprintf(buffer, 64, "%" DECCONV "*.2f %s", l, rate / (double)(getunitdivisor(unit, i + 1)), getrateunitprefix(unit, i + 1));
                        return buffer;
                }
        }
 
        l = getratespacing(len, unit, 1);
-       snprintf(buffer, 64, "%"DECCONV"*.*f %s", l, declen, rate/(double)(getunitdivisor(unit, 1)), getrateunitprefix(unit, 1));
+       snprintf(buffer, 64, "%" DECCONV "*.*f %s", l, declen, rate / (double)(getunitdivisor(unit, 1)), getrateunitprefix(unit, 1));
        return buffer;
 }
 
@@ -363,20 +365,20 @@ int validatedatetime(const char *str)
 {
        short valid;
        unsigned int len, i, t;
-       const char *templates[] = { "dddd-dd-dd dd:dd", "dddd-dd-dd" };
+       const char *templates[] = {"dddd-dd-dd dd:dd", "dddd-dd-dd"};
 
        len = (unsigned int)strlen(str);
        if (len > strlen(templates[0])) {
                return 0;
        }
 
-       for (t=0; t<2; t++) {
+       for (t = 0; t < 2; t++) {
                if (len != strlen(templates[t])) {
                        continue;
                }
                valid = 1;
-               for (i=0; i<strlen(templates[t]); i++) {
-                       switch(templates[t][i]) {
+               for (i = 0; i < strlen(templates[t]); i++) {
+                       switch (templates[t][i]) {
                                case 'd':
                                        if (!isdigit(str[i])) {
                                                valid = 0;
index d5a125b68a84b34bf2aa198d0bf5b9c8d51cfc6f..fdbc86dd7bab0b332c45c088d2fb44b82c5ab409 100644 (file)
@@ -17,7 +17,7 @@ void trafficmeter(char iface[], unsigned int sampletime)
        }
 
        /* less than 2 seconds doesn't produce good results */
-       if (sampletime<2) {
+       if (sampletime < 2) {
                printf("Error: Time for sampling too short.\n");
                exit(EXIT_FAILURE);
        }
@@ -38,17 +38,17 @@ void trafficmeter(char iface[], unsigned int sampletime)
                snprintf(buffer, 256, "Sampling %s (%u seconds average)", iface, sampletime);
                printf("%s", buffer);
                fflush(stdout);
-               sleep(sampletime/3);
+               sleep(sampletime / 3);
                printf(".");
                fflush(stdout);
-               sleep(sampletime/3);
+               sleep(sampletime / 3);
                printf(".");
                fflush(stdout);
-               sleep(sampletime/3);
+               sleep(sampletime / 3);
                printf(".");
                fflush(stdout);
-               if ((sampletime/3)*3!=sampletime) {
-                       sleep(sampletime-((sampletime/3)*3));
+               if ((sampletime / 3) * 3 != sampletime) {
+                       sleep(sampletime - ((sampletime / 3) * 3));
                }
 
                cursortocolumn(1);
@@ -71,10 +71,10 @@ void trafficmeter(char iface[], unsigned int sampletime)
 
        /* show the difference in a readable format or json */
        if (!json) {
-               printf("%"PRIu64" packets sampled in %d seconds\n", rxp+txp, sampletime);
+               printf("%" PRIu64 " packets sampled in %d seconds\n", rxp + txp, sampletime);
                printf("Traffic average for %s\n", iface);
-               printf("\n      rx     %s         %5"PRIu64" packets/s\n", gettrafficrate(rx, sampletime, 15), (uint64_t)(rxp/sampletime));
-               printf("      tx     %s         %5"PRIu64" packets/s\n\n", gettrafficrate(tx, sampletime, 15), (uint64_t)(txp/sampletime));
+               printf("\n      rx     %s         %5" PRIu64 " packets/s\n", gettrafficrate(rx, sampletime, 15), (uint64_t)(rxp / sampletime));
+               printf("      tx     %s         %5" PRIu64 " packets/s\n\n", gettrafficrate(tx, sampletime, 15), (uint64_t)(txp / sampletime));
        } else {
                printf("{\"jsonversion\":\"%d\",", JSONVERSION_TR);
                printf("\"vnstatversion\":\"%s\",", getversion());
@@ -82,17 +82,17 @@ void trafficmeter(char iface[], unsigned int sampletime)
                printf("\"sampletime\":%u,", sampletime);
                printf("\"rx\":{");
                printf("\"ratestring\":\"%s\",", gettrafficrate(rx, sampletime, 0));
-               printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(rx/sampletime));
-               printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(rxp/sampletime));
-               printf("\"bytes\":%"PRIu64",", rx);
-               printf("\"packets\":%"PRIu64"", rxp);
+               printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / sampletime));
+               printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / sampletime));
+               printf("\"bytes\":%" PRIu64 ",", rx);
+               printf("\"packets\":%" PRIu64 "", rxp);
                printf("},");
                printf("\"tx\":{");
                printf("\"ratestring\":\"%s\",", gettrafficrate(tx, sampletime, 0));
-               printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(tx/sampletime));
-               printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(txp/sampletime));
-               printf("\"bytes\":%"PRIu64",", tx);
-               printf("\"packets\":%"PRIu64"", txp);
+               printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / sampletime));
+               printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / sampletime));
+               printf("\"bytes\":%" PRIu64 ",", tx);
+               printf("\"packets\":%" PRIu64 "", txp);
                printf("}}\n");
        }
 }
@@ -130,9 +130,9 @@ void livetrafficmeter(char iface[32], int mode)
        }
 
        /* set some defaults */
-       rxtotal=txtotal=rxptotal=txptotal=rxpmax=txpmax=0;
-       rxpmin=txpmin=rxmin=txmin=MAX64;
-       rxmax=txmax=0;
+       rxtotal = txtotal = rxptotal = txptotal = rxpmax = txpmax = 0;
+       rxpmin = txpmin = rxmin = txmin = MAX64;
+       rxmax = txmax = 0;
        timeslept = 0;
 
        timespent = (uint64_t)time(NULL);
@@ -164,7 +164,7 @@ void livetrafficmeter(char iface[32], int mode)
        }
 
        /* loop until user gets bored */
-       while (intsignal==0) {
+       while (intsignal == 0) {
 
                timeslept = (uint64_t)time(NULL);
 
@@ -204,21 +204,37 @@ void livetrafficmeter(char iface[32], int mode)
                txptotal += txp;
 
                /* update min & max */
-               if (rxmin>rx) { rxmin = rx;     }
-               if (txmin>tx) { txmin = tx;     }
-               if (rxmax<rx) { rxmax = rx;     }
-               if (txmax<tx) { txmax = tx;     }
-               if (rxpmin>rxp) { rxpmin = rxp; }
-               if (txpmin>txp) { txpmin = txp; }
-               if (rxpmax<rxp) { rxpmax = rxp; }
-               if (txpmax<txp) { txpmax = txp; }
+               if (rxmin > rx) {
+                       rxmin = rx;
+               }
+               if (txmin > tx) {
+                       txmin = tx;
+               }
+               if (rxmax < rx) {
+                       rxmax = rx;
+               }
+               if (txmax < tx) {
+                       txmax = tx;
+               }
+               if (rxpmin > rxp) {
+                       rxpmin = rxp;
+               }
+               if (txpmin > txp) {
+                       txpmin = txp;
+               }
+               if (rxpmax < rxp) {
+                       rxpmax = rxp;
+               }
+               if (txpmax < txp) {
+                       txpmax = txp;
+               }
 
                /* show the difference in a readable format or json */
                if (!json) {
                        if (mode == 0) {
                                /* packets per second visible */
-                               snprintf(buffer, 128, "   rx: %s %*"PRIu64" p/s", gettrafficrate(rx, LIVETIME, ratewidth), ppswidth, (uint64_t)rxp/LIVETIME);
-                               snprintf(buffer2, 128, " %*s tx: %s %*"PRIu64" p/s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), ppswidth, (uint64_t)txp/LIVETIME);
+                               snprintf(buffer, 128, "   rx: %s %*" PRIu64 " p/s", gettrafficrate(rx, LIVETIME, ratewidth), ppswidth, (uint64_t)rxp / LIVETIME);
+                               snprintf(buffer2, 128, " %*s tx: %s %*" PRIu64 " p/s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), ppswidth, (uint64_t)txp / LIVETIME);
                        } else {
                                /* total transfer amount visible */
                                snprintf(buffer, 128, "   rx: %s   %s", gettrafficrate(rx, LIVETIME, ratewidth), getvalue(rxtotal, 1, RT_Normal));
@@ -226,36 +242,36 @@ void livetrafficmeter(char iface[32], int mode)
                        }
                        strcat(buffer, buffer2);
 
-                       if (cfg.ostyle!=4 || !debug) {
+                       if (cfg.ostyle != 4 || !debug) {
                                cursortocolumn(1);
                                eraseline();
                        }
-                       if (cfg.ostyle!=4) {
+                       if (cfg.ostyle != 4) {
                                printf("%s", buffer);
                                fflush(stdout);
                        } else {
                                printf("%s\n", buffer);
                        }
                } else {
-                       printf("{\"index\":%"PRIu64",", index);
-                       printf("\"seconds\":%"PRIu64",", (uint64_t)time(NULL) - timespent);
+                       printf("{\"index\":%" PRIu64 ",", index);
+                       printf("\"seconds\":%" PRIu64 ",", (uint64_t)time(NULL) - timespent);
                        printf("\"rx\":{");
                        printf("\"ratestring\":\"%s\",", gettrafficrate(rx, LIVETIME, 0));
-                       printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(rx/LIVETIME));
-                       printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(rxp/LIVETIME));
-                       printf("\"bytes\":%"PRIu64",", rx);
-                       printf("\"packets\":%"PRIu64",", rxp);
-                       printf("\"totalbytes\":%"PRIu64",", rxtotal);
-                       printf("\"totalpackets\":%"PRIu64"", rxptotal);
+                       printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / LIVETIME));
+                       printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / LIVETIME));
+                       printf("\"bytes\":%" PRIu64 ",", rx);
+                       printf("\"packets\":%" PRIu64 ",", rxp);
+                       printf("\"totalbytes\":%" PRIu64 ",", rxtotal);
+                       printf("\"totalpackets\":%" PRIu64 "", rxptotal);
                        printf("},");
                        printf("\"tx\":{");
                        printf("\"ratestring\":\"%s\",", gettrafficrate(tx, LIVETIME, 0));
-                       printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(tx/LIVETIME));
-                       printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(txp/LIVETIME));
-                       printf("\"bytes\":%"PRIu64",", tx);
-                       printf("\"packets\":%"PRIu64",", txp);
-                       printf("\"totalbytes\":%"PRIu64",", txtotal);
-                       printf("\"totalpackets\":%"PRIu64"", txptotal);
+                       printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / LIVETIME));
+                       printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / LIVETIME));
+                       printf("\"bytes\":%" PRIu64 ",", tx);
+                       printf("\"packets\":%" PRIu64 ",", txp);
+                       printf("\"totalbytes\":%" PRIu64 ",", txtotal);
+                       printf("\"totalpackets\":%" PRIu64 "", txptotal);
                        printf("}}\n");
                        index++;
                }
@@ -269,7 +285,7 @@ void livetrafficmeter(char iface[32], int mode)
        }
 
        /* print some statistics if enough time did pass */
-       if (!json && timespent>=10) {
+       if (!json && timespent >= 10) {
 
                printf("\n %s  /  traffic statistics\n\n", iface);
 
@@ -286,43 +302,43 @@ void livetrafficmeter(char iface[32], int mode)
                printf("          min        %s", gettrafficrate(rxmin, LIVETIME, 15));
                printf("  | %s\n", gettrafficrate(txmin, LIVETIME, 15));
                printf("--------------------------------------+------------------\n");
-               printf("  packets               %12"PRIu64"  |    %12"PRIu64"\n", rxptotal, txptotal);
+               printf("  packets               %12" PRIu64 "  |    %12" PRIu64 "\n", rxptotal, txptotal);
                printf("--------------------------------------+------------------\n");
-               printf("          max          %9"PRIu64" p/s  |   %9"PRIu64" p/s\n", rxpmax/LIVETIME, txpmax/LIVETIME);
-               printf("      average          %9"PRIu64" p/s  |   %9"PRIu64" p/s\n", rxptotal/timespent, txptotal/timespent);
-               printf("          min          %9"PRIu64" p/s  |   %9"PRIu64" p/s\n", rxpmin/LIVETIME, txpmin/LIVETIME);
+               printf("          max          %9" PRIu64 " p/s  |   %9" PRIu64 " p/s\n", rxpmax / LIVETIME, txpmax / LIVETIME);
+               printf("      average          %9" PRIu64 " p/s  |   %9" PRIu64 " p/s\n", rxptotal / timespent, txptotal / timespent);
+               printf("          min          %9" PRIu64 " p/s  |   %9" PRIu64 " p/s\n", rxpmin / LIVETIME, txpmin / LIVETIME);
                printf("--------------------------------------+------------------\n");
 
-               if (timespent<=60) {
-                       printf("  time             %9"PRIu64" seconds\n", timespent);
+               if (timespent <= 60) {
+                       printf("  time             %9" PRIu64 " seconds\n", timespent);
                } else {
-                       printf("  time               %7.2f minutes\n", timespent/(double)60);
+                       printf("  time               %7.2f minutes\n", timespent / (double)60);
                }
 
                printf("\n");
        } else if (json) {
-                       printf("{\"seconds\":%"PRIu64",", timespent);
-                       printf("\"rx\":{");
-                       printf("\"maxratestring\":\"%s\",", gettrafficrate(rxmax, LIVETIME, 0));
-                       printf("\"averageratestring\":\"%s\",", gettrafficrate(rxtotal, (time_t)timespent, 0));
-                       printf("\"minratestring\":\"%s\",", gettrafficrate(rxmin, LIVETIME, 0));
-                       printf("\"totalbytes\":%"PRIu64",", rxtotal);
-                       printf("\"maxbytes\":%"PRIu64",", rxmax);
-                       printf("\"minbytes\":%"PRIu64",", rxmin);
-                       printf("\"totalpackets\":%"PRIu64",", rxptotal);
-                       printf("\"maxpackets\":%"PRIu64",", rxpmax);
-                       printf("\"minpackets\":%"PRIu64"", rxpmin);
-                       printf("},");
-                       printf("\"tx\":{");
-                       printf("\"maxratestring\":\"%s\",", gettrafficrate(txmax, LIVETIME, 0));
-                       printf("\"averageratestring\":\"%s\",", gettrafficrate(txtotal, (time_t)timespent, 0));
-                       printf("\"minratestring\":\"%s\",", gettrafficrate(txmin, LIVETIME, 0));
-                       printf("\"totalbytes\":%"PRIu64",", txtotal);
-                       printf("\"maxbytes\":%"PRIu64",", txmax);
-                       printf("\"minbytes\":%"PRIu64",", txmin);
-                       printf("\"totalpackets\":%"PRIu64",", txptotal);
-                       printf("\"maxpackets\":%"PRIu64",", txpmax);
-                       printf("\"minpackets\":%"PRIu64"", txpmin);
-                       printf("}}\n");
+               printf("{\"seconds\":%" PRIu64 ",", timespent);
+               printf("\"rx\":{");
+               printf("\"maxratestring\":\"%s\",", gettrafficrate(rxmax, LIVETIME, 0));
+               printf("\"averageratestring\":\"%s\",", gettrafficrate(rxtotal, (time_t)timespent, 0));
+               printf("\"minratestring\":\"%s\",", gettrafficrate(rxmin, LIVETIME, 0));
+               printf("\"totalbytes\":%" PRIu64 ",", rxtotal);
+               printf("\"maxbytes\":%" PRIu64 ",", rxmax);
+               printf("\"minbytes\":%" PRIu64 ",", rxmin);
+               printf("\"totalpackets\":%" PRIu64 ",", rxptotal);
+               printf("\"maxpackets\":%" PRIu64 ",", rxpmax);
+               printf("\"minpackets\":%" PRIu64 "", rxpmin);
+               printf("},");
+               printf("\"tx\":{");
+               printf("\"maxratestring\":\"%s\",", gettrafficrate(txmax, LIVETIME, 0));
+               printf("\"averageratestring\":\"%s\",", gettrafficrate(txtotal, (time_t)timespent, 0));
+               printf("\"minratestring\":\"%s\",", gettrafficrate(txmin, LIVETIME, 0));
+               printf("\"totalbytes\":%" PRIu64 ",", txtotal);
+               printf("\"maxbytes\":%" PRIu64 ",", txmax);
+               printf("\"minbytes\":%" PRIu64 ",", txmin);
+               printf("\"totalpackets\":%" PRIu64 ",", txptotal);
+               printf("\"maxpackets\":%" PRIu64 ",", txpmax);
+               printf("\"minpackets\":%" PRIu64 "", txpmin);
+               printf("}}\n");
        }
 }
index 78e80ab065ba34fa35bc33825ca18594be02799a..8503eaa8791289e354a4b12d92abb30076f9fdf3 100644 (file)
@@ -29,7 +29,8 @@ vnStat - Copyright (c) 2002-2019 Teemu Toivola <tst@iki.fi>
 #include "fs.h"
 #include "vnstat.h"
 
-int main(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
 
        int currentarg;
        DIR *dir = NULL;
@@ -40,13 +41,13 @@ int main(int argc, char *argv[]) {
 
        /* early check for debug and config parameter */
        if (argc > 1) {
-               for (currentarg=1; currentarg<argc; currentarg++) {
-                       if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+               for (currentarg = 1; currentarg < argc; currentarg++) {
+                       if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
                                debug = 1;
                                printf("Debug enabled, vnstat %s\n", VERSION);
-                       } else if (strcmp(argv[currentarg],"--config")==0) {
-                               if (currentarg+1<argc) {
-                                       strncpy_nt(p.cfgfile, argv[currentarg+1], 512);
+                       } else if (strcmp(argv[currentarg], "--config") == 0) {
+                               if (currentarg + 1 < argc) {
+                                       strncpy_nt(p.cfgfile, argv[currentarg + 1], 512);
                                        if (debug)
                                                printf("Used config file: %s\n", p.cfgfile);
                                        currentarg++;
@@ -76,22 +77,22 @@ int main(int argc, char *argv[]) {
        strncpy_nt(p.dirname, cfg.dbdir, 512);
 
        /* parse parameters, maybe not the best way but... */
-       for (currentarg=1; currentarg<argc; currentarg++) {
+       for (currentarg = 1; currentarg < argc; currentarg++) {
                if (debug)
-                       printf("arg %d: \"%s\"\n",currentarg,argv[currentarg]);
-               if (strcmp(argv[currentarg],"--longhelp")==0) {
+                       printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
+               if (strcmp(argv[currentarg], "--longhelp") == 0) {
                        showlonghelp(&p);
                        return 0;
-               } else if ((strcmp(argv[currentarg],"-?")==0) || (strcmp(argv[currentarg],"--help")==0)) {
+               } else if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) {
                        showhelp(&p);
                        return 0;
-               } else if ((strcmp(argv[currentarg],"-i")==0) || (strcmp(argv[currentarg],"--iface")==0)) {
-                       if (currentarg+1<argc) {
-                               if (strlen(argv[currentarg+1]) > 31) {
+               } else if ((strcmp(argv[currentarg], "-i") == 0) || (strcmp(argv[currentarg], "--iface") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               if (strlen(argv[currentarg + 1]) > 31) {
                                        printf("Error: Interface name is limited to 31 characters.\n");
                                        return 1;
                                }
-                               strncpy_nt(p.interface, argv[currentarg+1], 32);
+                               strncpy_nt(p.interface, argv[currentarg + 1], 32);
                                p.defaultiface = 0;
                                if (debug)
                                        printf("Used interface: %s\n", p.interface);
@@ -101,13 +102,13 @@ int main(int argc, char *argv[]) {
                                printf("Error: Interface for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if (strcmp(argv[currentarg],"--config")==0) {
+               } else if (strcmp(argv[currentarg], "--config") == 0) {
                        /* config has already been parsed earlier so nothing to do here */
                        currentarg++;
                        continue;
-               } else if (strcmp(argv[currentarg],"--setalias")==0 || strcmp(argv[currentarg],"--nick")==0) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(p.alias, argv[currentarg+1], 32);
+               } else if (strcmp(argv[currentarg], "--setalias") == 0 || strcmp(argv[currentarg], "--nick") == 0) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(p.alias, argv[currentarg + 1], 32);
                                if (debug)
                                        printf("Used alias: %s\n", p.alias);
                                p.setalias = 1;
@@ -117,8 +118,8 @@ int main(int argc, char *argv[]) {
                                printf("Error: Alias for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"--style"))==0) {
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+               } else if ((strcmp(argv[currentarg], "--style")) == 0) {
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
                                if (cfg.ostyle > 4 || cfg.ostyle < 0) {
                                        printf("Error: Invalid style parameter \"%d\" for --style.\n", cfg.ostyle);
                                        printf(" Valid parameters:\n");
@@ -130,7 +131,7 @@ int main(int argc, char *argv[]) {
                                        printf("        and show raw values in --oneline\n");
                                        return 1;
                                }
-                               cfg.ostyle = atoi(argv[currentarg+1]);
+                               cfg.ostyle = atoi(argv[currentarg + 1]);
                                if (debug)
                                        printf("Style changed: %d\n", cfg.ostyle);
                                currentarg++;
@@ -146,9 +147,9 @@ int main(int argc, char *argv[]) {
                                printf("        and show raw values in --oneline\n");
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"--dbdir"))==0) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(p.dirname, argv[currentarg+1], 512);
+               } else if ((strcmp(argv[currentarg], "--dbdir")) == 0) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(p.dirname, argv[currentarg + 1], 512);
                                if (debug)
                                        printf("DatabaseDir: \"%s\"\n", p.dirname);
                                currentarg++;
@@ -157,110 +158,110 @@ int main(int argc, char *argv[]) {
                                printf("Error: Directory for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"--locale"))==0) {
-                       if (currentarg+1<argc) {
-                               setlocale(LC_ALL, argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "--locale")) == 0) {
+                       if (currentarg + 1 < argc) {
+                               setlocale(LC_ALL, argv[currentarg + 1]);
                                if (debug)
-                                       printf("Locale: \"%s\"\n", argv[currentarg+1]);
+                                       printf("Locale: \"%s\"\n", argv[currentarg + 1]);
                                currentarg++;
                                continue;
                        } else {
                                printf("Error: Locale for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if (strcmp(argv[currentarg],"--add")==0) {
-                       p.addiface=1;
-                       p.query=0;
-               } else if ((strcmp(argv[currentarg],"-u")==0) || (strcmp(argv[currentarg],"--update")==0)) {
+               } else if (strcmp(argv[currentarg], "--add") == 0) {
+                       p.addiface = 1;
+                       p.query = 0;
+               } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--update") == 0)) {
                        printf("Error: The \"%s\" parameter is not supported in this version.\n", argv[currentarg]);
                        return 1;
-               } else if ((strcmp(argv[currentarg],"-q")==0) || (strcmp(argv[currentarg],"--query")==0)) {
-                       p.query=1;
-               } else if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
-                       debug=1;
-               } else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--days")==0)) {
-                       cfg.qmode=1;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listdays = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-q") == 0) || (strcmp(argv[currentarg], "--query") == 0)) {
+                       p.query = 1;
+               } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
+                       debug = 1;
+               } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--days") == 0)) {
+                       cfg.qmode = 1;
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listdays = atoi(argv[currentarg + 1]);
                                if (cfg.listdays < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-m")==0) || (strcmp(argv[currentarg],"--months")==0)) {
-                       cfg.qmode=2;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listmonths = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-m") == 0) || (strcmp(argv[currentarg], "--months") == 0)) {
+                       cfg.qmode = 2;
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listmonths = atoi(argv[currentarg + 1]);
                                if (cfg.listmonths < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-t")==0) || (strcmp(argv[currentarg],"--top")==0)) {
-                       cfg.qmode=3;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listtop = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-t") == 0) || (strcmp(argv[currentarg], "--top") == 0)) {
+                       cfg.qmode = 3;
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listtop = atoi(argv[currentarg + 1]);
                                if (cfg.listtop < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-s")==0) || (strcmp(argv[currentarg],"--short")==0)) {
-                       cfg.qmode=5;
-               } else if ((strcmp(argv[currentarg],"-y")==0) || (strcmp(argv[currentarg],"--years")==0)) {
-                       cfg.qmode=6;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listyears = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--short") == 0)) {
+                       cfg.qmode = 5;
+               } else if ((strcmp(argv[currentarg], "-y") == 0) || (strcmp(argv[currentarg], "--years") == 0)) {
+                       cfg.qmode = 6;
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listyears = atoi(argv[currentarg + 1]);
                                if (cfg.listyears < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-hg")==0) || (strcmp(argv[currentarg],"--hoursgraph")==0)) {
-                       cfg.qmode=7;
-               } else if ((strcmp(argv[currentarg],"-h")==0) || (strcmp(argv[currentarg],"--hours")==0)) {
-                       cfg.qmode=11;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listhours = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv[currentarg], "--hoursgraph") == 0)) {
+                       cfg.qmode = 7;
+               } else if ((strcmp(argv[currentarg], "-h") == 0) || (strcmp(argv[currentarg], "--hours") == 0)) {
+                       cfg.qmode = 11;
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listhours = atoi(argv[currentarg + 1]);
                                if (cfg.listhours < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-5")==0) || (strcmp(argv[currentarg],"--fiveminutes")==0)) {
-                       cfg.qmode=12;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listfivemins = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-5") == 0) || (strcmp(argv[currentarg], "--fiveminutes") == 0)) {
+                       cfg.qmode = 12;
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listfivemins = atoi(argv[currentarg + 1]);
                                if (cfg.listfivemins < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if (strcmp(argv[currentarg],"--oneline")==0) {
-                       cfg.qmode=9;
-                       if (currentarg+1<argc && argv[currentarg+1][0]!='-') {
-                               if (argv[currentarg+1][0]=='b') {
+               } else if (strcmp(argv[currentarg], "--oneline") == 0) {
+                       cfg.qmode = 9;
+                       if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-') {
+                               if (argv[currentarg + 1][0] == 'b') {
                                        cfg.ostyle = 4;
                                        currentarg++;
                                } else {
-                                       printf("Error: Invalid mode parameter \"%s\" for --oneline.\n", argv[currentarg+1]);
+                                       printf("Error: Invalid mode parameter \"%s\" for --oneline.\n", argv[currentarg + 1]);
                                        printf(" Valid parameters:\n");
                                        printf("    (none) - automatically scaled units visible\n");
                                        printf("    b      - all values in bytes\n");
                                        return 1;
                                }
                        }
-               } else if (strcmp(argv[currentarg],"--xml")==0) {
-                       if (currentarg+1<argc && argv[currentarg+1][0]!='-' && !isdigit(argv[currentarg+1][0])) {
-                               p.xmlmode = argv[currentarg+1][0];
-                               if (strlen(argv[currentarg+1])!=1 || strchr("afhdmyt", p.xmlmode)==NULL) {
-                                       printf("Error: Invalid mode parameter \"%s\" for --xml.\n", argv[currentarg+1]);
+               } else if (strcmp(argv[currentarg], "--xml") == 0) {
+                       if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-' && !isdigit(argv[currentarg + 1][0])) {
+                               p.xmlmode = argv[currentarg + 1][0];
+                               if (strlen(argv[currentarg + 1]) != 1 || strchr("afhdmyt", p.xmlmode) == NULL) {
+                                       printf("Error: Invalid mode parameter \"%s\" for --xml.\n", argv[currentarg + 1]);
                                        printf(" Valid parameters:\n");
                                        printf("    a - all (default)\n");
                                        printf("    f - only 5 minutes\n");
@@ -273,20 +274,20 @@ int main(int argc, char *argv[]) {
                                }
                                currentarg++;
                        }
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listjsonxml = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listjsonxml = atoi(argv[currentarg + 1]);
                                if (cfg.listjsonxml < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-                       cfg.qmode=8;
-               } else if (strcmp(argv[currentarg],"--json")==0) {
-                       if (currentarg+1<argc && argv[currentarg+1][0]!='-' && !isdigit(argv[currentarg+1][0])) {
-                               p.jsonmode = argv[currentarg+1][0];
-                               if (strlen(argv[currentarg+1])!=1 || strchr("afhdmyt", p.jsonmode)==NULL) {
-                                       printf("Error: Invalid mode parameter \"%s\" for --json.\n", argv[currentarg+1]);
+                       cfg.qmode = 8;
+               } else if (strcmp(argv[currentarg], "--json") == 0) {
+                       if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-' && !isdigit(argv[currentarg + 1][0])) {
+                               p.jsonmode = argv[currentarg + 1][0];
+                               if (strlen(argv[currentarg + 1]) != 1 || strchr("afhdmyt", p.jsonmode) == NULL) {
+                                       printf("Error: Invalid mode parameter \"%s\" for --json.\n", argv[currentarg + 1]);
                                        printf(" Valid parameters:\n");
                                        printf("    a - all (default)\n");
                                        printf("    f - only 5 minutes\n");
@@ -299,17 +300,17 @@ int main(int argc, char *argv[]) {
                                }
                                currentarg++;
                        }
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listjsonxml = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listjsonxml = atoi(argv[currentarg + 1]);
                                if (cfg.listjsonxml < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-                       cfg.qmode=10;
-               } else if ((strcmp(argv[currentarg],"-ru")==0) || (strcmp(argv[currentarg],"--rateunit"))==0) {
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+                       cfg.qmode = 10;
+               } else if ((strcmp(argv[currentarg], "-ru") == 0) || (strcmp(argv[currentarg], "--rateunit")) == 0) {
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
                                if (cfg.rateunit > 1 || cfg.rateunit < 0) {
                                        printf("Error: Invalid parameter \"%d\" for --rateunit.\n", cfg.rateunit);
                                        printf(" Valid parameters:\n");
@@ -317,7 +318,7 @@ int main(int argc, char *argv[]) {
                                        printf("    1 - bits\n");
                                        return 1;
                                }
-                               cfg.rateunit = atoi(argv[currentarg+1]);
+                               cfg.rateunit = atoi(argv[currentarg + 1]);
                                if (debug)
                                        printf("Rateunit changed: %d\n", cfg.rateunit);
                                currentarg++;
@@ -327,80 +328,79 @@ int main(int argc, char *argv[]) {
                                if (debug)
                                        printf("Rateunit changed: %d\n", cfg.rateunit);
                        }
-               } else if ((strcmp(argv[currentarg],"-tr")==0) || (strcmp(argv[currentarg],"--traffic")==0)) {
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.sampletime=atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-tr") == 0) || (strcmp(argv[currentarg], "--traffic") == 0)) {
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.sampletime = atoi(argv[currentarg + 1]);
                                currentarg++;
-                               p.traffic=1;
-                               p.query=0;
+                               p.traffic = 1;
+                               p.query = 0;
                                continue;
                        }
-                       p.traffic=1;
-                       p.query=0;
-               } else if ((strcmp(argv[currentarg],"-l")==0) || (strcmp(argv[currentarg],"--live")==0)) {
-                       if (currentarg+1<argc && argv[currentarg+1][0]!='-') {
-                               if (!isdigit(argv[currentarg+1][0]) || p.livemode > 1 || p.livemode < 0) {
-                                       printf("Error: Invalid mode parameter \"%s\" for -l / --live.\n", argv[currentarg+1]);
+                       p.traffic = 1;
+                       p.query = 0;
+               } else if ((strcmp(argv[currentarg], "-l") == 0) || (strcmp(argv[currentarg], "--live") == 0)) {
+                       if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-') {
+                               if (!isdigit(argv[currentarg + 1][0]) || p.livemode > 1 || p.livemode < 0) {
+                                       printf("Error: Invalid mode parameter \"%s\" for -l / --live.\n", argv[currentarg + 1]);
                                        printf(" Valid parameters:\n");
                                        printf("    0 - show packets per second (default)\n");
                                        printf("    1 - show transfer counters\n");
                                        return 1;
                                }
-                               p.livemode = atoi(argv[currentarg+1]);
+                               p.livemode = atoi(argv[currentarg + 1]);
                                currentarg++;
                        }
-                       p.livetraffic=1;
-                       p.query=0;
-               } else if (strcmp(argv[currentarg],"--force")==0) {
-                       p.force=1;
-               } else if (strcmp(argv[currentarg],"--showconfig")==0) {
+                       p.livetraffic = 1;
+                       p.query = 0;
+               } else if (strcmp(argv[currentarg], "--force") == 0) {
+                       p.force = 1;
+               } else if (strcmp(argv[currentarg], "--showconfig") == 0) {
                        printcfgfile();
                        return 0;
-               } else if (strcmp(argv[currentarg],"--remove")==0) {
-                       p.removeiface=1;
-                       p.query=0;
-               } else if ((strcmp(argv[currentarg],"-b")==0) || (strcmp(argv[currentarg],"--begin")==0)) {
-                       if (currentarg+1<argc) {
-                               if (!validatedatetime(argv[currentarg+1])) {
+               } else if (strcmp(argv[currentarg], "--remove") == 0) {
+                       p.removeiface = 1;
+                       p.query = 0;
+               } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[currentarg], "--begin") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               if (!validatedatetime(argv[currentarg + 1])) {
                                        printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
                                        return 1;
                                }
-                               strncpy_nt(p.databegin, argv[currentarg+1], 18);
+                               strncpy_nt(p.databegin, argv[currentarg + 1], 18);
                                currentarg++;
                        } else {
                                printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"-e")==0) || (strcmp(argv[currentarg],"--end")==0)) {
-                       if (currentarg+1<argc) {
-                               if (!validatedatetime(argv[currentarg+1])) {
+               } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[currentarg], "--end") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               if (!validatedatetime(argv[currentarg + 1])) {
                                        printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
                                        return 1;
                                }
-                               strncpy_nt(p.dataend, argv[currentarg+1], 18);
+                               strncpy_nt(p.dataend, argv[currentarg + 1], 18);
                                currentarg++;
                        } else {
                                printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if (strcmp(argv[currentarg],"--iflist")==0) {
+               } else if (strcmp(argv[currentarg], "--iflist") == 0) {
                        getiflist(&p.ifacelist, 1);
                        printf("Available interfaces: %s\n", p.ifacelist);
                        free(p.ifacelist);
                        return 0;
-               } else if ((strcmp(argv[currentarg],"-v")==0) || (strcmp(argv[currentarg],"--version")==0)) {
+               } else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[currentarg], "--version") == 0)) {
                        printf("vnStat %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
                        return 0;
                } else {
-                       printf("Unknown parameter \"%s\". Use --help for help.\n",argv[currentarg]);
+                       printf("Unknown parameter \"%s\". Use --help for help.\n", argv[currentarg]);
                        return 1;
                }
-
        }
 
        /* open database and see if it contains any interfaces */
        if (!p.traffic && !p.livetraffic) {
-               if ((dir=opendir(p.dirname))!=NULL) {
+               if ((dir = opendir(p.dirname)) != NULL) {
                        if (debug)
                                printf("Dir OK\n");
                        closedir(dir);
@@ -415,14 +415,14 @@ int main(int argc, char *argv[]) {
                        }
                        p.ifcount = db_getinterfacecount();
                        if (debug)
-                               printf("%"PRIu64" interface(s) found\n", p.ifcount);
+                               printf("%" PRIu64 " interface(s) found\n", p.ifcount);
 
                        if (p.ifcount > 1) {
                                strncpy_nt(p.definterface, cfg.iface, 32);
                        }
                } else {
                        printf("Error: Unable to open database directory \"%s\": %s\n", p.dirname, strerror(errno));
-                       if (errno==ENOENT) {
+                       if (errno == ENOENT) {
                                printf("The vnStat daemon should have created this directory when started.\n");
                                printf("Check that it is configured and running. See also \"man vnstatd\".\n");
                        } else {
@@ -448,7 +448,7 @@ int main(int argc, char *argv[]) {
                        }
                }
        }
-       p.interface[31]='\0';
+       p.interface[31] = '\0';
 
        /* parameter handlers */
        handleremoveinterface(&p);
@@ -487,8 +487,8 @@ int main(int argc, char *argv[]) {
 
 void initparams(PARAMS *p)
 {
-       noexit = 0; /* allow functions to exit in case of error */
-       debug = 0; /* debug disabled by default */
+       noexit = 0;                /* allow functions to exit in case of error */
+       debug = 0;                 /* debug disabled by default */
        disableprints = 0; /* let prints be visible */
 
        p->addiface = 0;
@@ -709,20 +709,20 @@ void handleshowdatabases(PARAMS *p)
        }
 
        /* show all interfaces if -i isn't specified */
-       if (p->ifcount==0) {
+       if (p->ifcount == 0) {
                /* printf("No database found.\n"); */
-               p->query=0;
-       } else if ((cfg.qmode==0 || cfg.qmode==8 || cfg.qmode==10) && (p->ifcount>1)) {
+               p->query = 0;
+       } else if ((cfg.qmode == 0 || cfg.qmode == 8 || cfg.qmode == 10) && (p->ifcount > 1)) {
 
-               if (cfg.qmode==0) {
-                       if (cfg.ostyle!=0) {
+               if (cfg.qmode == 0) {
+                       if (cfg.ostyle != 0) {
                                printf("\n                      rx      /      tx      /     total    /   estimated\n");
                        } else {
                                printf("\n                      rx      /      tx      /     total\n");
                        }
-               } else if (cfg.qmode==8) {
+               } else if (cfg.qmode == 8) {
                        xmlheader();
-               } else if (cfg.qmode==10) {
+               } else if (cfg.qmode == 10) {
                        jsonheader();
                }
 
@@ -736,11 +736,11 @@ void handleshowdatabases(PARAMS *p)
                        strncpy_nt(p->interface, dbifl_i->interface, 32);
                        if (debug)
                                printf("\nProcessing interface \"%s\"...\n", p->interface);
-                       if (cfg.qmode==0) {
+                       if (cfg.qmode == 0) {
                                showdb(p->interface, 5, "", "");
-                       } else if (cfg.qmode==8) {
+                       } else if (cfg.qmode == 8) {
                                showxml(p->interface, p->xmlmode, p->databegin, p->dataend);
-                       } else if (cfg.qmode==10) {
+                       } else if (cfg.qmode == 10) {
                                showjson(p->interface, ifcount, p->jsonmode, p->databegin, p->dataend);
                        }
                        ifcount++;
@@ -748,13 +748,13 @@ void handleshowdatabases(PARAMS *p)
                }
                dbiflistfree(&dbifl);
 
-               if (cfg.qmode==8) {
+               if (cfg.qmode == 8) {
                        xmlfooter();
-               } else if (cfg.qmode==10) {
+               } else if (cfg.qmode == 10) {
                        jsonfooter();
                }
 
-       /* show in qmode if there's only one file or qmode!=0 */
+               /* show in qmode if there's only one file or qmode!=0 */
        } else {
                showoneinterface(p, p->interface);
        }
@@ -763,7 +763,7 @@ void handleshowdatabases(PARAMS *p)
 void showoneinterface(PARAMS *p, const char *interface)
 {
        if (!db_getinterfacecountbyname(p->interface)) {
-               if (strchr(p->interface, '+') == NULL)  {
+               if (strchr(p->interface, '+') == NULL) {
                        printf("Error: Interface \"%s\" not found in database.\n", p->interface);
                } else {
                        printf("Error: Not all requested interfaces found in database or given interfaces aren't unique.\n");
@@ -771,20 +771,20 @@ void showoneinterface(PARAMS *p, const char *interface)
                exit(EXIT_FAILURE);
        }
 
-       if (cfg.qmode==5) {
-               if (cfg.ostyle!=0) {
+       if (cfg.qmode == 5) {
+               if (cfg.ostyle != 0) {
                        printf("\n                      rx      /      tx      /     total    /   estimated\n");
                } else {
                        printf("\n                      rx      /      tx      /     total\n");
                }
        }
-       if (cfg.qmode!=8 && cfg.qmode!=10) {
+       if (cfg.qmode != 8 && cfg.qmode != 10) {
                showdb(interface, cfg.qmode, p->databegin, p->dataend);
-       } else if (cfg.qmode==8) {
+       } else if (cfg.qmode == 8) {
                xmlheader();
                showxml(p->interface, p->xmlmode, p->databegin, p->dataend);
                xmlfooter();
-       } else if (cfg.qmode==10) {
+       } else if (cfg.qmode == 10) {
                jsonheader();
                showjson(p->interface, 0, p->jsonmode, p->databegin, p->dataend);
                jsonfooter();
index 9f03701fb8f7e51b40c7f36e64ed8241024244a9..f23fd736f066ea35c2dba2bbc70ae6e5cbde3617 100644 (file)
@@ -35,13 +35,13 @@ int main(int argc, char *argv[])
 
        /* early check for debug and config parameter */
        if (argc > 1) {
-               for (currentarg=1; currentarg<argc; currentarg++) {
-                       if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+               for (currentarg = 1; currentarg < argc; currentarg++) {
+                       if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
                                debug = 1;
                                printf("Debug enabled, vnstatd %s\n", VERSION);
-                       } else if (strcmp(argv[currentarg],"--config")==0) {
-                               if (currentarg+1<argc) {
-                                       strncpy_nt(s.cfgfile, argv[currentarg+1], 512);
+                       } else if (strcmp(argv[currentarg], "--config") == 0) {
+                               if (currentarg + 1 < argc) {
+                                       strncpy_nt(s.cfgfile, argv[currentarg + 1], 512);
                                        if (debug)
                                                printf("Used config file: %s\n", s.cfgfile);
                                        currentarg++;
@@ -67,30 +67,30 @@ int main(int argc, char *argv[])
        strncpy_nt(s.user, cfg.daemonuser, 33);
        strncpy_nt(s.group, cfg.daemongroup, 33);
        s.updateinterval = cfg.updateinterval;
-       s.saveinterval = cfg.saveinterval*60;
+       s.saveinterval = cfg.saveinterval * 60;
 
        /* parse parameters, maybe not the best way but... */
-       for (currentarg=1; currentarg<argc; currentarg++) {
+       for (currentarg = 1; currentarg < argc; currentarg++) {
                if (debug)
-                       printf("arg %d: \"%s\"\n",currentarg,argv[currentarg]);
-               if ((strcmp(argv[currentarg],"-?")==0) || (strcmp(argv[currentarg],"--help")==0)) {
+                       printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
+               if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) {
                        break;
-               } else if (strcmp(argv[currentarg],"--config")==0) {
+               } else if (strcmp(argv[currentarg], "--config") == 0) {
                        /* config has already been parsed earlier so nothing to do here */
                        currentarg++;
                        continue;
-               } else if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+               } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
                        debug = 1;
-               } else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--daemon")==0)) {
+               } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--daemon") == 0)) {
                        s.rundaemon = 1;
                        s.showhelp = 0;
-               } else if ((strcmp(argv[currentarg],"-n")==0) || (strcmp(argv[currentarg],"--nodaemon")==0)) {
+               } else if ((strcmp(argv[currentarg], "-n") == 0) || (strcmp(argv[currentarg], "--nodaemon") == 0)) {
                        s.showhelp = 0;
-               } else if ((strcmp(argv[currentarg],"-s")==0) || (strcmp(argv[currentarg],"--sync")==0)) {
+               } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--sync") == 0)) {
                        s.sync = 1;
-               } else if ((strcmp(argv[currentarg],"-u")==0) || (strcmp(argv[currentarg],"--user")==0)) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(s.user, argv[currentarg+1], 33);
+               } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--user") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(s.user, argv[currentarg + 1], 33);
                                if (debug)
                                        printf("Requested user: \"%s\"\n", s.user);
                                currentarg++;
@@ -99,9 +99,9 @@ int main(int argc, char *argv[])
                                printf("Error: User for --user missing.\n");
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"-g")==0) || (strcmp(argv[currentarg],"--group")==0)) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(s.group, argv[currentarg+1], 33);
+               } else if ((strcmp(argv[currentarg], "-g") == 0) || (strcmp(argv[currentarg], "--group") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(s.group, argv[currentarg + 1], 33);
                                if (debug)
                                        printf("Requested group: \"%s\"\n", s.group);
                                currentarg++;
@@ -110,16 +110,16 @@ int main(int argc, char *argv[])
                                printf("Error: Group for --group missing.\n");
                                return 1;
                        }
-               } else if (strcmp(argv[currentarg],"--noadd")==0) {
+               } else if (strcmp(argv[currentarg], "--noadd") == 0) {
                        s.noadd = 1;
-               } else if (strcmp(argv[currentarg],"--alwaysadd")==0) {
+               } else if (strcmp(argv[currentarg], "--alwaysadd") == 0) {
                        s.alwaysadd = 1;
-               } else if ((strcmp(argv[currentarg],"-v")==0) || (strcmp(argv[currentarg],"--version")==0)) {
+               } else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[currentarg], "--version") == 0)) {
                        printf("vnStat daemon %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
                        return 0;
-               } else if ((strcmp(argv[currentarg],"-p")==0) || (strcmp(argv[currentarg],"--pidfile")==0)) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(cfg.pidfile, argv[currentarg+1], 512);
+               } else if ((strcmp(argv[currentarg], "-p") == 0) || (strcmp(argv[currentarg], "--pidfile") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(cfg.pidfile, argv[currentarg + 1], 512);
                                cfg.pidfile[511] = '\0';
                                if (debug)
                                        printf("Used pid file: %s\n", cfg.pidfile);
@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
                                return 1;
                        }
                } else {
-                       printf("Unknown arg \"%s\". Use --help for help.\n",argv[currentarg]);
+                       printf("Unknown arg \"%s\". Use --help for help.\n", argv[currentarg]);
                        return 1;
                }
        }
@@ -193,11 +193,11 @@ int main(int argc, char *argv[])
        s.running = 1;
 
 #if defined(__linux__)
-  #if HAVE_DECL_IFLA_STATS64
+#if HAVE_DECL_IFLA_STATS64
        snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d 64-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
-  #else
+#else
        snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d 32-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
-  #endif
+#endif
 #else
        snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
 #endif
@@ -249,7 +249,7 @@ int main(int argc, char *argv[])
                        if (s.dbifcount == 0) {
                                filldatabaselist(&s);
 
-                       /* update data cache */
+                               /* update data cache */
                        } else {
                                s.prevdbupdate = s.current - (s.current % s.updateinterval);
 
index 6c2a02413b969af21062fe26e09865d2bd074281..4d73352b0d88f8e37bc5494948490dc4179b692d 100644 (file)
@@ -33,13 +33,13 @@ int main(int argc, char *argv[])
 
        /* early check for debug and config parameter */
        if (argc > 1) {
-               for (currentarg=1; currentarg<argc; currentarg++) {
-                       if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+               for (currentarg = 1; currentarg < argc; currentarg++) {
+                       if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
                                debug = 1;
                                printf("Debug enabled, vnstati %s\n", VERSION);
-                       } else if (strcmp(argv[currentarg],"--config")==0) {
-                               if (currentarg+1<argc) {
-                                       strncpy_nt(p.cfgfile, argv[currentarg+1], 512);
+                       } else if (strcmp(argv[currentarg], "--config") == 0) {
+                               if (currentarg + 1 < argc) {
+                                       strncpy_nt(p.cfgfile, argv[currentarg + 1], 512);
                                        if (debug)
                                                printf("Used config file: %s\n", p.cfgfile);
                                        currentarg++;
@@ -63,18 +63,18 @@ int main(int argc, char *argv[])
        ic.current = time(NULL);
 
        /* parse parameters */
-       for (currentarg=1; currentarg<argc; currentarg++) {
+       for (currentarg = 1; currentarg < argc; currentarg++) {
                if (debug)
-                       printf("arg %d: \"%s\"\n",currentarg,argv[currentarg]);
-               if ((strcmp(argv[currentarg],"-?")==0) || (strcmp(argv[currentarg],"--help"))==0) {
+                       printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
+               if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help")) == 0) {
                        p.help = 1;
-               } else if ((strcmp(argv[currentarg],"-i")==0) || (strcmp(argv[currentarg],"--iface"))==0) {
-                       if (currentarg+1<argc) {
-                               if (strlen(argv[currentarg+1]) > 31) {
+               } else if ((strcmp(argv[currentarg], "-i") == 0) || (strcmp(argv[currentarg], "--iface")) == 0) {
+                       if (currentarg + 1 < argc) {
+                               if (strlen(argv[currentarg + 1]) > 31) {
                                        printf("Error: Interface name is limited to 31 characters.\n");
                                        return 1;
                                }
-                               strncpy_nt(p.interface, argv[currentarg+1], 32);
+                               strncpy_nt(p.interface, argv[currentarg + 1], 32);
                                if (debug)
                                        printf("Used interface: \"%s\"\n", p.interface);
                                currentarg++;
@@ -83,9 +83,9 @@ int main(int argc, char *argv[])
                                printf("Error: Interface for -i missing.\n");
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"-o")==0) || (strcmp(argv[currentarg],"--output"))==0) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(p.filename, argv[currentarg+1], 512);
+               } else if ((strcmp(argv[currentarg], "-o") == 0) || (strcmp(argv[currentarg], "--output")) == 0) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(p.filename, argv[currentarg + 1], 512);
                                if (debug)
                                        printf("Output file: \"%s\"\n", p.filename);
                                currentarg++;
@@ -94,9 +94,9 @@ int main(int argc, char *argv[])
                                printf("Error: Filename for -o missing.\n");
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"-c")==0) || (strcmp(argv[currentarg],"--cache"))==0) {
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               p.cache = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-c") == 0) || (strcmp(argv[currentarg], "--cache")) == 0) {
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               p.cache = atoi(argv[currentarg + 1]);
                                if (debug)
                                        printf("Cache time: %d minutes\n", p.cache);
                                currentarg++;
@@ -105,9 +105,9 @@ int main(int argc, char *argv[])
                                printf("Error: Parameter for -c missing or invalid.\n");
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"--style"))==0) {
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.ostyle = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "--style")) == 0) {
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.ostyle = atoi(argv[currentarg + 1]);
                                if (cfg.ostyle > 3 || cfg.ostyle < 0) {
                                        printf("Error: Invalid style parameter \"%d\" for --style.\n", cfg.ostyle);
                                        return 1;
@@ -120,9 +120,9 @@ int main(int argc, char *argv[])
                                printf("Error: Style parameter for --style missing.\n");
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"--transparent"))==0) {
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.transbg = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "--transparent")) == 0) {
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.transbg = atoi(argv[currentarg + 1]);
                                if (cfg.transbg > 1 || cfg.transbg < 0) {
                                        printf("Error: Invalid parameter \"%d\" for --transparent.\n", cfg.transbg);
                                        return 1;
@@ -136,9 +136,9 @@ int main(int argc, char *argv[])
                                if (debug)
                                        printf("Transparency changed: %d\n", cfg.transbg);
                        }
-               } else if ((strcmp(argv[currentarg],"--dbdir"))==0) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(cfg.dbdir, argv[currentarg+1], 512);
+               } else if ((strcmp(argv[currentarg], "--dbdir")) == 0) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(cfg.dbdir, argv[currentarg + 1], 512);
                                if (debug)
                                        printf("DatabaseDir: \"%s\"\n", cfg.dbdir);
                                currentarg++;
@@ -147,24 +147,24 @@ int main(int argc, char *argv[])
                                printf("Error: Directory for --dbdir missing.\n");
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"--locale"))==0) {
-                       if (currentarg+1<argc) {
-                               setlocale(LC_ALL, argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "--locale")) == 0) {
+                       if (currentarg + 1 < argc) {
+                               setlocale(LC_ALL, argv[currentarg + 1]);
                                if (debug)
-                                       printf("Locale: \"%s\"\n", argv[currentarg+1]);
+                                       printf("Locale: \"%s\"\n", argv[currentarg + 1]);
                                currentarg++;
                                continue;
                        } else {
                                printf("Error: Locale for --locale missing.\n");
                                return 1;
                        }
-               } else if (strcmp(argv[currentarg],"--config")==0) {
+               } else if (strcmp(argv[currentarg], "--config") == 0) {
                        /* config has already been parsed earlier so nothing to do here */
                        currentarg++;
                        continue;
-               } else if ((strcmp(argv[currentarg],"--headertext"))==0) {
-                       if (currentarg+1<argc) {
-                               strncpy_nt(ic.headertext, argv[currentarg+1], 65);
+               } else if ((strcmp(argv[currentarg], "--headertext")) == 0) {
+                       if (currentarg + 1 < argc) {
+                               strncpy_nt(ic.headertext, argv[currentarg + 1], 65);
                                if (debug)
                                        printf("Header text: \"%s\"\n", ic.headertext);
                                currentarg++;
@@ -173,87 +173,87 @@ int main(int argc, char *argv[])
                                printf("Error: Text string parameter for --headertext missing.\n");
                                return 1;
                        }
-               } else if (strcmp(argv[currentarg],"--altdate")==0) {
+               } else if (strcmp(argv[currentarg], "--altdate") == 0) {
                        ic.altdate = 1;
-               } else if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug"))==0) {
+               } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug")) == 0) {
                        debug = 1;
-               } else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--days"))==0) {
+               } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--days")) == 0) {
                        cfg.qmode = 1;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listdays = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listdays = atoi(argv[currentarg + 1]);
                                if (cfg.listdays < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-m")==0) || (strcmp(argv[currentarg],"--months"))==0) {
+               } else if ((strcmp(argv[currentarg], "-m") == 0) || (strcmp(argv[currentarg], "--months")) == 0) {
                        cfg.qmode = 2;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listmonths = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listmonths = atoi(argv[currentarg + 1]);
                                if (cfg.listmonths < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-t")==0) || (strcmp(argv[currentarg],"--top"))==0) {
+               } else if ((strcmp(argv[currentarg], "-t") == 0) || (strcmp(argv[currentarg], "--top")) == 0) {
                        cfg.qmode = 3;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listtop = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listtop = atoi(argv[currentarg + 1]);
                                if (cfg.listtop < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-y")==0) || (strcmp(argv[currentarg],"--years"))==0) {
+               } else if ((strcmp(argv[currentarg], "-y") == 0) || (strcmp(argv[currentarg], "--years")) == 0) {
                        cfg.qmode = 4;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listyears = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listyears = atoi(argv[currentarg + 1]);
                                if (cfg.listyears < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-h")==0) || (strcmp(argv[currentarg],"--hours"))==0) {
+               } else if ((strcmp(argv[currentarg], "-h") == 0) || (strcmp(argv[currentarg], "--hours")) == 0) {
                        cfg.qmode = 8;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listhours = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listhours = atoi(argv[currentarg + 1]);
                                if (cfg.listhours < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-5")==0) || (strcmp(argv[currentarg],"--fiveminutes"))==0) {
+               } else if ((strcmp(argv[currentarg], "-5") == 0) || (strcmp(argv[currentarg], "--fiveminutes")) == 0) {
                        cfg.qmode = 9;
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.listfivemins = atoi(argv[currentarg+1]);
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.listfivemins = atoi(argv[currentarg + 1]);
                                if (cfg.listfivemins < 0) {
-                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+                                       printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
                                        return 1;
                                }
                                currentarg++;
                        }
-               } else if ((strcmp(argv[currentarg],"-s")==0) || (strcmp(argv[currentarg],"--summary"))==0) {
+               } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--summary")) == 0) {
                        cfg.qmode = 5;
-               } else if ((strcmp(argv[currentarg],"-hg")==0) || (strcmp(argv[currentarg],"--hoursgraph"))==0) {
+               } else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv[currentarg], "--hoursgraph")) == 0) {
                        cfg.qmode = 7;
-               } else if ((strcmp(argv[currentarg],"-hs")==0) || (strcmp(argv[currentarg],"--hsummary"))==0) {
+               } else if ((strcmp(argv[currentarg], "-hs") == 0) || (strcmp(argv[currentarg], "--hsummary")) == 0) {
                        cfg.qmode = 51;
-               } else if ((strcmp(argv[currentarg],"-vs")==0) || (strcmp(argv[currentarg],"--vsummary"))==0) {
+               } else if ((strcmp(argv[currentarg], "-vs") == 0) || (strcmp(argv[currentarg], "--vsummary")) == 0) {
                        cfg.qmode = 52;
-               } else if ((strcmp(argv[currentarg],"-nh")==0) || (strcmp(argv[currentarg],"--noheader"))==0) {
+               } else if ((strcmp(argv[currentarg], "-nh") == 0) || (strcmp(argv[currentarg], "--noheader")) == 0) {
                        ic.showheader = 0;
-               } else if ((strcmp(argv[currentarg],"-ne")==0) || (strcmp(argv[currentarg],"--noedge"))==0) {
+               } else if ((strcmp(argv[currentarg], "-ne") == 0) || (strcmp(argv[currentarg], "--noedge")) == 0) {
                        ic.showedge = 0;
-               } else if ((strcmp(argv[currentarg],"-nl")==0) || (strcmp(argv[currentarg],"--nolegend"))==0) {
+               } else if ((strcmp(argv[currentarg], "-nl") == 0) || (strcmp(argv[currentarg], "--nolegend")) == 0) {
                        ic.showlegend = 0;
-               } else if ((strcmp(argv[currentarg],"-ru")==0) || (strcmp(argv[currentarg],"--rateunit"))==0) {
-                       if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
-                               cfg.rateunit = atoi(argv[currentarg+1]);
+               } else if ((strcmp(argv[currentarg], "-ru") == 0) || (strcmp(argv[currentarg], "--rateunit")) == 0) {
+                       if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+                               cfg.rateunit = atoi(argv[currentarg + 1]);
                                if (cfg.rateunit > 1 || cfg.rateunit < 0) {
                                        printf("Error: Invalid parameter \"%d\" for --rateunit.\n", cfg.rateunit);
                                        printf(" Valid parameters:\n");
@@ -270,35 +270,35 @@ int main(int argc, char *argv[])
                                if (debug)
                                        printf("Rateunit changed: %d\n", cfg.rateunit);
                        }
-               } else if ((strcmp(argv[currentarg],"-b")==0) || (strcmp(argv[currentarg],"--begin")==0)) {
-                       if (currentarg+1<argc) {
-                               if (!validatedatetime(argv[currentarg+1])) {
+               } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[currentarg], "--begin") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               if (!validatedatetime(argv[currentarg + 1])) {
                                        printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
                                        return 1;
                                }
-                               strncpy_nt(ic.databegin, argv[currentarg+1], 18);
+                               strncpy_nt(ic.databegin, argv[currentarg + 1], 18);
                                currentarg++;
                        } else {
                                printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"-e")==0) || (strcmp(argv[currentarg],"--end")==0)) {
-                       if (currentarg+1<argc) {
-                               if (!validatedatetime(argv[currentarg+1])) {
+               } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[currentarg], "--end") == 0)) {
+                       if (currentarg + 1 < argc) {
+                               if (!validatedatetime(argv[currentarg + 1])) {
                                        printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
                                        return 1;
                                }
-                               strncpy_nt(ic.dataend, argv[currentarg+1], 18);
+                               strncpy_nt(ic.dataend, argv[currentarg + 1], 18);
                                currentarg++;
                        } else {
                                printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
                                return 1;
                        }
-               } else if ((strcmp(argv[currentarg],"-v")==0) || (strcmp(argv[currentarg],"--version"))==0) {
+               } else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[currentarg], "--version")) == 0) {
                        printf("vnStat image output %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
                        return 0;
                } else {
-                       printf("Unknown arg \"%s\". Use --help for help.\n",argv[currentarg]);
+                       printf("Unknown arg \"%s\". Use --help for help.\n", argv[currentarg]);
                        return 1;
                }
        }
@@ -329,8 +329,8 @@ int main(int argc, char *argv[])
 
 void initiparams(IPARAMS *p)
 {
-       noexit = 0;        /* allow functions to exit in case of error */
-       debug = 0;         /* debug disabled by default */
+       noexit = 0;                /* allow functions to exit in case of error */
+       debug = 0;                 /* debug disabled by default */
        disableprints = 0; /* let prints be visible */
        p->interface[0] = '\0';
        p->filename[0] = '\0';
@@ -389,19 +389,19 @@ void handlecaching(IPARAMS *p, IMAGECONTENT *ic)
 {
        struct stat filestat;
 
-       if (p->cache==0 || p->filename[0]=='-') {
+       if (p->cache == 0 || p->filename[0] == '-') {
                return;
        }
 
-       if (stat(p->filename, &filestat)==0) {
-               if ((ic->current-filestat.st_mtime)<(p->cache*60)) {
+       if (stat(p->filename, &filestat) == 0) {
+               if ((ic->current - filestat.st_mtime) < (p->cache * 60)) {
                        if (debug)
-                               printf("Using cached file (%d<%d).\n", (int)(ic->current-filestat.st_mtime), p->cache*60);
+                               printf("Using cached file (%d<%d).\n", (int)(ic->current - filestat.st_mtime), p->cache * 60);
                        exit(EXIT_SUCCESS);
                }
        } else {
                /* abort if error is something else than file not found */
-               if (errno!=ENOENT) {
+               if (errno != ENOENT) {
                        printf("Error: Getting status for file \"%s\" failed: %s (%d)\n", p->filename, strerror(errno), errno);
                        exit(EXIT_FAILURE);
                }
@@ -415,7 +415,7 @@ void handledatabase(IPARAMS *p, IMAGECONTENT *ic)
                exit(EXIT_FAILURE);
        }
        if (!db_getinterfacecountbyname(p->interface)) {
-               if (strchr(p->interface, '+') == NULL)  {
+               if (strchr(p->interface, '+') == NULL) {
                        printf("Error: Interface \"%s\" not found in database.\n", p->interface);
                } else {
                        printf("Error: Not all requested interfaces found in database or given interfaces aren't unique.\n");
@@ -430,14 +430,14 @@ void handledatabase(IPARAMS *p, IMAGECONTENT *ic)
 
 void openoutput(IPARAMS *p)
 {
-       if (p->filename[0]!='-') {
-               if ((p->pngout = fopen(p->filename, "w"))==NULL) {
+       if (p->filename[0] != '-') {
+               if ((p->pngout = fopen(p->filename, "w")) == NULL) {
                        printf("Error: Opening file \"%s\" for output failed: %s\n", p->filename, strerror(errno));
                        exit(EXIT_FAILURE);
                }
        } else {
                /* output to stdout */
-               if ((p->pngout = fdopen(1, "w"))==NULL) {
+               if ((p->pngout = fdopen(1, "w")) == NULL) {
                        printf("Error: Opening stdout for output failed: %s\n", strerror(errno));
                        exit(EXIT_FAILURE);
                }
index d0900cc30b48bc3c140cd27802141fa4e82b345e..701e8cebc3d0a98206a3b94e8e883493c3041568 100644 (file)
@@ -43,8 +43,8 @@ START_TEST(logprint_options)
 END_TEST
 
 #if defined(__clang__)
-  #pragma clang diagnostic push
-  #pragma clang diagnostic ignored "-Wused-but-marked-unused"
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wused-but-marked-unused"
 #endif
 START_TEST(dmonth_return_within_range)
 {
@@ -55,7 +55,7 @@ START_TEST(dmonth_return_within_range)
 }
 END_TEST
 #if defined(__clang__)
-  #pragma clang diagnostic pop
+#pragma clang diagnostic pop
 #endif
 
 START_TEST(leapyears_are_known)
@@ -208,8 +208,8 @@ START_TEST(countercalc_rollover_with_32bit)
 
        a = 1;
        b = 0;
-       ck_assert(countercalc(&a, &b, 0)==(MAX32-1));
-       ck_assert(countercalc(&a, &b, -1)==(MAX32-1));
+       ck_assert(countercalc(&a, &b, 0) == (MAX32 - 1));
+       ck_assert(countercalc(&a, &b, -1) == (MAX32 - 1));
 }
 END_TEST
 
@@ -219,7 +219,7 @@ START_TEST(countercalc_rollover_with_64bit)
 
        a = 1;
        b = 0;
-       ck_assert(countercalc(&a, &b, 1)==(MAX64-1));
+       ck_assert(countercalc(&a, &b, 1) == (MAX64 - 1));
 }
 END_TEST
 
@@ -227,9 +227,9 @@ START_TEST(countercalc_rollover_with_64bit_2)
 {
        uint64_t a, b;
 
-       a = MAX32+1;
+       a = MAX32 + 1;
        b = 0;
-       ck_assert(countercalc(&a, &b, 1)==(MAX64-MAX32-1));
+       ck_assert(countercalc(&a, &b, 1) == (MAX64 - MAX32 - 1));
 }
 END_TEST
 
@@ -237,10 +237,10 @@ START_TEST(countercalc_rollover_with_32bit_starting_32bit)
 {
        uint64_t a, b;
 
-       a = MAX32-1;
+       a = MAX32 - 1;
        b = 0;
-       ck_assert(countercalc(&a, &b, 0)==1);
-       ck_assert(countercalc(&a, &b, -1)==1);
+       ck_assert(countercalc(&a, &b, 0) == 1);
+       ck_assert(countercalc(&a, &b, -1) == 1);
 }
 END_TEST
 
@@ -248,10 +248,10 @@ START_TEST(countercalc_rollover_with_32bit_starting_over_32bit)
 {
        uint64_t a, b;
 
-       a = MAX32+1;
+       a = MAX32 + 1;
        b = 0;
-       ck_assert(countercalc(&a, &b, 0)==(MAX64-MAX32-1));
-       ck_assert(countercalc(&a, &b, -1)==(MAX64-MAX32-1));
+       ck_assert(countercalc(&a, &b, 0) == (MAX64 - MAX32 - 1));
+       ck_assert(countercalc(&a, &b, -1) == (MAX64 - MAX32 - 1));
 }
 END_TEST
 
@@ -259,9 +259,9 @@ START_TEST(countercalc_rollover_with_64bit_starting_32bit)
 {
        uint64_t a, b;
 
-       a = MAX32-1;
+       a = MAX32 - 1;
        b = 0;
-       ck_assert(countercalc(&a, &b, 1)==(MAX64-MAX32+1));
+       ck_assert(countercalc(&a, &b, 1) == (MAX64 - MAX32 + 1));
 }
 END_TEST
 
@@ -269,9 +269,9 @@ START_TEST(countercalc_rollover_with_64bit_starting_64bit)
 {
        uint64_t a, b;
 
-       a = MAX64-1;
+       a = MAX64 - 1;
        b = 0;
-       ck_assert(countercalc(&a, &b, 1)==1);
+       ck_assert(countercalc(&a, &b, 1) == 1);
 }
 END_TEST
 
index 0d6a4e38fbfe8af179bf092ebba88e98df806ee1..564971081ca53a90f911651c8f4fc1bbe7ea5474 100644 (file)
@@ -85,7 +85,7 @@ START_TEST(ibwget_with_empty_list_and_maxbw)
        int ret;
        uint32_t limit;
        cfg.maxbw = 10;
-       ret  = ibwget("does_not_exist", &limit);
+       ret = ibwget("does_not_exist", &limit);
        ck_assert_int_eq(ret, 1);
        ck_assert_int_eq(limit, 10);
 }
@@ -98,7 +98,7 @@ START_TEST(ibwget_from_config)
        ck_assert_int_eq(loadcfg(CFGFILE), 1);
        ck_assert_int_eq(ibwloadcfg(CFGFILE), 1);
        cfg.maxbw = 10;
-       ret  = ibwget("ethnone", &limit);
+       ret = ibwget("ethnone", &limit);
        ck_assert_int_eq(ret, 1);
        ck_assert_int_eq(limit, 8);
 }
@@ -356,7 +356,7 @@ START_TEST(setcfgvalue_can_set_chars)
 {
        int ret;
        char target[32];
-       struct cfgsetting cset[] = {{ "unused", target, 0, 32, 0 }};
+       struct cfgsetting cset[] = {{"unused", target, 0, 32, 0}};
 
        ret = setcfgvalue(&cset[0], "one", "unused");
        ck_assert_int_eq(ret, 1);
@@ -379,7 +379,7 @@ END_TEST
 START_TEST(setcfgvalue_can_set_ints)
 {
        int ret, target;
-       struct cfgsetting cset[] = {{ "unused", 0, &target, 0, 0 }};
+       struct cfgsetting cset[] = {{"unused", 0, &target, 0, 0}};
 
        ret = setcfgvalue(&cset[0], "1", "unused");
        ck_assert_int_eq(ret, 1);
@@ -407,7 +407,7 @@ START_TEST(setcfgvalue_does_not_exceed_char_limit)
 {
        int ret;
        char target[10];
-       struct cfgsetting cset[] = {{ "unused", target, 0, 5, 0 }};
+       struct cfgsetting cset[] = {{"unused", target, 0, 5, 0}};
 
        ret = setcfgvalue(&cset[0], "one", "unused");
        ck_assert_int_eq(ret, 1);
@@ -426,7 +426,7 @@ END_TEST
 START_TEST(setcfgvalue_can_do_nothing)
 {
        int ret;
-       struct cfgsetting cset[] = {{ "unused", 0, 0, 0, 0 }};
+       struct cfgsetting cset[] = {{"unused", 0, 0, 0, 0}};
 
        ret = setcfgvalue(&cset[0], "nothing", "unused");
        ck_assert_int_eq(ret, 0);
index 21ed85ebc18d487d2f3882c98f99270c2292595f..8e06c2b96adf41a061a2eb814f1e1b1f26bb2bf3 100644 (file)
@@ -1087,11 +1087,11 @@ START_TEST(handledatabaseerror_does_not_exit_if_limit_is_not_reached)
 
        ck_assert_int_eq(s.dbretrycount, 1);
 
-       for (i=1; i<DBRETRYLIMIT-1; i++) {
+       for (i = 1; i < DBRETRYLIMIT - 1; i++) {
                handledatabaseerror(&s);
        }
 
-       ck_assert_int_eq(s.dbretrycount, DBRETRYLIMIT-1);
+       ck_assert_int_eq(s.dbretrycount, DBRETRYLIMIT - 1);
 }
 END_TEST
 
@@ -1110,7 +1110,7 @@ START_TEST(handledatabaseerror_exits_if_limit_is_reached)
 
        ck_assert_int_eq(s.dbretrycount, 1);
 
-       for (i=1; i<DBRETRYLIMIT; i++) {
+       for (i = 1; i < DBRETRYLIMIT; i++) {
                handledatabaseerror(&s);
        }
 }
@@ -1421,7 +1421,7 @@ START_TEST(datacache_status_has_no_issues_with_large_number_of_interfaces)
        disable_logprints();
        dcache = NULL;
 
-       for (i=0; i<100; i++) {
+       for (i = 0; i < 100; i++) {
                snprintf(buffer, 8, "eth%d", i);
                ret = datacache_add(&dcache, buffer, 0);
                ck_assert_int_eq(ret, 1);
index f3047b19e4fa56dcd13509c305c12bc5c4d6a056..bead0c67bb1085101985e34b7be2c98e92db9d12 100644 (file)
@@ -207,14 +207,14 @@ START_TEST(database_outputs_do_not_crash)
        ret = db_addinterface("something");
        ck_assert_int_eq(ret, 1);
 
-       for (i=1; i<100; i++) {
-               ret = db_addtraffic_dated("something", (uint64_t)i*1234, (uint64_t)i*2345, (uint64_t)i*85000);
+       for (i = 1; i < 100; i++) {
+               ret = db_addtraffic_dated("something", (uint64_t)i * 1234, (uint64_t)i * 2345, (uint64_t)i * 85000);
                ck_assert_int_eq(ret, 1);
        }
 
        suppress_output();
 
-       for (i=0; i<=4; i++) {
+       for (i = 0; i <= 4; i++) {
                cfg.ostyle = i;
                showdb("something", 0, "", "");
                showdb("something", 1, "", "");
@@ -275,7 +275,7 @@ START_TEST(database_outputs_do_not_crash_without_traffic)
 
        suppress_output();
 
-       for (i=0; i<=4; i++) {
+       for (i = 0; i <= 4; i++) {
                cfg.ostyle = i;
                showdb("something", 0, "", "");
                showdb("something", 1, "", "");
@@ -333,7 +333,7 @@ START_TEST(database_outputs_do_not_crash_without_data)
 
        suppress_output();
 
-       for (i=0; i<=4; i++) {
+       for (i = 0; i <= 4; i++) {
                cfg.ostyle = i;
                showdb("something", 0, "", "");
                showdb("something", 1, "", "");
@@ -394,7 +394,7 @@ START_TEST(database_outputs_do_not_crash_without_data_if_totals_are_wrong)
 
        suppress_output();
 
-       for (i=0; i<=4; i++) {
+       for (i = 0; i <= 4; i++) {
                cfg.ostyle = i;
                showdb("something", 0, "", "");
                showdb("something", 1, "", "");
@@ -658,28 +658,28 @@ START_TEST(importlegacydb_can_import_legacy_database)
        data.totaltxk = 2;
        data.currx = 456;
        data.curtx = 654;
-       for (i=0; i<24; i++) {
+       for (i = 0; i < 24; i++) {
                data.hour[i].date = 788911200 + 3600 * i;
-               data.hour[i].rx = (uint64_t)(12 * (i+1));
-               data.hour[i].tx = (uint64_t)(23 * (i+1));
+               data.hour[i].rx = (uint64_t)(12 * (i + 1));
+               data.hour[i].tx = (uint64_t)(23 * (i + 1));
        }
-       for (i=0; i<30; i++) {
-               data.day[i].date = 788911200 + 86400 * (29-i);
+       for (i = 0; i < 30; i++) {
+               data.day[i].date = 788911200 + 86400 * (29 - i);
                data.day[i].used = 1;
                data.day[i].rx = (uint64_t)(34 * i);
                data.day[i].tx = (uint64_t)(45 * i);
        }
-       for (i=0; i<12; i++) {
-               data.month[i].month = 788911200 + 2678400 * (11-i);
+       for (i = 0; i < 12; i++) {
+               data.month[i].month = 788911200 + 2678400 * (11 - i);
                data.month[i].used = 1;
                data.month[i].rx = (uint64_t)(56 * i);
                data.month[i].tx = (uint64_t)(67 * i);
        }
-       for (i=0; i<10; i++) {
+       for (i = 0; i < 10; i++) {
                data.top10[i].date = 788911200 + 86400 * i;
                data.top10[i].used = 1;
-               data.top10[i].rx = (uint64_t)(89 * (9-i+1));
-               data.top10[i].tx = (uint64_t)(90 * (9-i+1));
+               data.top10[i].rx = (uint64_t)(89 * (9 - i + 1));
+               data.top10[i].tx = (uint64_t)(90 * (9 - i + 1));
        }
 
        ck_assert_int_eq(clean_testdbdir(), 1);
@@ -700,8 +700,8 @@ START_TEST(importlegacydb_can_import_legacy_database)
 
        ck_assert_str_eq(info.alias, data.nick);
        ck_assert_int_eq(info.active, data.active);
-       ck_assert_int_eq(info.rxtotal, (data.totalrx*1024*1024)+(uint64_t)(data.totalrxk*1024));
-       ck_assert_int_eq(info.txtotal, (data.totaltx*1024*1024)+(uint64_t)(data.totaltxk*1024));
+       ck_assert_int_eq(info.rxtotal, (data.totalrx * 1024 * 1024) + (uint64_t)(data.totalrxk * 1024));
+       ck_assert_int_eq(info.txtotal, (data.totaltx * 1024 * 1024) + (uint64_t)(data.totaltxk * 1024));
        ck_assert_int_eq(info.rxcounter, data.currx);
        ck_assert_int_eq(info.txcounter, data.curtx);
        ck_assert_int_ge(info.created, data.created);
@@ -712,10 +712,9 @@ START_TEST(importlegacydb_can_import_legacy_database)
        ck_assert_int_eq(datainfo.count, 30);
        datalist_i = datalist;
        i = 29;
-       while (datalist_i != NULL)
-       {
-               ck_assert_int_eq(datalist_i->rx, data.day[i].rx*1024*1024);
-               ck_assert_int_eq(datalist_i->tx, data.day[i].tx*1024*1024);
+       while (datalist_i != NULL) {
+               ck_assert_int_eq(datalist_i->rx, data.day[i].rx * 1024 * 1024);
+               ck_assert_int_eq(datalist_i->tx, data.day[i].tx * 1024 * 1024);
                datalist_i = datalist_i->next;
                i--;
        }
@@ -726,10 +725,9 @@ START_TEST(importlegacydb_can_import_legacy_database)
        ck_assert_int_eq(datainfo.count, 12);
        datalist_i = datalist;
        i = 11;
-       while (datalist_i != NULL)
-       {
-               ck_assert_int_eq(datalist_i->rx, data.month[i].rx*1024*1024);
-               ck_assert_int_eq(datalist_i->tx, data.month[i].tx*1024*1024);
+       while (datalist_i != NULL) {
+               ck_assert_int_eq(datalist_i->rx, data.month[i].rx * 1024 * 1024);
+               ck_assert_int_eq(datalist_i->tx, data.month[i].tx * 1024 * 1024);
                datalist_i = datalist_i->next;
                i--;
        }
@@ -740,10 +738,9 @@ START_TEST(importlegacydb_can_import_legacy_database)
        ck_assert_int_eq(datainfo.count, 24);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               ck_assert_int_eq(datalist_i->rx, data.hour[i].rx*1024);
-               ck_assert_int_eq(datalist_i->tx, data.hour[i].tx*1024);
+       while (datalist_i != NULL) {
+               ck_assert_int_eq(datalist_i->rx, data.hour[i].rx * 1024);
+               ck_assert_int_eq(datalist_i->tx, data.hour[i].tx * 1024);
                datalist_i = datalist_i->next;
                i++;
        }
@@ -754,10 +751,9 @@ START_TEST(importlegacydb_can_import_legacy_database)
        ck_assert_int_eq(datainfo.count, 10);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               ck_assert_int_eq(datalist_i->rx, data.top10[i].rx*1024*1024);
-               ck_assert_int_eq(datalist_i->tx, data.top10[i].tx*1024*1024);
+       while (datalist_i != NULL) {
+               ck_assert_int_eq(datalist_i->rx, data.top10[i].rx * 1024 * 1024);
+               ck_assert_int_eq(datalist_i->tx, data.top10[i].tx * 1024 * 1024);
                datalist_i = datalist_i->next;
                i++;
        }
@@ -820,20 +816,20 @@ int writedb(DATA *data, const char *iface, const char *dirname, int newdb)
        }
 
        /* make sure version stays correct */
-       data->version=LEGACYDBVERSION;
+       data->version = LEGACYDBVERSION;
 
-       if ((testdb=fopen(file,"w"))==NULL) {
+       if ((testdb = fopen(file, "w")) == NULL) {
                snprintf(errorstring, 1024, "Unable to open database \"%s\" for writing: %s", file, strerror(errno));
                printe(PT_Error);
                return 0;
        }
 
        /* update timestamp when not merging */
-       if (newdb!=2) {
-               data->lastupdated=time(NULL);
+       if (newdb != 2) {
+               data->lastupdated = time(NULL);
        }
 
-       if (fwrite(data,sizeof(DATA),1,testdb)==0) {
+       if (fwrite(data, sizeof(DATA), 1, testdb) == 0) {
                snprintf(errorstring, 1024, "Unable to write database \"%s\": %s", file, strerror(errno));
                printe(PT_Error);
                fclose(testdb);
@@ -843,7 +839,7 @@ int writedb(DATA *data, const char *iface, const char *dirname, int newdb)
                        printf("db: Database \"%s\" saved.\n", file);
                }
                fclose(testdb);
-               if ((newdb) && (noexit==0)) {
+               if ((newdb) && (noexit == 0)) {
                        snprintf(errorstring, 1024, "-> A new database has been created.");
                        printe(PT_Info);
                        matchdbownerwithdirowner(dirname);
@@ -872,7 +868,7 @@ int backupdb(const char *current, const char *backup)
        b = fileno(bf);
 
        /* copy data */
-       while((bytes = (int)read(c, buffer, sizeof(buffer))) > 0) {
+       while ((bytes = (int)read(c, buffer, sizeof(buffer))) > 0) {
                if (write(b, buffer, (size_t)bytes) < 0) {
                        close(c);
                        fclose(bf);
index fb10bf8f1834c9410bbe181055f44dba87926e25..8d835b6c03c41eedb121ca000d6a90538d996f62 100644 (file)
@@ -276,8 +276,8 @@ START_TEST(datacache_can_do_stuff)
 
        iter = dc;
        ret = datacache_seek(&iter, "eth3");
-       for (i=1; i<=10; i++) {
-               ret = xferlog_add(&iter->log, (time_t)i, (uint64_t)i*10, (uint64_t)i*20);
+       for (i = 1; i <= 10; i++) {
+               ret = xferlog_add(&iter->log, (time_t)i, (uint64_t)i * 10, (uint64_t)i * 20);
                ck_assert_int_eq(ret, 1);
        }
        ck_assert_int_eq(iter->log->timestamp, 10);
index e85318138368fbc616e6c24cd23c27a8c3b0fc74..cf02fa9467d8ba915e040bbd3eaec567211f72bd 100644 (file)
@@ -695,7 +695,8 @@ END_TEST
 START_TEST(db_getiflist_lists_interfaces)
 {
        int ret;
-       dbiflist *dbifl = NULL, *dbifl_i = NULL;;
+       dbiflist *dbifl = NULL, *dbifl_i = NULL;
+       ;
 
        defaultcfg();
 
@@ -986,7 +987,7 @@ void range_test_month_setup(void)
        ret = db_addinterface("ethtest");
        ck_assert_int_eq(ret, 1);
 
-       for (i=1; i<=6; i++) {
+       for (i = 1; i <= 6; i++) {
                ret = db_insertdata("month", "ethtest", 1, 2, get_timestamp(2000, i, 1, 0, 0));
                ck_assert_int_eq(ret, 1);
        }
@@ -1006,9 +1007,8 @@ START_TEST(db_getdata_range_can_get_months_without_range_defined)
        ck_assert_int_eq(datainfo.count, 6);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-01-01");
@@ -1042,9 +1042,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_matching_existing_data)
        ck_assert_int_eq(datainfo.count, 6);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-01-01");
@@ -1078,9 +1077,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_past_existing_data)
        ck_assert_int_eq(datainfo.count, 6);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-01-01");
@@ -1114,9 +1112,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin_and_end)
        ck_assert_int_eq(datainfo.count, 3);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-02-01");
@@ -1150,9 +1147,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin)
        ck_assert_int_eq(datainfo.count, 4);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-03-01");
@@ -1186,9 +1182,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin_with_limit)
        ck_assert_int_eq(datainfo.count, 3);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-03-01");
@@ -1222,9 +1217,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_limiting_end)
        ck_assert_int_eq(datainfo.count, 4);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-01-01");
@@ -1258,9 +1252,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_limiting_end_with_limit)
        ck_assert_int_eq(datainfo.count, 3);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-02-01");
@@ -1294,9 +1287,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_on_same_month)
        ck_assert_int_eq(datainfo.count, 1);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-04-01");
@@ -1326,9 +1318,8 @@ START_TEST(db_getdata_range_can_get_months_with_range_past_first_day_of_month)
        ck_assert_int_eq(datainfo.count, 3);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-03-01");
@@ -1359,8 +1350,8 @@ void range_test_hour_setup(void)
        ret = db_addinterface("ethtest");
        ck_assert_int_eq(ret, 1);
 
-       for (j=2; j<5; j++) {
-               for (i=0; i<24; i++) {
+       for (j = 2; j < 5; j++) {
+               for (i = 0; i < 24; i++) {
                        ret = db_insertdata("hour", "ethtest", 1, 2, get_timestamp(2002, 2, j, i, 0));
                        ck_assert_int_eq(ret, 1);
                }
@@ -1381,9 +1372,8 @@ START_TEST(db_getdata_range_can_get_hours_without_range_defined)
        ck_assert_int_eq(datainfo.count, 72);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 00:00");
@@ -1417,9 +1407,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_matching_existing_data)
        ck_assert_int_eq(datainfo.count, 72);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 00:00");
@@ -1453,9 +1442,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_past_existing_data)
        ck_assert_int_eq(datainfo.count, 72);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 00:00");
@@ -1489,9 +1477,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin_and_end)
        ck_assert_int_eq(datainfo.count, 22);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 20:00");
@@ -1525,9 +1512,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin)
        ck_assert_int_eq(datainfo.count, 52);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 20:00");
@@ -1561,9 +1547,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin_with_limit)
        ck_assert_int_eq(datainfo.count, 11);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 20:00");
@@ -1597,9 +1582,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_limiting_end)
        ck_assert_int_eq(datainfo.count, 21);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 00:00");
@@ -1633,9 +1617,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_limiting_end_with_limit)
        ck_assert_int_eq(datainfo.count, 5);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 16:00");
@@ -1669,9 +1652,8 @@ START_TEST(db_getdata_range_can_get_hours_with_range_on_same_hour)
        ck_assert_int_eq(datainfo.count, 1);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2002-02-02 20:00");
@@ -1708,7 +1690,7 @@ START_TEST(db_getdata_range_with_merged_interfaces)
        ret = db_addinterface("ethother");
        ck_assert_int_eq(ret, 1);
 
-       for (i=1; i<=20; i++) {
+       for (i = 1; i <= 20; i++) {
                ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
                ck_assert_int_eq(ret, 1);
                ret = db_addtraffic_dated("ethother", 3, 7, get_timestamp(2000, 2, i, 0, 0));
@@ -1720,9 +1702,8 @@ START_TEST(db_getdata_range_with_merged_interfaces)
        ck_assert_int_eq(datainfo.count, 1);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-02-01");
@@ -1755,7 +1736,7 @@ START_TEST(db_addtraffic_without_monthrotate)
        ret = db_addinterface("ethtest");
        ck_assert_int_eq(ret, 1);
 
-       for (i=1; i<=20; i++) {
+       for (i = 1; i <= 20; i++) {
                ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
                ck_assert_int_eq(ret, 1);
        }
@@ -1765,9 +1746,8 @@ START_TEST(db_addtraffic_without_monthrotate)
        ck_assert_int_eq(datainfo.count, 1);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-02-01");
@@ -1800,7 +1780,7 @@ START_TEST(db_addtraffic_with_monthrotate)
        ret = db_addinterface("ethtest");
        ck_assert_int_eq(ret, 1);
 
-       for (i=1; i<=20; i++) {
+       for (i = 1; i <= 20; i++) {
                ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
                ck_assert_int_eq(ret, 1);
        }
@@ -1810,9 +1790,8 @@ START_TEST(db_addtraffic_with_monthrotate)
        ck_assert_int_eq(datainfo.count, 2);
        datalist_i = datalist;
        i = 0;
-       while (datalist_i != NULL)
-       {
-               switch(i) {
+       while (datalist_i != NULL) {
+               switch (i) {
                        case 0:
                                strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
                                ck_assert_str_eq(timestamp, "2000-01-01");
index 4634d4508bde49f935816537f5c8dbf490ff0d22..3d573142c41876a53dd3d84d8e7d589dd59f4ff3 100644 (file)
@@ -238,13 +238,13 @@ char *hourly_imagescale_logic(const uint64_t max, const int rate)
                step = 1;
        }
 
-       for (i=step; (uint64_t)(scaleunit * (unsigned int)i) <= max; i=i+step) {
+       for (i = step; (uint64_t)(scaleunit * (unsigned int)i) <= max; i = i + step) {
                s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
                prev = s;
        }
 
        s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
-       if ( ((s+prev)/2) <= 128 ) {
+       if (((s + prev) / 2) <= 128) {
                ;
        } else {
                i = i - step;
@@ -424,173 +424,172 @@ START_TEST(libgd_output_comparison)
        /* line 1 */
        x = 40;
        y = 80;
-       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd bug workaround", ic.ctext);
+       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 105, (unsigned char *)"libgd bug workaround", ic.ctext);
        drawdonut(&ic, x, y, (float)0, (float)0);
-       drawdonut(&ic, x+55, y, (float)50, (float)50);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)50, (float)50);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 50/50", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)100, (float)0);
-       drawdonut(&ic, x+55, y, (float)0, (float)100);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)0, (float)100);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"100/0 - 0/100", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)60, (float)40);
-       drawdonut(&ic, x+55, y, (float)40, (float)60);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)40, (float)60);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"60/40 - 40/60", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)75, (float)25);
-       drawdonut(&ic, x+55, y, (float)25, (float)75);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)25, (float)75);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"75/25 - 25/75", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)90, (float)10);
-       drawdonut(&ic, x+55, y, (float)10, (float)90);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)10, (float)90);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"90/10 - 10/90", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)95, (float)5);
-       drawdonut(&ic, x+55, y, (float)5, (float)95);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)5, (float)95);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"95/5 - 5/95", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)99, (float)1);
-       drawdonut(&ic, x+55, y, (float)1, (float)99);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)1, (float)99);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99/1 - 1/99", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)99.9, (float)0.1);
-       drawdonut(&ic, x+55, y, (float)0.1, (float)99.9);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)0.1, (float)99.9);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99.9/0.1 - 0.1/99.9", ic.ctext);
 
        /* line 2 */
        x = 40;
        y = 160;
        drawdonut(&ic, x, y, (float)0, (float)0);
-       drawdonut(&ic, x+55, y, (float)25, (float)25);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)25, (float)25);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 25/25", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)50, (float)0);
-       drawdonut(&ic, x+55, y, (float)0, (float)50);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)0, (float)50);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"50/0 - 0/50", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)40, (float)30);
-       drawdonut(&ic, x+55, y, (float)30, (float)40);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)30, (float)40);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"40/30 - 30/40", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)30, (float)20);
-       drawdonut(&ic, x+55, y, (float)20, (float)30);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)20, (float)30);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"30/20 - 20/30", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)20, (float)10);
-       drawdonut(&ic, x+55, y, (float)10, (float)20);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)10, (float)20);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"20/10 - 10/20", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)15, (float)5);
-       drawdonut(&ic, x+55, y, (float)5, (float)15);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)5, (float)15);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"15/5 - 5/15", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)10, (float)1);
-       drawdonut(&ic, x+55, y, (float)1, (float)10);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)1, (float)10);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"10/1 - 1/10", ic.ctext);
 
        x += 130;
        drawdonut(&ic, x, y, (float)1, (float)0.1);
-       drawdonut(&ic, x+55, y, (float)0.1, (float)1);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext);
+       drawdonut(&ic, x + 55, y, (float)0.1, (float)1);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"1.0/0.1 - 0.1/1.0", ic.ctext);
 
        /* line 3 */
        x = 40;
        y = 270;
-       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd native", ic.ctext);
+       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 105, (unsigned char *)"libgd native", ic.ctext);
        drawdonut_libgd_native(&ic, x, y, (float)0, (float)0);
-       drawdonut_libgd_native(&ic, x+55, y, (float)50, (float)50);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)50, (float)50);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 50/50", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)100, (float)0);
-       drawdonut_libgd_native(&ic, x+55, y, (float)0, (float)100);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)0, (float)100);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"100/0 - 0/100", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)60, (float)40);
-       drawdonut_libgd_native(&ic, x+55, y, (float)40, (float)60);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)40, (float)60);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"60/40 - 40/60", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)75, (float)25);
-       drawdonut_libgd_native(&ic, x+55, y, (float)25, (float)75);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)25, (float)75);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"75/25 - 25/75", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)90, (float)10);
-       drawdonut_libgd_native(&ic, x+55, y, (float)10, (float)90);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)10, (float)90);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"90/10 - 10/90", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)95, (float)5);
-       drawdonut_libgd_native(&ic, x+55, y, (float)5, (float)95);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)5, (float)95);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"95/5 - 5/95", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)99, (float)1);
-       drawdonut_libgd_native(&ic, x+55, y, (float)1, (float)99);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)1, (float)99);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99/1 - 1/99", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)99.9, (float)0.1);
-       drawdonut_libgd_native(&ic, x+55, y, (float)0.1, (float)99.9);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)0.1, (float)99.9);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99.9/0.1 - 0.1/99.9", ic.ctext);
 
        /* line 4 */
        x = 40;
        y = 350;
        drawdonut_libgd_native(&ic, x, y, (float)0, (float)0);
-       drawdonut_libgd_native(&ic, x+55, y, (float)25, (float)25);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)25, (float)25);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 25/25", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)50, (float)0);
-       drawdonut_libgd_native(&ic, x+55, y, (float)0, (float)50);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)0, (float)50);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"50/0 - 0/50", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)40, (float)30);
-       drawdonut_libgd_native(&ic, x+55, y, (float)30, (float)40);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)30, (float)40);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"40/30 - 30/40", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)30, (float)20);
-       drawdonut_libgd_native(&ic, x+55, y, (float)20, (float)30);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)20, (float)30);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"30/20 - 20/30", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)20, (float)10);
-       drawdonut_libgd_native(&ic, x+55, y, (float)10, (float)20);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)10, (float)20);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"20/10 - 10/20", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)15, (float)5);
-       drawdonut_libgd_native(&ic, x+55, y, (float)5, (float)15);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)5, (float)15);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"15/5 - 5/15", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)10, (float)1);
-       drawdonut_libgd_native(&ic, x+55, y, (float)1, (float)10);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext);
+       drawdonut_libgd_native(&ic, x + 55, y, (float)1, (float)10);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"10/1 - 1/10", ic.ctext);
 
        x += 130;
        drawdonut_libgd_native(&ic, x, y, (float)1, (float)0.1);
-       drawdonut_libgd_native(&ic, x+55, y, (float)0.1, (float)1);
-       gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext);
-
+       drawdonut_libgd_native(&ic, x + 55, y, (float)0.1, (float)1);
+       gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"1.0/0.1 - 0.1/1.0", ic.ctext);
 
        gdImagePng(ic.im, pngout);
        ret = fclose(pngout);
@@ -623,27 +622,27 @@ START_TEST(element_output_check)
        x = 40;
        y = 70;
 
-       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+15, (unsigned char*)"50.0%", ic.ctext);
+       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 15, (unsigned char *)"50.0%", ic.ctext);
 
-       for (i=50.0; i>=0; i-=(float)0.2) {
+       for (i = 50.0; i >= 0; i -= (float)0.2) {
 
                drawdonut(&ic, x, y, i, i);
                x += 55;
 
-               if (x>1000) {
+               if (x > 1000) {
                        x = 40;
                        y += 60;
 
-                       snprintf(buffer, 6, "%3.1f%%", (double)i-0.2);
-                       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+15, (unsigned char*)buffer, ic.ctext);
+                       snprintf(buffer, 6, "%3.1f%%", (double)i - 0.2);
+                       gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 15, (unsigned char *)buffer, ic.ctext);
                }
        }
 
-       gdImageString(ic.im, gdFontGetGiant(), 1020, 40, (unsigned char*)"Giant - The quick brown fox jumps over the lazy dog", ic.ctext);
-       gdImageString(ic.im, gdFontGetLarge(), 1020, 60, (unsigned char*)"Large - The quick brown fox jumps over the lazy dog", ic.ctext);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1020, 80, (unsigned char*)"MediumBold - The quick brown fox jumps over the lazy dog", ic.ctext);
-       gdImageString(ic.im, gdFontGetSmall(), 1020, 100, (unsigned char*)"Small - The quick brown fox jumps over the lazy dog", ic.ctext);
-       gdImageString(ic.im, gdFontGetTiny(), 1020, 120, (unsigned char*)"Tiny - The quick brown fox jumps over the lazy dog", ic.ctext);
+       gdImageString(ic.im, gdFontGetGiant(), 1020, 40, (unsigned char *)"Giant - The quick brown fox jumps over the lazy dog", ic.ctext);
+       gdImageString(ic.im, gdFontGetLarge(), 1020, 60, (unsigned char *)"Large - The quick brown fox jumps over the lazy dog", ic.ctext);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1020, 80, (unsigned char *)"MediumBold - The quick brown fox jumps over the lazy dog", ic.ctext);
+       gdImageString(ic.im, gdFontGetSmall(), 1020, 100, (unsigned char *)"Small - The quick brown fox jumps over the lazy dog", ic.ctext);
+       gdImageString(ic.im, gdFontGetTiny(), 1020, 120, (unsigned char *)"Tiny - The quick brown fox jumps over the lazy dog", ic.ctext);
 
        drawlegend(&ic, 1230, 140);
 
@@ -671,21 +670,20 @@ START_TEST(element_output_check)
        drawpole(&ic, 1210, 360, 400, 0, 100, 130);
        drawpole(&ic, 1230, 360, 400, 100, 0, 130);
 
-
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 400, (unsigned char*)"Color: ctext", ic.ctext);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 420, (unsigned char*)"Color: cedge", ic.cedge);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 440, (unsigned char*)"Color: cheader", ic.cheader);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 460, (unsigned char*)"Color: cheadertitle", ic.cheadertitle);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 480, (unsigned char*)"Color: cheaderdate", ic.cheaderdate);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 500, (unsigned char*)"Color: cline", ic.cline);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 520, (unsigned char*)"Color: clinel", ic.clinel);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 540, (unsigned char*)"Color: cbackground", ic.cbackground);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 560, (unsigned char*)"Color: cvnstat", ic.cvnstat);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 580, (unsigned char*)"Color: cbgoffset", ic.cbgoffset);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 600, (unsigned char*)"Color: crx", ic.crx);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 620, (unsigned char*)"Color: crxd", ic.crxd);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 640, (unsigned char*)"Color: ctx", ic.ctx);
-       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 660, (unsigned char*)"Color: ctxd", ic.ctxd);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 400, (unsigned char *)"Color: ctext", ic.ctext);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 420, (unsigned char *)"Color: cedge", ic.cedge);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 440, (unsigned char *)"Color: cheader", ic.cheader);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 460, (unsigned char *)"Color: cheadertitle", ic.cheadertitle);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 480, (unsigned char *)"Color: cheaderdate", ic.cheaderdate);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 500, (unsigned char *)"Color: cline", ic.cline);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 520, (unsigned char *)"Color: clinel", ic.clinel);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 540, (unsigned char *)"Color: cbackground", ic.cbackground);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 560, (unsigned char *)"Color: cvnstat", ic.cvnstat);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 580, (unsigned char *)"Color: cbgoffset", ic.cbgoffset);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 600, (unsigned char *)"Color: crx", ic.crx);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 620, (unsigned char *)"Color: crxd", ic.crxd);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 640, (unsigned char *)"Color: ctx", ic.ctx);
+       gdImageString(ic.im, gdFontGetMediumBold(), 1280, 660, (unsigned char *)"Color: ctxd", ic.ctxd);
 
        gdImagePng(ic.im, pngout);
        ret = fclose(pngout);
index eb3c802ad826299c124c834538fcda9af0f1727c..2702c4c34bc80db37b0f648fcd6374293efdbc01 100644 (file)
@@ -10,8 +10,8 @@ START_TEST(getbtime_does_not_return_zero)
 END_TEST
 
 #if defined(__clang__)
-  #pragma clang diagnostic push
-  #pragma clang diagnostic ignored "-Wused-but-marked-unused"
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wused-but-marked-unused"
 #endif
 START_TEST(getunitprefix_returns_something_with_all_cfg_combinations)
 {
@@ -19,7 +19,7 @@ START_TEST(getunitprefix_returns_something_with_all_cfg_combinations)
        int j;
 
        cfg.unitmode = _i;
-       for (j=1; j<=(UNITPREFIXCOUNT+1); j++) {
+       for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) {
                string = getunitprefix(j);
                ck_assert_int_gt(strlen(string), 0);
        }
@@ -31,7 +31,7 @@ START_TEST(getrateunitprefix_returns_something_with_all_cfg_combinations)
        const char *string;
        int j;
 
-       for (j=1; j<=(UNITPREFIXCOUNT+1); j++) {
+       for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) {
                string = getrateunitprefix(_i, j);
                ck_assert_int_gt(strlen(string), 0);
        }
@@ -43,9 +43,9 @@ START_TEST(getunitdivisor_returns_something_with_all_cfg_combinations)
        int j;
        char div[16];
 
-       for (j=1; j<=(UNITPREFIXCOUNT+1); j++) {
-               snprintf(div, 15, "%"PRIu64"", getunitdivisor(_i, j));
-               if (j>UNITPREFIXCOUNT) {
+       for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) {
+               snprintf(div, 15, "%" PRIu64 "", getunitdivisor(_i, j));
+               if (j > UNITPREFIXCOUNT) {
                        ck_assert_str_eq(div, "1");
                } else {
                        ck_assert_str_ne(div, "0");
@@ -54,7 +54,7 @@ START_TEST(getunitdivisor_returns_something_with_all_cfg_combinations)
 }
 END_TEST
 #if defined(__clang__)
-  #pragma clang diagnostic pop
+#pragma clang diagnostic pop
 #endif
 
 START_TEST(spacecheck_does_not_check_when_not_configured)
@@ -209,9 +209,9 @@ START_TEST(gettrafficrate_zero_interval)
 {
        int i, j;
 
-       for (i=0; i<=1; i++) {
+       for (i = 0; i <= 1; i++) {
                cfg.rateunit = i;
-               for (j=0; j<=2; j++) {
+               for (j = 0; j <= 2; j++) {
                        cfg.unitmode = j;
                        ck_assert_str_eq(gettrafficrate(1, 0, 0), "n/a");
                }
@@ -330,12 +330,12 @@ START_TEST(gettrafficrate_padding)
        cfg.defaultdecimals = 2;
        cfg.unitmode = 0;
        cfg.rateunit = 0;
-       ck_assert_str_eq(gettrafficrate(102400, 1, 0),  "100.00 KiB/s");
+       ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KiB/s");
        ck_assert_str_eq(gettrafficrate(102400, 1, 12), "100.00 KiB/s");
        ck_assert_str_eq(gettrafficrate(102400, 1, 14), "  100.00 KiB/s");
 
-       ck_assert_str_eq(gettrafficrate(900, 1, 0),  "900 B/s");
-       ck_assert_str_eq(gettrafficrate(900, 1, 7),  "900 B/s");
+       ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s");
+       ck_assert_str_eq(gettrafficrate(900, 1, 7), "900 B/s");
        ck_assert_str_eq(gettrafficrate(900, 1, 12), "     900 B/s");
        ck_assert_str_eq(gettrafficrate(900, 1, 14), "       900 B/s");
 }
@@ -346,9 +346,9 @@ START_TEST(sighandler_sets_signal)
        debug = 1;
        intsignal = 0;
        disable_logprints();
-       ck_assert(signal(SIGINT, sighandler)!=SIG_ERR);
-       ck_assert(signal(SIGHUP, sighandler)!=SIG_ERR);
-       ck_assert(signal(SIGTERM, sighandler)!=SIG_ERR);
+       ck_assert(signal(SIGINT, sighandler) != SIG_ERR);
+       ck_assert(signal(SIGHUP, sighandler) != SIG_ERR);
+       ck_assert(signal(SIGTERM, sighandler) != SIG_ERR);
 
        ck_assert_int_eq(kill(getpid(), SIGINT), 0);
        ck_assert_int_eq(intsignal, SIGINT);
index 866059d67e7f141748f6be81d5faf03cd81a3d3c..3102c97cc076ef4c8a9b52c882a88ddac83ba3c2 100644 (file)
@@ -87,9 +87,9 @@ int clean_testdbdir(void)
 
        create_testdir();
 
-       if (stat(TESTDBDIR, &statbuf)!=0) {
-               if (errno==ENOENT) {
-                       if (mkdir(TESTDBDIR, 0755)==0) {
+       if (stat(TESTDBDIR, &statbuf) != 0) {
+               if (errno == ENOENT) {
+                       if (mkdir(TESTDBDIR, 0755) == 0) {
                                return 1;
                        }
                }
@@ -100,7 +100,7 @@ int clean_testdbdir(void)
                ck_abort_msg("error \"%s\" while removing directory \"%s\", please remove it manually", strerror(errno), TESTDBDIR);
        }
 
-       if (mkdir(TESTDBDIR, 0755)!=0) {
+       if (mkdir(TESTDBDIR, 0755) != 0) {
                ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), TESTDBDIR);
        }
 
@@ -111,9 +111,9 @@ int create_testdir(void)
 {
        struct stat statbuf;
 
-       if (stat(TESTDIR, &statbuf)!=0) {
-               if (errno==ENOENT) {
-                       if (mkdir(TESTDIR, 0755)==0) {
+       if (stat(TESTDIR, &statbuf) != 0) {
+               if (errno == ENOENT) {
+                       if (mkdir(TESTDIR, 0755) == 0) {
                                return 1;
                        }
                }
@@ -127,8 +127,8 @@ int create_directory(const char *directory)
 {
        struct stat statbuf;
 
-       if (stat(directory, &statbuf)!=0) {
-               if (errno==ENOENT) {
+       if (stat(directory, &statbuf) != 0) {
+               if (errno == ENOENT) {
                        if (mkdir(directory, 0755) != 0) {
                                ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), directory);
                        }
@@ -146,26 +146,26 @@ int remove_directory(const char *directory)
        struct dirent *di = NULL;
        char entryname[512];
 
-       if ((dir=opendir(directory))==NULL) {
-               if (errno==ENOENT) {
+       if ((dir = opendir(directory)) == NULL) {
+               if (errno == ENOENT) {
                        return 1;
                } else {
                        return 0;
                }
        }
 
-       while ((di=readdir(dir))) {
+       while ((di = readdir(dir))) {
                switch (di->d_type) {
                        case DT_LNK:
                        case DT_REG:
                                snprintf(entryname, 512, "%s/%s", directory, di->d_name);
-                               if (unlink(entryname)!=0) {
+                               if (unlink(entryname) != 0) {
                                        closedir(dir);
                                        return 0;
                                }
                                break;
                        case DT_DIR:
-                               if (strcmp(di->d_name, ".")==0 || strcmp(di->d_name, "..")==0) {
+                               if (strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0) {
                                        continue;
                                }
                                snprintf(entryname, 512, "%s/%s", directory, di->d_name);
@@ -179,7 +179,7 @@ int remove_directory(const char *directory)
                }
        }
        closedir(dir);
-       if (rmdir(directory)!=0) {
+       if (rmdir(directory) != 0) {
                return 0;
        }
 
@@ -192,7 +192,7 @@ int create_zerosize_dbfile(const char *iface)
        char filename[512];
 
        snprintf(filename, 512, "%s/%s", TESTDBDIR, iface);
-       if ((fp=fopen(filename, "w"))==NULL) {
+       if ((fp = fopen(filename, "w")) == NULL) {
                ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
        }
        fclose(fp);
@@ -206,8 +206,8 @@ int check_dbfile_exists(const char *iface, const int minsize)
        char filename[512];
 
        snprintf(filename, 512, "%s/%s", TESTDBDIR, iface);
-       if (stat(filename, &statbuf)!=0) {
-               if (errno==ENOENT) {
+       if (stat(filename, &statbuf) != 0) {
+               if (errno == ENOENT) {
                        return 0;
                }
                ck_abort_msg("error \"%s\" while inspecting file \"%s\"", strerror(errno), filename);
@@ -225,7 +225,7 @@ int fake_proc_net_dev(const char *mode, const char *iface, const int rx, const i
        FILE *devfp;
        char filename[512];
 
-       if (strcmp(mode, "w") != 0  && strcmp(mode, "a") != 0) {
+       if (strcmp(mode, "w") != 0 && strcmp(mode, "a") != 0) {
                ck_abort_msg("error: only w and a modes are supported");
        }
 
@@ -233,7 +233,7 @@ int fake_proc_net_dev(const char *mode, const char *iface, const int rx, const i
        create_directory(TESTPROCDIR);
 
        snprintf(filename, 512, "%s/dev", TESTPROCDIR);
-       if ((devfp=fopen(filename, mode))==NULL) {
+       if ((devfp = fopen(filename, mode)) == NULL) {
                ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
        }
 
@@ -266,7 +266,7 @@ int fake_sys_class_net(const char *iface, const int rx, const int tx, const int
 
        if (speed != 0) {
                snprintf(filename, 512, "%s/%s/speed", TESTSYSCLASSNETDIR, iface);
-               if ((devfp=fopen(filename, "w"))==NULL) {
+               if ((devfp = fopen(filename, "w")) == NULL) {
                        ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
                }
                fprintf(devfp, "%d\n", speed);
@@ -274,28 +274,28 @@ int fake_sys_class_net(const char *iface, const int rx, const int tx, const int
        }
 
        snprintf(filename, 512, "%s/%s/statistics/rx_bytes", TESTSYSCLASSNETDIR, iface);
-       if ((devfp=fopen(filename, "w"))==NULL) {
+       if ((devfp = fopen(filename, "w")) == NULL) {
                ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
        }
        fprintf(devfp, "%d\n", rx);
        fclose(devfp);
 
        snprintf(filename, 512, "%s/%s/statistics/tx_bytes", TESTSYSCLASSNETDIR, iface);
-       if ((devfp=fopen(filename, "w"))==NULL) {
+       if ((devfp = fopen(filename, "w")) == NULL) {
                ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
        }
        fprintf(devfp, "%d\n", tx);
        fclose(devfp);
 
        snprintf(filename, 512, "%s/%s/statistics/rx_packets", TESTSYSCLASSNETDIR, iface);
-       if ((devfp=fopen(filename, "w"))==NULL) {
+       if ((devfp = fopen(filename, "w")) == NULL) {
                ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
        }
        fprintf(devfp, "%d\n", rxp);
        fclose(devfp);
 
        snprintf(filename, 512, "%s/%s/statistics/tx_packets", TESTSYSCLASSNETDIR, iface);
-       if ((devfp=fopen(filename, "w"))==NULL) {
+       if ((devfp = fopen(filename, "w")) == NULL) {
                ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
        }
        fprintf(devfp, "%d\n", txp);