Compare commits

...

5 Commits

Author SHA1 Message Date
Chris Cromer abb230ee22
add test 2018-10-13 13:28:59 -03:00
Chris Cromer 1a21f3a556
fix colon style to match project 2018-09-25 16:39:35 -03:00
Chris Cromer 43ea64918b
add dynamic version to build via meson
remove unused arg in misc
mark arg as unused in addtax
update translations
2018-09-25 16:36:01 -03:00
Chris Cromer 8e5ddc62e7
update translations 2018-09-24 16:18:49 -03:00
Chris Cromer a1225763d6
add check to make sure resource exists 2018-09-24 16:17:47 -03:00
10 changed files with 51 additions and 26 deletions

View File

@ -1,10 +1,16 @@
project('addtax',
'c',
version : '1.0.0',
version : '1.0.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')
subdir('po')
subdir('glade')
subdir('src/include')
subdir('src')

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: addtax\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-09-13 17:11-0300\n"
"POT-Creation-Date: 2018-09-25 16:35-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/addtax.c:51 src/addtax.c:65
#: src/addtax.c:48 src/addtax.c:62
#, c-format
msgid "Usage: %s [prices...]\n"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: addtax\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-09-13 17:11-0300\n"
"POT-Creation-Date: 2018-09-25 16:35-0300\n"
"PO-Revision-Date: 2018-09-13 10:10-0300\n"
"Last-Translator: Chris Cromer <chris@cromer.cl>\n"
"Language-Team: none\n"
@ -18,7 +18,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n"
#: src/addtax.c:51 src/addtax.c:65
#: src/addtax.c:48 src/addtax.c:62
#, c-format
msgid "Usage: %s [prices...]\n"
msgstr "Uso: %s [precios...]\n"

View File

@ -4,11 +4,8 @@
#include <locale.h>
#include <stdbool.h>
#include <getopt.h>
#include "misc.h"
#define _(STRING) gettext(STRING)
#define TAX 1.111111111
#define VERSION "1.0.0"
#include "include/addtax.h"
#include "include/misc.h"
GtkLabel *calculated_value = NULL;
@ -18,7 +15,7 @@ void calculate_tax(GtkWidget *entry) {
const gchar *label_text;
entry_text = (char*) gtk_entry_get_text(GTK_ENTRY(entry));
money = atof(entry_text);
if (is_float(entry_text, money)) {
if (is_float(entry_text)) {
g_print("$%d * %f = ", (int) round(money), TAX);
money = money * TAX;
g_print("$%d\n", (int) round(money));
@ -56,7 +53,7 @@ int main(int argc, char *argv[]) {
// Process arguments that are not options
while (optind < argc) {
money = atof(argv[optind]);
if (is_float(argv[optind++], money)) {
if (is_float(argv[optind++])) {
printf("$%d * %f = ", (int) round(money), TAX);
money = money * TAX;
printf("$%d\n", (int) round(money));
@ -71,11 +68,16 @@ int main(int argc, char *argv[]) {
GtkBuilder *builder;
GtkWidget *window;
GError *error = NULL;
gtk_init(&argc, &argv);
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"));
gtk_builder_connect_signals(builder, NULL);
@ -91,7 +93,7 @@ int main(int argc, char *argv[]) {
}
// 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);
}

3
src/include/addtax.h.in Normal file
View File

@ -0,0 +1,3 @@
#define _(STRING) gettext(STRING)
#define TAX 1.111111111
#define VERSION "@version@"

5
src/include/meson.build Normal file
View 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
View File

@ -0,0 +1 @@
bool is_float(const char *string);

View File

@ -6,18 +6,27 @@ gmodule_dep = dependency('gmodule-export-2.0', version : '>=2.0')
cc = meson.get_compiler('c')
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 += ['misc.c']
sources += ['misc.h']
sources += [main_resource_c]
executable('addtax',
# -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')
addtaxexe = executable('addtax',
sources,
include_directories : inc,
c_args : c_args,
link_args : link_args,
dependencies : [gtk_dep, m_dep, gmodule_dep],
install : true)
test('basic', addtaxexe, args : ['15000', '100000'])

View File

@ -3,13 +3,13 @@
#include <ctype.h>
#include <stdlib.h>
bool is_float(const char *s, float dest) {
if (s == NULL) {
bool is_float(const char *string) {
if (string == NULL) {
return false;
}
char *endptr;
dest = (float) strtod(s, &endptr);
if (s == endptr) {
strtod(string, &endptr);
if (string == endptr) {
return false;
}
while (isspace((unsigned char ) *endptr)) {

View File

@ -1 +0,0 @@
bool is_float(const char *s, float dest);