[main.{c,h}] Let's put some safety into this code! xD
This commit is contained in:
parent
1ef712c6a5
commit
8556f85781
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int const argc, const char * const * const argv) {
|
||||||
price_t price;
|
price_t price;
|
||||||
wattage_t wattage;
|
wattage_t wattage;
|
||||||
interval_t interval = 0;
|
interval_t interval = 0;
|
||||||
@ -23,7 +23,7 @@ int main(int argc, char **argv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_arguments(int argc, char **argv, price_t *price, wattage_t *wattage, interval_t *interval) {
|
int parse_arguments(const int argc, const char *const *const argv, price_t *const price, wattage_t *const wattage, interval_t *const interval) {
|
||||||
if (argc < 2) return 1;
|
if (argc < 2) return 1;
|
||||||
|
|
||||||
for (int i = 1, pos = 0; i < argc; ++i)
|
for (int i = 1, pos = 0; i < argc; ++i)
|
||||||
@ -46,7 +46,7 @@ int parse_arguments(int argc, char **argv, price_t *price, wattage_t *wattage, i
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline interval_t interval_to_seconds(char *interval) {
|
inline interval_t interval_to_seconds(const char * const interval) {
|
||||||
interval_t intrvl = (interval_t)atol(interval);
|
interval_t intrvl = (interval_t)atol(interval);
|
||||||
|
|
||||||
switch (interval[strlen(interval) - 1]) {
|
switch (interval[strlen(interval) - 1]) {
|
||||||
@ -64,7 +64,7 @@ inline interval_t interval_to_seconds(char *interval) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline price_t to_wattspersecond(price_t price) {
|
inline price_t to_wattspersecond(const price_t price) {
|
||||||
return price / 1000.f / 3600.f;
|
return price / 1000.f / 3600.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,10 +7,10 @@ typedef long double price_t;
|
|||||||
typedef long double wattage_t;
|
typedef long double wattage_t;
|
||||||
typedef unsigned long interval_t;
|
typedef unsigned long interval_t;
|
||||||
|
|
||||||
int parse_arguments(int argc, char **argv, price_t *price, wattage_t *wattage, interval_t *interval);
|
int parse_arguments(const int argc, const char *const *const argv, price_t *const price, wattage_t *const wattage, interval_t *const interval);
|
||||||
|
|
||||||
inline interval_t interval_to_seconds(char *interval);
|
inline interval_t interval_to_seconds(const char * const interval);
|
||||||
inline price_t to_wattspersecond(price_t price);
|
inline price_t to_wattspersecond(const price_t price);
|
||||||
|
|
||||||
inline void print_version();
|
inline void print_version();
|
||||||
inline void print_usage();
|
inline void print_usage();
|
||||||
|
Loading…
Reference in New Issue
Block a user