1
0
Fork 0

Compare commits

...

6 Commits

Author SHA1 Message Date
Alexander Andreev aa6b0cd453
Version updated to 1.1.0.
Now, instead of git repo cloning, release archive is being used.
And let's remove that sentence from README.
2022-10-07 03:56:15 +04:00
Alexander Andreev cfa5c344cd
Added year 2022 to copyright.
Changed usage a little.
2022-10-07 03:51:52 +04:00
Alexander Andreev 7eecfbee01
Removed unnecessary (double) casting of interval_to_seconds result to interval_t. 2022-10-07 03:50:57 +04:00
Alexander Andreev d398de1f8f
to_wattspersecond() changed to price_to_wattspersecond(). 2022-10-07 03:49:56 +04:00
Alexander Andreev d7501eb2a9
Changed formatting for parse_arguments(). 2022-10-07 03:48:34 +04:00
Alexander Andreev 4e69cde16d
Weird int const chenged to const int in main(). 2022-10-07 03:46:56 +04:00
4 changed files with 23 additions and 22 deletions

View File

@ -1,6 +1,6 @@
# Maintainer: Alexander "Arav" Andreev <me@arav.top> # Maintainer: Alexander "Arav" Andreev <me@arav.top>
pkgname=kwh-cost-git pkgname=kwh-cost
pkgver=1.0.0 pkgver=1.1.0
pkgrel=1 pkgrel=1
pkgdesc="Calculates cost of electricity." pkgdesc="Calculates cost of electricity."
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64') arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
@ -10,7 +10,7 @@ makedepends=('git' 'gcc')
provides=('kwh-cost') provides=('kwh-cost')
conflicts=('kwh-cost') conflicts=('kwh-cost')
options=('strip') options=('strip')
source=('kwh-cost-git::git+https://git.arav.top/Arav/kwh-cost.git') source=('https://git.arav.top/Arav/kwh-cost/archive/1.1.0.tar.gz')
md5sums=('SKIP') md5sums=('SKIP')
build() { build() {

View File

@ -23,8 +23,6 @@ $ kwh-cost 4.02 120 30d 2h
Will give 348.29. Will give 348.29.
P.S.: Yeah, I pay 3.83 rubles per kWh. Which is just $0.05. :)
## Installation ## Installation
### Manually ### Manually

View File

@ -4,7 +4,7 @@
#include "main.h" #include "main.h"
int main(int const argc, const char * const * const argv) { int main(const int 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,8 @@ int main(int const argc, const char * const * const argv) {
return 0; return 0;
} }
int parse_arguments(const int argc, const char *const *const argv, price_t *const price, wattage_t *const wattage, interval_t *const 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)
@ -35,13 +36,13 @@ int parse_arguments(const int argc, const char *const *const argv, price_t *cons
} else if (argc < 4) { } else if (argc < 4) {
return 1; return 1;
} else if (pos == 0) { } else if (pos == 0) {
*price = to_wattspersecond((price_t)atof(argv[i])); *price = price_to_wattspersecond((price_t)atof(argv[i]));
++pos; ++pos;
} else if (pos == 1) { } else if (pos == 1) {
*wattage = (wattage_t)atof(argv[2]); *wattage = (wattage_t)atof(argv[2]);
++pos; ++pos;
} else } else
*interval += (interval_t)interval_to_seconds(argv[i]); *interval += interval_to_seconds(argv[i]);
return 0; return 0;
} }
@ -64,26 +65,27 @@ inline interval_t interval_to_seconds(const char * const interval) {
} }
} }
inline price_t to_wattspersecond(const price_t price) { inline price_t price_to_wattspersecond(const price_t price) {
return price / 1000.f / 3600.f; return price / 1000.f / 3600.f;
} }
inline void print_version() { inline void print_version() {
puts("kwh-cost Ver. " VERSION "\n" puts("kwh-cost Ver. " VERSION "\n"
"Copyright (C) 2021 Alexander \"Arav\" Andreev <me@arav.top>. All rights reserved.\n" "Copyright (C) 2021,2022 Alexander \"Arav\" Andreev <me@arav.top>. All rights reserved.\n"
"You can see a license for this program in /usr/share/licenses/kwh-cost/LICENSE."); "You can see a license for this program in /usr/share/licenses/kwh-cost/LICENSE.");
} }
inline void print_usage() { inline void print_usage() {
puts("Usage: kwh-cost [OPTIONS] price wattage interval [interval ...]\n" puts("Usage: kwh-cost [OPTIONS] price wattage interval [interval ...]\n"
"Options:\n" "Options:\n"
" --help, -h Display this usage information.\n" " --help, -h display this usage information.\n"
" --version, -v Display program version.\n" " --version, -v display program version.\n"
"Arguments:\n" "Arguments:\n"
" price Price per kWh.\n" " price price per kWh.\n"
" wattage Specify power usage in Watts.\n" " wattage power usage in Watts.\n"
" interval Time interval in seconds total cost to be calculated for.\n" " interval time interval in seconds during which\n"
" You may specify other time units such as:\n" " this much power to be constantly used.\n"
" m'inute, h'our, d'ay. Example: 5d 3h.\n" " You may specify other time units such as:\n"
" All given intervals will be summed up."); " m'inute, h'our, d'ay. Example: 5d 3h.\n"
" All given intervals will be summed up.");
} }

View File

@ -1,16 +1,17 @@
#ifndef _MAIN_H_ #ifndef _MAIN_H_
#define _MAIN_H_ #define _MAIN_H_
#define VERSION "1.0.0" #define VERSION "1.1.0"
typedef long double price_t; 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(const int argc, const char *const *const argv, price_t *const price, wattage_t *const wattage, interval_t *const 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(const char * const interval); inline interval_t interval_to_seconds(const char * const interval);
inline price_t to_wattspersecond(const price_t price); inline price_t price_to_wattspersecond(const price_t price);
inline void print_version(); inline void print_version();
inline void print_usage(); inline void print_usage();