Add version and options to check for it
This commit is contained in:
parent
b9822af312
commit
9baa4b2881
21
src/addtax.c
21
src/addtax.c
@ -3,10 +3,12 @@
|
|||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
#define _(STRING) gettext(STRING)
|
#define _(STRING) gettext(STRING)
|
||||||
#define TAX 1.111111111
|
#define TAX 1.111111111
|
||||||
|
#define VERSION "1.0.0"
|
||||||
|
|
||||||
GtkLabel *calculated_value = NULL;
|
GtkLabel *calculated_value = NULL;
|
||||||
|
|
||||||
@ -27,25 +29,34 @@ void calculate_tax(GtkWidget *entry) {
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
float money;
|
float money;
|
||||||
|
int long_index = 0;
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"version", no_argument, 0, 'v'},
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain("addtax", "/usr/share/locale/");
|
bindtextdomain("addtax", "/usr/share/locale/");
|
||||||
textdomain("addtax");
|
textdomain("addtax");
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
while ((opt = getopt(argc, argv, "")) != -1) {
|
// Process options
|
||||||
|
while ((opt = getopt_long(argc, argv,"v", long_options, &long_index)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'v':
|
||||||
|
printf("%s %s\n", argv[0], VERSION);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _("Usage: %s [prices...]\n"), argv[0]);
|
fprintf(stderr, _("Usage: %s [prices...]\n"), argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (opt = 1; opt < argc; opt++) {
|
// Process arguments that are not options
|
||||||
money = atof(argv[opt]);
|
while (optind < argc) {
|
||||||
if (is_float(argv[opt], money)) {
|
money = atof(argv[optind]);
|
||||||
|
if (is_float(argv[optind++], money)) {
|
||||||
printf("$%d * %f = ", (int) round(money), TAX);
|
printf("$%d * %f = ", (int) round(money), TAX);
|
||||||
money = money * TAX;
|
money = money * TAX;
|
||||||
printf("$%d\n", (int) round(money));
|
printf("$%d\n", (int) round(money));
|
||||||
|
Loading…
Reference in New Issue
Block a user