src directory as well as a separate header file is absolutely not necessary. Also fixed a typo price_kwh_to_wattspersecond -> price_kwh_to_wattsecond, because because a price per kilowatt-hour is being converted to watt-second. Also added a notice about a licence that is used.
This commit is contained in:
parent
5fa6142b21
commit
9112fc018c
4
Makefile
4
Makefile
@ -5,13 +5,11 @@ PREFIX:=/usr/local
|
|||||||
|
|
||||||
CFLAGS=--std=c99 -O3 -Wall -Werror -Wextra -pedantic
|
CFLAGS=--std=c99 -O3 -Wall -Werror -Wextra -pedantic
|
||||||
|
|
||||||
SRC_DIR=src
|
|
||||||
|
|
||||||
DESTDIR=/
|
DESTDIR=/
|
||||||
|
|
||||||
.PHONY: clean install uninstall test
|
.PHONY: clean install uninstall test
|
||||||
|
|
||||||
${TARGET}: ${SRC_DIR}/main.c ${SRC_DIR}/main.h
|
${TARGET}: main.c
|
||||||
${CC} ${CFLAGS} ${LDFLAGS} $< -o $@
|
${CC} ${CFLAGS} ${LDFLAGS} $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -2,15 +2,27 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "main.h"
|
#define VERSION "1.1.1"
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
inline interval_t interval_to_seconds(const char *const interval);
|
||||||
|
inline price_t price_kwh_to_wattsecond(const price_t price);
|
||||||
|
|
||||||
|
inline void print_version();
|
||||||
|
inline void print_usage();
|
||||||
|
|
||||||
int main(const int 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;
|
||||||
|
|
||||||
int res = parse_arguments(argc, argv, &price, &wattage, &interval);
|
switch (parse_arguments(argc, argv, &price, &wattage, &interval)) {
|
||||||
switch (res) {
|
|
||||||
case 1: print_usage(); exit(0);
|
case 1: print_usage(); exit(0);
|
||||||
case 2: print_version(); exit(0);
|
case 2: print_version(); exit(0);
|
||||||
case 99: fputs("Unknown flag provided.\n", stderr); print_usage(); exit(1);
|
case 99: fputs("Unknown flag provided.\n", stderr); print_usage(); exit(1);
|
||||||
@ -36,7 +48,7 @@ int parse_arguments(const int argc, const char *const *const argv,
|
|||||||
} else if (argc < 4) {
|
} else if (argc < 4) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (pos == 0) {
|
} else if (pos == 0) {
|
||||||
*price = price_kwh_to_wattspersecond((price_t)atof(argv[i]));
|
*price = price_kwh_to_wattsecond((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]);
|
||||||
@ -65,13 +77,14 @@ inline interval_t interval_to_seconds(const char *const interval) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline price_t price_kwh_to_wattspersecond(const price_t price) {
|
inline price_t price_kwh_to_wattsecond(const price_t price) {
|
||||||
return price / 1000.f / 3600.f;
|
return price / 1000.f / 3600.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void print_version() {
|
inline void print_version() {
|
||||||
fputs("kwh-cost Ver. " VERSION "\n"
|
fputs("kwh-cost Ver. " VERSION "\n"
|
||||||
"Copyright (C) 2021-2023 Alexander \"Arav\" Andreev <me@arav.su>. All rights reserved.\n"
|
"Copyright (C) 2021-2023 Alexander \"Arav\" Andreev <me@arav.su>. All rights reserved.\n"
|
||||||
|
"This program is distributed under the terms of MIT+NIGGER licence.\n"
|
||||||
"You can see a license for this program in /usr/share/licenses/kwh-cost/LICENSE.\n", stderr);
|
"You can see a license for this program in /usr/share/licenses/kwh-cost/LICENSE.\n", stderr);
|
||||||
}
|
}
|
||||||
|
|
19
src/main.h
19
src/main.h
@ -1,19 +0,0 @@
|
|||||||
#ifndef _MAIN_H_
|
|
||||||
#define _MAIN_H_
|
|
||||||
|
|
||||||
#define VERSION "1.1.1"
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
inline interval_t interval_to_seconds(const char *const interval);
|
|
||||||
inline price_t price_kwh_to_wattspersecond(const price_t price);
|
|
||||||
|
|
||||||
inline void print_version();
|
|
||||||
inline void print_usage();
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user