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>
pkgname=kwh-cost-git
pkgver=1.0.0
pkgname=kwh-cost
pkgver=1.1.0
pkgrel=1
pkgdesc="Calculates cost of electricity."
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
@ -10,7 +10,7 @@ makedepends=('git' 'gcc')
provides=('kwh-cost')
conflicts=('kwh-cost')
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')
build() {

View File

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

View File

@ -4,7 +4,7 @@
#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;
wattage_t wattage;
interval_t interval = 0;
@ -23,7 +23,8 @@ int main(int const argc, const char * const * const argv) {
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;
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) {
return 1;
} else if (pos == 0) {
*price = to_wattspersecond((price_t)atof(argv[i]));
*price = price_to_wattspersecond((price_t)atof(argv[i]));
++pos;
} else if (pos == 1) {
*wattage = (wattage_t)atof(argv[2]);
++pos;
} else
*interval += (interval_t)interval_to_seconds(argv[i]);
*interval += interval_to_seconds(argv[i]);
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;
}
inline void print_version() {
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.");
}
inline void print_usage() {
puts("Usage: kwh-cost [OPTIONS] price wattage interval [interval ...]\n"
"Options:\n"
" --help, -h Display this usage information.\n"
" --version, -v Display program version.\n"
" --help, -h display this usage information.\n"
" --version, -v display program version.\n"
"Arguments:\n"
" price Price per kWh.\n"
" wattage Specify power usage in Watts.\n"
" interval Time interval in seconds total cost to be calculated for.\n"
" You may specify other time units such as:\n"
" m'inute, h'our, d'ay. Example: 5d 3h.\n"
" All given intervals will be summed up.");
" price price per kWh.\n"
" wattage power usage in Watts.\n"
" interval time interval in seconds during which\n"
" this much power to be constantly used.\n"
" You may specify other time units such as:\n"
" 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_
#define _MAIN_H_
#define VERSION "1.0.0"
#define VERSION "1.1.0"
typedef long double price_t;
typedef long double wattage_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 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_usage();