Compare commits
8 Commits
d34bd8f72e
...
1.0.2
Author | SHA1 | Date | |
---|---|---|---|
1a21f3a556
|
|||
43ea64918b
|
|||
8e5ddc62e7
|
|||
a1225763d6
|
|||
23051f4a8c
|
|||
e82ccf5e82
|
|||
9baa4b2881
|
|||
b9822af312
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
build
|
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# addtax
|
||||||
|
This application allows the calculation of a price by adding the 10% taxes for boletas in Chile.
|
10
meson.build
10
meson.build
@@ -1,10 +1,16 @@
|
|||||||
project('addtax',
|
project('addtax',
|
||||||
'c',
|
'c',
|
||||||
version : '1.0.0',
|
version : '1.0.2',
|
||||||
license : 'BSD-3',
|
license : 'BSD-3',
|
||||||
default_options : [ 'b_ofast=if-release', 'b_march_native=if-release', 'b_ndebug=if-release' ]
|
default_options : [ 'b_ofast=if-release',
|
||||||
|
'b_march_native=if-release',
|
||||||
|
'b_ndebug=if-release',
|
||||||
|
'warning_level=3',
|
||||||
|
'c_std=c11'
|
||||||
|
]
|
||||||
)
|
)
|
||||||
add_global_arguments('-DGETTEXT_PACKAGE="addtax"', language: 'c')
|
add_global_arguments('-DGETTEXT_PACKAGE="addtax"', language: 'c')
|
||||||
subdir('po')
|
subdir('po')
|
||||||
subdir('glade')
|
subdir('glade')
|
||||||
|
subdir('src/include')
|
||||||
subdir('src')
|
subdir('src')
|
||||||
|
@@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: addtax\n"
|
"Project-Id-Version: addtax\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-09-13 10:09-0300\n"
|
"POT-Creation-Date: 2018-09-25 16:35-0300\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@@ -17,7 +17,7 @@ msgstr ""
|
|||||||
"Content-Type: text/plain; charset=CHARSET\n"
|
"Content-Type: text/plain; charset=CHARSET\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
#: src/addtax.c:58 src/addtax.c:71
|
#: src/addtax.c:48 src/addtax.c:62
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Usage: %s [prices...]\n"
|
msgid "Usage: %s [prices...]\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
4
po/es.po
4
po/es.po
@@ -7,7 +7,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: addtax\n"
|
"Project-Id-Version: addtax\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-09-13 10:09-0300\n"
|
"POT-Creation-Date: 2018-09-25 16:35-0300\n"
|
||||||
"PO-Revision-Date: 2018-09-13 10:10-0300\n"
|
"PO-Revision-Date: 2018-09-13 10:10-0300\n"
|
||||||
"Last-Translator: Chris Cromer <chris@cromer.cl>\n"
|
"Last-Translator: Chris Cromer <chris@cromer.cl>\n"
|
||||||
"Language-Team: none\n"
|
"Language-Team: none\n"
|
||||||
@@ -18,7 +18,7 @@ msgstr ""
|
|||||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
"X-Generator: Poedit 2.0.6\n"
|
"X-Generator: Poedit 2.0.6\n"
|
||||||
|
|
||||||
#: src/addtax.c:58 src/addtax.c:71
|
#: src/addtax.c:48 src/addtax.c:62
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Usage: %s [prices...]\n"
|
msgid "Usage: %s [prices...]\n"
|
||||||
msgstr "Uso: %s [precios...]\n"
|
msgstr "Uso: %s [precios...]\n"
|
||||||
|
37
src/addtax.c
37
src/addtax.c
@@ -3,10 +3,9 @@
|
|||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "misc.h"
|
#include <getopt.h>
|
||||||
|
#include "include/addtax.h"
|
||||||
#define _(STRING) gettext(STRING)
|
#include "include/misc.h"
|
||||||
#define TAX 1.111111111
|
|
||||||
|
|
||||||
GtkLabel *calculated_value = NULL;
|
GtkLabel *calculated_value = NULL;
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ void calculate_tax(GtkWidget *entry) {
|
|||||||
const gchar *label_text;
|
const gchar *label_text;
|
||||||
entry_text = (char*) gtk_entry_get_text(GTK_ENTRY(entry));
|
entry_text = (char*) gtk_entry_get_text(GTK_ENTRY(entry));
|
||||||
money = atof(entry_text);
|
money = atof(entry_text);
|
||||||
if (is_float(entry_text, money)) {
|
if (is_float(entry_text)) {
|
||||||
g_print("$%d * %f = ", (int) round(money), TAX);
|
g_print("$%d * %f = ", (int) round(money), TAX);
|
||||||
money = money * TAX;
|
money = money * TAX;
|
||||||
g_print("$%d\n", (int) round(money));
|
g_print("$%d\n", (int) round(money));
|
||||||
@@ -27,25 +26,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++])) {
|
||||||
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));
|
||||||
@@ -60,11 +68,16 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
builder = gtk_builder_new();
|
builder = gtk_builder_new();
|
||||||
gtk_builder_add_from_resource(builder, "/cl/cromer/addtax/window_main.glade", NULL);
|
gtk_builder_add_from_resource(builder, "/cl/cromer/addtax/window_main.glade", &error);
|
||||||
|
if (error != NULL) {
|
||||||
|
fprintf(stderr, "Error: %s\n", error->message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
|
window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
|
||||||
gtk_builder_connect_signals(builder, NULL);
|
gtk_builder_connect_signals(builder, NULL);
|
||||||
@@ -80,7 +93,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Called when calculate is clicked
|
// Called when calculate is clicked
|
||||||
void on_button_calculate_clicked(GtkWidget *button, GtkWidget *entry) {
|
void on_button_calculate_clicked(__attribute__((unused)) GtkWidget *button, GtkWidget *entry) {
|
||||||
calculate_tax(entry);
|
calculate_tax(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
src/include/addtax.h.in
Normal file
3
src/include/addtax.h.in
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#define _(STRING) gettext(STRING)
|
||||||
|
#define TAX 1.111111111
|
||||||
|
#define VERSION "@version@"
|
5
src/include/meson.build
Normal file
5
src/include/meson.build
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
conf_data = configuration_data()
|
||||||
|
conf_data.set('version', meson.project_version())
|
||||||
|
configure_file(input : 'addtax.h.in',
|
||||||
|
output : 'addtax.h',
|
||||||
|
configuration : conf_data)
|
1
src/include/misc.h
Normal file
1
src/include/misc.h
Normal file
@@ -0,0 +1 @@
|
|||||||
|
bool is_float(const char *string);
|
@@ -6,17 +6,24 @@ gmodule_dep = dependency('gmodule-export-2.0', version : '>=2.0')
|
|||||||
cc = meson.get_compiler('c')
|
cc = meson.get_compiler('c')
|
||||||
m_dep = cc.find_library('m', required : false)
|
m_dep = cc.find_library('m', required : false)
|
||||||
|
|
||||||
# -no-pie so that the executable is double clickable in gui
|
|
||||||
c_args = ['-no-pie']
|
|
||||||
link_args = ['-no-pie']
|
|
||||||
|
|
||||||
sources = ['addtax.c']
|
sources = ['addtax.c']
|
||||||
sources += ['misc.c']
|
sources += ['misc.c']
|
||||||
sources += ['misc.h']
|
|
||||||
sources += [main_resource_c]
|
sources += [main_resource_c]
|
||||||
|
|
||||||
|
# -no-pie so that the executable is double clickable in gui
|
||||||
|
if cc.get_id() == 'gcc'
|
||||||
|
c_args = ['-no-pie']
|
||||||
|
link_args = ['-no-pie']
|
||||||
|
else
|
||||||
|
c_args = ''
|
||||||
|
link_args = ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
inc = include_directories('include')
|
||||||
|
|
||||||
executable('addtax',
|
executable('addtax',
|
||||||
sources,
|
sources,
|
||||||
|
include_directories : inc,
|
||||||
c_args : c_args,
|
c_args : c_args,
|
||||||
link_args : link_args,
|
link_args : link_args,
|
||||||
dependencies : [gtk_dep, m_dep, gmodule_dep],
|
dependencies : [gtk_dep, m_dep, gmodule_dep],
|
||||||
|
@@ -3,13 +3,13 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
bool is_float(const char *s, float dest) {
|
bool is_float(const char *string) {
|
||||||
if (s == NULL) {
|
if (string == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
char *endptr;
|
char *endptr;
|
||||||
dest = (float) strtod(s, &endptr);
|
strtod(string, &endptr);
|
||||||
if (s == endptr) {
|
if (string == endptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while (isspace((unsigned char ) *endptr)) {
|
while (isspace((unsigned char ) *endptr)) {
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
bool is_float(const char *s, float dest);
|
|
Reference in New Issue
Block a user