Index: uspace/app/calculator/calculator.c
===================================================================
--- uspace/app/calculator/calculator.c	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
+++ uspace/app/calculator/calculator.c	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
@@ -0,0 +1,734 @@
+/*
+ * Copyright (c) 2020 Jiri Svoboda
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup calculator
+ * @{
+ */
+/** @file
+ *
+ * Inspired by the code released at https://github.com/osgroup/HelenOSProject
+ *
+ */
+
+#include <ctype.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <str.h>
+#include <ui/label.h>
+#include <ui/fixed.h>
+#include <ui/pbutton.h>
+#include <ui/ui.h>
+#include <ui/window.h>
+
+#define NAME  "calculator"
+
+#define NULL_DISPLAY  "0"
+
+#define SYNTAX_ERROR_DISPLAY   "Syntax error"
+#define NUMERIC_ERROR_DISPLAY  "Numerical error"
+#define UNKNOWN_ERROR_DISPLAY  "Unknown error"
+
+#define EXPR_MAX_LEN 22
+
+typedef enum {
+	STATE_INITIAL = 0,
+	STATE_FINISH,
+	STATE_ERROR,
+	STATE_DIGIT,
+	STATE_VALUE
+} parser_state_t;
+
+typedef enum {
+	ERROR_SYNTAX = 0,
+	ERROR_NUMERIC
+} error_type_t;
+
+typedef enum {
+	OPERATOR_NONE = 0,
+	OPERATOR_ADD,
+	OPERATOR_SUB,
+	OPERATOR_MUL,
+	OPERATOR_DIV
+} operator_t;
+
+typedef enum {
+	ITEM_VALUE = 0,
+	ITEM_OPERATOR
+} stack_item_type_t;
+
+typedef struct {
+	link_t link;
+
+	stack_item_type_t type;
+	union {
+		int64_t value;
+		operator_t operator;
+	} data;
+} stack_item_t;
+
+typedef struct {
+	ui_t *ui;
+} calc_t;
+
+static void calc_pb_clicked(ui_pbutton_t *, void *);
+static void calc_eval_clicked(ui_pbutton_t *, void *);
+static void calc_clear_clicked(ui_pbutton_t *, void *);
+
+static ui_pbutton_cb_t calc_pbutton_cb = {
+	.clicked = calc_pb_clicked
+};
+
+static ui_pbutton_cb_t calc_clear_cb = {
+	.clicked = calc_clear_clicked
+};
+
+static ui_pbutton_cb_t calc_eval_cb = {
+	.clicked = calc_eval_clicked
+};
+
+static void wnd_close(ui_window_t *, void *);
+
+static ui_window_cb_t window_cb = {
+	.close = wnd_close
+};
+
+/** Window close button was clicked.
+ *
+ * @param window Window
+ * @param arg Argument (calc_t *)
+ */
+static void wnd_close(ui_window_t *window, void *arg)
+{
+	calc_t *calc = (calc_t *) arg;
+
+	ui_quit(calc->ui);
+}
+
+static char *expr = NULL;
+static ui_label_t *display;
+
+static bool is_digit(char c)
+{
+	return ((c >= '0') && (c <= '9'));
+}
+
+static int get_digit(char c)
+{
+	assert(is_digit(c));
+
+	return (c - '0');
+}
+
+static bool is_plus(char c)
+{
+	return (c == '+');
+}
+
+static bool is_minus(char c)
+{
+	return (c == '-');
+}
+
+static bool is_finish(char c)
+{
+	return (c == 0);
+}
+
+static operator_t get_operator(char c)
+{
+	switch (c) {
+	case '+':
+		return OPERATOR_ADD;
+	case '-':
+		return OPERATOR_SUB;
+	case '*':
+		return OPERATOR_MUL;
+	case '/':
+		return OPERATOR_DIV;
+	default:
+		return OPERATOR_NONE;
+	}
+}
+
+static bool is_operator(char c)
+{
+	return (get_operator(c) != OPERATOR_NONE);
+}
+
+static bool stack_push_value(list_t *stack, int64_t value, bool value_neg)
+{
+	stack_item_t *item = malloc(sizeof(stack_item_t));
+	if (!item)
+		return false;
+
+	link_initialize(&item->link);
+	item->type = ITEM_VALUE;
+
+	if (value_neg)
+		item->data.value = -value;
+	else
+		item->data.value = value;
+
+	list_prepend(&item->link, stack);
+
+	return true;
+}
+
+static bool stack_push_operator(list_t *stack, operator_t operator)
+{
+	stack_item_t *item = malloc(sizeof(stack_item_t));
+	if (!item)
+		return false;
+
+	link_initialize(&item->link);
+	item->type = ITEM_OPERATOR;
+	item->data.operator = operator;
+	list_prepend(&item->link, stack);
+
+	return true;
+}
+
+static bool stack_pop_value(list_t *stack, int64_t *value)
+{
+	link_t *link = list_first(stack);
+	if (!link)
+		return false;
+
+	stack_item_t *item = list_get_instance(link, stack_item_t, link);
+	if (item->type != ITEM_VALUE)
+		return false;
+
+	*value = item->data.value;
+
+	list_remove(link);
+	free(item);
+
+	return true;
+}
+
+static bool stack_pop_operator(list_t *stack, operator_t *operator)
+{
+	link_t *link = list_first(stack);
+	if (!link)
+		return false;
+
+	stack_item_t *item = list_get_instance(link, stack_item_t, link);
+	if (item->type != ITEM_OPERATOR)
+		return false;
+
+	*operator = item->data.operator;
+
+	list_remove(link);
+	free(item);
+
+	return true;
+}
+
+static void stack_cleanup(list_t *stack)
+{
+	while (!list_empty(stack)) {
+		link_t *link = list_first(stack);
+		if (link) {
+			stack_item_t *item = list_get_instance(link, stack_item_t,
+			    link);
+
+			list_remove(link);
+			free(item);
+		}
+	}
+}
+
+static bool compute(int64_t a, operator_t operator, int64_t b, int64_t *value)
+{
+	switch (operator) {
+	case OPERATOR_ADD:
+		*value = a + b;
+		break;
+	case OPERATOR_SUB:
+		*value = a - b;
+		break;
+	case OPERATOR_MUL:
+		*value = a * b;
+		break;
+	case OPERATOR_DIV:
+		if (b == 0)
+			return false;
+
+		*value = a / b;
+		break;
+	default:
+		return false;
+	}
+
+	return true;
+}
+
+static unsigned int get_priority(operator_t operator)
+{
+	switch (operator) {
+	case OPERATOR_ADD:
+		return 0;
+	case OPERATOR_SUB:
+		return 0;
+	case OPERATOR_MUL:
+		return 1;
+	case OPERATOR_DIV:
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+static void evaluate(list_t *stack, int64_t *value, parser_state_t *state,
+    error_type_t *error_type)
+{
+	while (!list_empty(stack)) {
+		if (!stack_pop_value(stack, value)) {
+			*state = STATE_ERROR;
+			*error_type = ERROR_SYNTAX;
+			break;
+		}
+
+		if (!list_empty(stack)) {
+			operator_t operator;
+			if (!stack_pop_operator(stack, &operator)) {
+				*state = STATE_ERROR;
+				*error_type = ERROR_SYNTAX;
+				break;
+			}
+
+			int64_t value_a;
+			if (!stack_pop_value(stack, &value_a)) {
+				*state = STATE_ERROR;
+				*error_type = ERROR_SYNTAX;
+				break;
+			}
+
+			if (!compute(value_a, operator, *value, value)) {
+				*state = STATE_ERROR;
+				*error_type = ERROR_NUMERIC;
+				break;
+			}
+
+			if (!stack_push_value(stack, *value, false)) {
+				*state = STATE_ERROR;
+				*error_type = ERROR_SYNTAX;
+				break;
+			}
+		}
+	}
+}
+
+static void display_update(void)
+{
+	if (expr != NULL)
+		(void) ui_label_set_text(display, (void *) expr);
+	else
+		(void) ui_label_set_text(display, (void *) NULL_DISPLAY);
+
+	ui_label_paint(display);
+}
+
+static void display_error(error_type_t error_type)
+{
+	if (expr != NULL) {
+		free(expr);
+		expr = NULL;
+	}
+
+	switch (error_type) {
+	case ERROR_SYNTAX:
+		(void) ui_label_set_text(display,
+		    (void *) SYNTAX_ERROR_DISPLAY);
+		break;
+	case ERROR_NUMERIC:
+		(void) ui_label_set_text(display,
+		    (void *) NUMERIC_ERROR_DISPLAY);
+		break;
+	default:
+		(void) ui_label_set_text(display,
+		    (void *) UNKNOWN_ERROR_DISPLAY);
+		break;
+	}
+
+	ui_label_paint(display);
+}
+
+static void calc_pb_clicked(ui_pbutton_t *pbutton, void *arg)
+{
+	const char *subexpr = (const char *) arg;
+
+	if (expr != NULL) {
+		char *new_expr;
+
+		if (str_length(expr) < EXPR_MAX_LEN) {
+			asprintf(&new_expr, "%s%s", expr, subexpr);
+			free(expr);
+			expr = new_expr;
+		}
+	} else {
+		expr = str_dup(subexpr);
+	}
+
+	display_update();
+}
+
+static void calc_clear_clicked(ui_pbutton_t *pbutton, void *arg)
+{
+	if (expr != NULL) {
+		free(expr);
+		expr = NULL;
+	}
+
+	display_update();
+}
+
+static void calc_eval_clicked(ui_pbutton_t *pbutton, void *arg)
+{
+	if (expr == NULL)
+		return;
+
+	list_t stack;
+	list_initialize(&stack);
+
+	error_type_t error_type = ERROR_SYNTAX;
+	size_t i = 0;
+	parser_state_t state = STATE_INITIAL;
+	int64_t value = 0;
+	bool value_neg = false;
+	operator_t last_operator = OPERATOR_NONE;
+
+	while ((state != STATE_FINISH) && (state != STATE_ERROR)) {
+		switch (state) {
+		case STATE_INITIAL:
+			if (is_digit(expr[i])) {
+				value = get_digit(expr[i]);
+				i++;
+				state = STATE_VALUE;
+			} else if (is_plus(expr[i])) {
+				i++;
+				value_neg = false;
+				state = STATE_DIGIT;
+			} else if (is_minus(expr[i])) {
+				i++;
+				value_neg = true;
+				state = STATE_DIGIT;
+			} else
+				state = STATE_ERROR;
+			break;
+
+		case STATE_DIGIT:
+			if (is_digit(expr[i])) {
+				value = get_digit(expr[i]);
+				i++;
+				state = STATE_VALUE;
+			} else
+				state = STATE_ERROR;
+			break;
+
+		case STATE_VALUE:
+			if (is_digit(expr[i])) {
+				value *= 10;
+				value += get_digit(expr[i]);
+				i++;
+			} else if (is_operator(expr[i])) {
+				if (!stack_push_value(&stack, value, value_neg)) {
+					state = STATE_ERROR;
+					break;
+				}
+
+				value = 0;
+				value_neg = false;
+
+				operator_t operator = get_operator(expr[i]);
+
+				if (get_priority(operator) <= get_priority(last_operator)) {
+					evaluate(&stack, &value, &state, &error_type);
+					if (state == STATE_ERROR)
+						break;
+
+					if (!stack_push_value(&stack, value, value_neg)) {
+						state = STATE_ERROR;
+						break;
+					}
+				}
+
+				if (!stack_push_operator(&stack, operator)) {
+					state = STATE_ERROR;
+					break;
+				}
+
+				last_operator = operator;
+				i++;
+				state = STATE_DIGIT;
+			} else if (is_finish(expr[i])) {
+				if (!stack_push_value(&stack, value, value_neg)) {
+					state = STATE_ERROR;
+					break;
+				}
+
+				state = STATE_FINISH;
+			} else
+				state = STATE_ERROR;
+			break;
+
+		default:
+			state = STATE_ERROR;
+		}
+	}
+
+	evaluate(&stack, &value, &state, &error_type);
+	stack_cleanup(&stack);
+
+	if (state == STATE_ERROR) {
+		display_error(error_type);
+		return;
+	}
+
+	free(expr);
+	asprintf(&expr, "%" PRId64, value);
+	display_update();
+}
+
+static errno_t calc_button_create(ui_resource_t *ui_res, ui_fixed_t *fixed,
+    int x, int y, const char *text, ui_pbutton_cb_t *cb, void *arg,
+    ui_pbutton_t **rbutton)
+{
+	ui_pbutton_t *pb;
+	gfx_rect_t rect;
+	errno_t rc;
+
+	rc = ui_pbutton_create(ui_res, text, &pb);
+	if (rc != EOK) {
+		printf("Error creating button.\n");
+		return rc;
+	}
+
+	ui_pbutton_set_cb(pb, cb, arg);
+
+	rect.p0.x = 10 + 60 * x;
+	rect.p0.y = 90 + 45 * y;
+	rect.p1.x = 60 + 60 * x;
+	rect.p1.y = 125 + 45 * y;
+	ui_pbutton_set_rect(pb, &rect);
+
+	rc = ui_fixed_add(fixed, ui_pbutton_ctl(pb));
+	if (rc != EOK) {
+		printf("Error adding control to layout.\n");
+		return rc;
+	}
+
+	if (rbutton != NULL)
+		*rbutton = pb;
+	return EOK;
+}
+
+static void print_syntax(void)
+{
+	printf("Syntax: %s [-d <display-spec>]\n", NAME);
+}
+
+int main(int argc, char *argv[])
+{
+	const char *display_spec = UI_DISPLAY_DEFAULT;
+	ui_t *ui;
+	ui_resource_t *ui_res;
+	ui_fixed_t *fixed;
+	ui_wnd_params_t params;
+	ui_window_t *window;
+	ui_pbutton_t *pb_eval;
+	gfx_rect_t rect;
+	calc_t calc;
+	errno_t rc;
+	int i;
+
+	i = 1;
+	while (i < argc) {
+		if (str_cmp(argv[i], "-d") == 0) {
+			++i;
+			if (i >= argc) {
+				printf("Argument missing.\n");
+				print_syntax();
+				return 1;
+			}
+
+			display_spec = argv[i++];
+		} else {
+			printf("Invalid option '%s'.\n", argv[i]);
+			print_syntax();
+			return 1;
+		}
+	}
+
+	rc = ui_create(display_spec, &ui);
+	if (rc != EOK) {
+		printf("Error creating UI on display %s.\n", display_spec);
+		return rc;
+	}
+
+	ui_wnd_params_init(&params);
+	params.caption = "Calculator";
+	params.rect.p0.x = 0;
+	params.rect.p0.y = 0;
+	params.rect.p1.x = 250;
+	params.rect.p1.y = 270;
+
+	rc = ui_window_create(ui, &params, &window);
+	if (rc != EOK) {
+		printf("Error creating window.\n");
+		return rc;
+	}
+
+	ui_window_set_cb(window, &window_cb, (void *) &calc);
+	calc.ui = ui;
+
+	ui_res = ui_window_get_res(window);
+
+	rc = ui_fixed_create(&fixed);
+	if (rc != EOK) {
+		printf("Error creating fixed layout.\n");
+		return rc;
+	}
+
+	rc = ui_label_create(ui_res, NULL_DISPLAY, &display);
+	if (rc != EOK) {
+		printf("Error creating label.\n");
+		return rc;
+	}
+
+	rect.p0.x = 15;
+	rect.p0.y = 50;
+	rect.p1.x = 235;
+	rect.p1.y = 70;
+	ui_label_set_rect(display, &rect);
+	ui_label_set_halign(display, gfx_halign_right);
+
+	rc = ui_fixed_add(fixed, ui_label_ctl(display));
+	if (rc != EOK) {
+		printf("Error adding control to layout.\n");
+		return rc;
+	}
+
+	rc = calc_button_create(ui_res, fixed, 0, 0, "7", &calc_pbutton_cb,
+	    (void *) "7", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 1, 0, "8", &calc_pbutton_cb,
+	    (void *) "8", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 2, 0, "9", &calc_pbutton_cb,
+	    (void *) "9", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 3, 0, "/", &calc_pbutton_cb,
+	    (void *) "/", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 0, 1, "4", &calc_pbutton_cb,
+	    (void *) "4", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 1, 1, "5", &calc_pbutton_cb,
+	    (void *) "5", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 2, 1, "6", &calc_pbutton_cb,
+	    (void *) "6", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 3, 1, "*", &calc_pbutton_cb,
+	    (void *) "*", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 0, 2, "1", &calc_pbutton_cb,
+	    (void *) "1", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 1, 2, "2", &calc_pbutton_cb,
+	    (void *) "2", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 2, 2, "3", &calc_pbutton_cb,
+	    (void *) "3", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 3, 2, "-", &calc_pbutton_cb,
+	    (void *) "-", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 0, 3, "0", &calc_pbutton_cb,
+	    (void *) "0", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 1, 3, "C", &calc_clear_cb,
+	    (void *) "C", NULL);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 2, 3, "=", &calc_eval_cb,
+	    (void *) "=", &pb_eval);
+	if (rc != EOK)
+		return rc;
+
+	rc = calc_button_create(ui_res, fixed, 3, 3, "+", &calc_pbutton_cb,
+	    (void *) "+", NULL);
+	if (rc != EOK)
+		return rc;
+
+	ui_pbutton_set_default(pb_eval, true);
+
+	ui_window_add(window, ui_fixed_ctl(fixed));
+
+	rc = ui_window_paint(window);
+	if (rc != EOK) {
+		printf("Error painting window.\n");
+		return rc;
+	}
+
+	ui_run(ui);
+	ui_window_destroy(window);
+	ui_destroy(ui);
+
+	return 0;
+}
Index: uspace/app/calculator/doc/doxygroups.h
===================================================================
--- uspace/app/calculator/doc/doxygroups.h	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
+++ uspace/app/calculator/doc/doxygroups.h	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
@@ -0,0 +1,4 @@
+/** @addtogroup calculator calculator
+ * @brief Calculator
+ * @ingroup apps
+ */
Index: uspace/app/calculator/meson.build
===================================================================
--- uspace/app/calculator/meson.build	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
+++ uspace/app/calculator/meson.build	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
@@ -0,0 +1,30 @@
+#
+# Copyright (c) 2020 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+deps = [ 'ui' ]
+src = files('calculator.c')
Index: uspace/app/launcher/launcher.c
===================================================================
--- uspace/app/launcher/launcher.c	(revision b41564c7b4110ad3685cc29e7fe8fc5e76cf1571)
+++ uspace/app/launcher/launcher.c	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
@@ -101,5 +101,5 @@
 		app_launch("/app/terminal");
 	} else if (pbutton == launcher->pb2) {
-		app_launch("/app/vcalc");
+		app_launch("/app/calculator");
 	} else if (pbutton == launcher->pb3) {
 		app_launch("/app/uidemo");
Index: uspace/app/meson.build
===================================================================
--- uspace/app/meson.build	(revision b41564c7b4110ad3685cc29e7fe8fc5e76cf1571)
+++ uspace/app/meson.build	(revision 6dca10f8c152110e0eef31e9daaf728c22ab6700)
@@ -32,4 +32,5 @@
 	'bithenge',
 	'blkdump',
+	'calculator',
 	'contacts',
 	'corecfg',
@@ -90,5 +91,4 @@
 	'untar',
 	'usbinfo',
-	'vcalc',
 	'vdemo',
 	'viewer',
Index: pace/app/vcalc/doc/doxygroups.h
===================================================================
--- uspace/app/vcalc/doc/doxygroups.h	(revision b41564c7b4110ad3685cc29e7fe8fc5e76cf1571)
+++ 	(revision )
@@ -1,4 +1,0 @@
-/** @addtogroup vcalc vcalc
- * @brief Calculator
- * @ingroup apps
- */
Index: pace/app/vcalc/meson.build
===================================================================
--- uspace/app/vcalc/meson.build	(revision b41564c7b4110ad3685cc29e7fe8fc5e76cf1571)
+++ 	(revision )
@@ -1,30 +1,0 @@
-#
-# Copyright (c) 2012 Petr Koupy
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-deps = [ 'ui' ]
-src = files('vcalc.c')
Index: pace/app/vcalc/vcalc.c
===================================================================
--- uspace/app/vcalc/vcalc.c	(revision b41564c7b4110ad3685cc29e7fe8fc5e76cf1571)
+++ 	(revision )
@@ -1,734 +1,0 @@
-/*
- * Copyright (c) 2020 Jiri Svoboda
- * Copyright (c) 2016 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup vcalc
- * @{
- */
-/** @file
- *
- * Inspired by the code released at https://github.com/osgroup/HelenOSProject
- *
- */
-
-#include <ctype.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <str.h>
-#include <ui/label.h>
-#include <ui/fixed.h>
-#include <ui/pbutton.h>
-#include <ui/ui.h>
-#include <ui/window.h>
-
-#define NAME  "vcalc"
-
-#define NULL_DISPLAY  "0"
-
-#define SYNTAX_ERROR_DISPLAY   "Syntax error"
-#define NUMERIC_ERROR_DISPLAY  "Numerical error"
-#define UNKNOWN_ERROR_DISPLAY  "Unknown error"
-
-#define EXPR_MAX_LEN 22
-
-typedef enum {
-	STATE_INITIAL = 0,
-	STATE_FINISH,
-	STATE_ERROR,
-	STATE_DIGIT,
-	STATE_VALUE
-} parser_state_t;
-
-typedef enum {
-	ERROR_SYNTAX = 0,
-	ERROR_NUMERIC
-} error_type_t;
-
-typedef enum {
-	OPERATOR_NONE = 0,
-	OPERATOR_ADD,
-	OPERATOR_SUB,
-	OPERATOR_MUL,
-	OPERATOR_DIV
-} operator_t;
-
-typedef enum {
-	ITEM_VALUE = 0,
-	ITEM_OPERATOR
-} stack_item_type_t;
-
-typedef struct {
-	link_t link;
-
-	stack_item_type_t type;
-	union {
-		int64_t value;
-		operator_t operator;
-	} data;
-} stack_item_t;
-
-typedef struct {
-	ui_t *ui;
-} calc_t;
-
-static void calc_pb_clicked(ui_pbutton_t *, void *);
-static void calc_eval_clicked(ui_pbutton_t *, void *);
-static void calc_clear_clicked(ui_pbutton_t *, void *);
-
-static ui_pbutton_cb_t calc_pbutton_cb = {
-	.clicked = calc_pb_clicked
-};
-
-static ui_pbutton_cb_t calc_clear_cb = {
-	.clicked = calc_clear_clicked
-};
-
-static ui_pbutton_cb_t calc_eval_cb = {
-	.clicked = calc_eval_clicked
-};
-
-static void wnd_close(ui_window_t *, void *);
-
-static ui_window_cb_t window_cb = {
-	.close = wnd_close
-};
-
-/** Window close button was clicked.
- *
- * @param window Window
- * @param arg Argument (calc_t *)
- */
-static void wnd_close(ui_window_t *window, void *arg)
-{
-	calc_t *calc = (calc_t *) arg;
-
-	ui_quit(calc->ui);
-}
-
-static char *expr = NULL;
-static ui_label_t *display;
-
-static bool is_digit(char c)
-{
-	return ((c >= '0') && (c <= '9'));
-}
-
-static int get_digit(char c)
-{
-	assert(is_digit(c));
-
-	return (c - '0');
-}
-
-static bool is_plus(char c)
-{
-	return (c == '+');
-}
-
-static bool is_minus(char c)
-{
-	return (c == '-');
-}
-
-static bool is_finish(char c)
-{
-	return (c == 0);
-}
-
-static operator_t get_operator(char c)
-{
-	switch (c) {
-	case '+':
-		return OPERATOR_ADD;
-	case '-':
-		return OPERATOR_SUB;
-	case '*':
-		return OPERATOR_MUL;
-	case '/':
-		return OPERATOR_DIV;
-	default:
-		return OPERATOR_NONE;
-	}
-}
-
-static bool is_operator(char c)
-{
-	return (get_operator(c) != OPERATOR_NONE);
-}
-
-static bool stack_push_value(list_t *stack, int64_t value, bool value_neg)
-{
-	stack_item_t *item = malloc(sizeof(stack_item_t));
-	if (!item)
-		return false;
-
-	link_initialize(&item->link);
-	item->type = ITEM_VALUE;
-
-	if (value_neg)
-		item->data.value = -value;
-	else
-		item->data.value = value;
-
-	list_prepend(&item->link, stack);
-
-	return true;
-}
-
-static bool stack_push_operator(list_t *stack, operator_t operator)
-{
-	stack_item_t *item = malloc(sizeof(stack_item_t));
-	if (!item)
-		return false;
-
-	link_initialize(&item->link);
-	item->type = ITEM_OPERATOR;
-	item->data.operator = operator;
-	list_prepend(&item->link, stack);
-
-	return true;
-}
-
-static bool stack_pop_value(list_t *stack, int64_t *value)
-{
-	link_t *link = list_first(stack);
-	if (!link)
-		return false;
-
-	stack_item_t *item = list_get_instance(link, stack_item_t, link);
-	if (item->type != ITEM_VALUE)
-		return false;
-
-	*value = item->data.value;
-
-	list_remove(link);
-	free(item);
-
-	return true;
-}
-
-static bool stack_pop_operator(list_t *stack, operator_t *operator)
-{
-	link_t *link = list_first(stack);
-	if (!link)
-		return false;
-
-	stack_item_t *item = list_get_instance(link, stack_item_t, link);
-	if (item->type != ITEM_OPERATOR)
-		return false;
-
-	*operator = item->data.operator;
-
-	list_remove(link);
-	free(item);
-
-	return true;
-}
-
-static void stack_cleanup(list_t *stack)
-{
-	while (!list_empty(stack)) {
-		link_t *link = list_first(stack);
-		if (link) {
-			stack_item_t *item = list_get_instance(link, stack_item_t,
-			    link);
-
-			list_remove(link);
-			free(item);
-		}
-	}
-}
-
-static bool compute(int64_t a, operator_t operator, int64_t b, int64_t *value)
-{
-	switch (operator) {
-	case OPERATOR_ADD:
-		*value = a + b;
-		break;
-	case OPERATOR_SUB:
-		*value = a - b;
-		break;
-	case OPERATOR_MUL:
-		*value = a * b;
-		break;
-	case OPERATOR_DIV:
-		if (b == 0)
-			return false;
-
-		*value = a / b;
-		break;
-	default:
-		return false;
-	}
-
-	return true;
-}
-
-static unsigned int get_priority(operator_t operator)
-{
-	switch (operator) {
-	case OPERATOR_ADD:
-		return 0;
-	case OPERATOR_SUB:
-		return 0;
-	case OPERATOR_MUL:
-		return 1;
-	case OPERATOR_DIV:
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-static void evaluate(list_t *stack, int64_t *value, parser_state_t *state,
-    error_type_t *error_type)
-{
-	while (!list_empty(stack)) {
-		if (!stack_pop_value(stack, value)) {
-			*state = STATE_ERROR;
-			*error_type = ERROR_SYNTAX;
-			break;
-		}
-
-		if (!list_empty(stack)) {
-			operator_t operator;
-			if (!stack_pop_operator(stack, &operator)) {
-				*state = STATE_ERROR;
-				*error_type = ERROR_SYNTAX;
-				break;
-			}
-
-			int64_t value_a;
-			if (!stack_pop_value(stack, &value_a)) {
-				*state = STATE_ERROR;
-				*error_type = ERROR_SYNTAX;
-				break;
-			}
-
-			if (!compute(value_a, operator, *value, value)) {
-				*state = STATE_ERROR;
-				*error_type = ERROR_NUMERIC;
-				break;
-			}
-
-			if (!stack_push_value(stack, *value, false)) {
-				*state = STATE_ERROR;
-				*error_type = ERROR_SYNTAX;
-				break;
-			}
-		}
-	}
-}
-
-static void display_update(void)
-{
-	if (expr != NULL)
-		(void) ui_label_set_text(display, (void *) expr);
-	else
-		(void) ui_label_set_text(display, (void *) NULL_DISPLAY);
-
-	ui_label_paint(display);
-}
-
-static void display_error(error_type_t error_type)
-{
-	if (expr != NULL) {
-		free(expr);
-		expr = NULL;
-	}
-
-	switch (error_type) {
-	case ERROR_SYNTAX:
-		(void) ui_label_set_text(display,
-		    (void *) SYNTAX_ERROR_DISPLAY);
-		break;
-	case ERROR_NUMERIC:
-		(void) ui_label_set_text(display,
-		    (void *) NUMERIC_ERROR_DISPLAY);
-		break;
-	default:
-		(void) ui_label_set_text(display,
-		    (void *) UNKNOWN_ERROR_DISPLAY);
-		break;
-	}
-
-	ui_label_paint(display);
-}
-
-static void calc_pb_clicked(ui_pbutton_t *pbutton, void *arg)
-{
-	const char *subexpr = (const char *) arg;
-
-	if (expr != NULL) {
-		char *new_expr;
-
-		if (str_length(expr) < EXPR_MAX_LEN) {
-			asprintf(&new_expr, "%s%s", expr, subexpr);
-			free(expr);
-			expr = new_expr;
-		}
-	} else {
-		expr = str_dup(subexpr);
-	}
-
-	display_update();
-}
-
-static void calc_clear_clicked(ui_pbutton_t *pbutton, void *arg)
-{
-	if (expr != NULL) {
-		free(expr);
-		expr = NULL;
-	}
-
-	display_update();
-}
-
-static void calc_eval_clicked(ui_pbutton_t *pbutton, void *arg)
-{
-	if (expr == NULL)
-		return;
-
-	list_t stack;
-	list_initialize(&stack);
-
-	error_type_t error_type = ERROR_SYNTAX;
-	size_t i = 0;
-	parser_state_t state = STATE_INITIAL;
-	int64_t value = 0;
-	bool value_neg = false;
-	operator_t last_operator = OPERATOR_NONE;
-
-	while ((state != STATE_FINISH) && (state != STATE_ERROR)) {
-		switch (state) {
-		case STATE_INITIAL:
-			if (is_digit(expr[i])) {
-				value = get_digit(expr[i]);
-				i++;
-				state = STATE_VALUE;
-			} else if (is_plus(expr[i])) {
-				i++;
-				value_neg = false;
-				state = STATE_DIGIT;
-			} else if (is_minus(expr[i])) {
-				i++;
-				value_neg = true;
-				state = STATE_DIGIT;
-			} else
-				state = STATE_ERROR;
-			break;
-
-		case STATE_DIGIT:
-			if (is_digit(expr[i])) {
-				value = get_digit(expr[i]);
-				i++;
-				state = STATE_VALUE;
-			} else
-				state = STATE_ERROR;
-			break;
-
-		case STATE_VALUE:
-			if (is_digit(expr[i])) {
-				value *= 10;
-				value += get_digit(expr[i]);
-				i++;
-			} else if (is_operator(expr[i])) {
-				if (!stack_push_value(&stack, value, value_neg)) {
-					state = STATE_ERROR;
-					break;
-				}
-
-				value = 0;
-				value_neg = false;
-
-				operator_t operator = get_operator(expr[i]);
-
-				if (get_priority(operator) <= get_priority(last_operator)) {
-					evaluate(&stack, &value, &state, &error_type);
-					if (state == STATE_ERROR)
-						break;
-
-					if (!stack_push_value(&stack, value, value_neg)) {
-						state = STATE_ERROR;
-						break;
-					}
-				}
-
-				if (!stack_push_operator(&stack, operator)) {
-					state = STATE_ERROR;
-					break;
-				}
-
-				last_operator = operator;
-				i++;
-				state = STATE_DIGIT;
-			} else if (is_finish(expr[i])) {
-				if (!stack_push_value(&stack, value, value_neg)) {
-					state = STATE_ERROR;
-					break;
-				}
-
-				state = STATE_FINISH;
-			} else
-				state = STATE_ERROR;
-			break;
-
-		default:
-			state = STATE_ERROR;
-		}
-	}
-
-	evaluate(&stack, &value, &state, &error_type);
-	stack_cleanup(&stack);
-
-	if (state == STATE_ERROR) {
-		display_error(error_type);
-		return;
-	}
-
-	free(expr);
-	asprintf(&expr, "%" PRId64, value);
-	display_update();
-}
-
-static errno_t calc_button_create(ui_resource_t *ui_res, ui_fixed_t *fixed,
-    int x, int y, const char *text, ui_pbutton_cb_t *cb, void *arg,
-    ui_pbutton_t **rbutton)
-{
-	ui_pbutton_t *pb;
-	gfx_rect_t rect;
-	errno_t rc;
-
-	rc = ui_pbutton_create(ui_res, text, &pb);
-	if (rc != EOK) {
-		printf("Error creating button.\n");
-		return rc;
-	}
-
-	ui_pbutton_set_cb(pb, cb, arg);
-
-	rect.p0.x = 10 + 60 * x;
-	rect.p0.y = 90 + 45 * y;
-	rect.p1.x = 60 + 60 * x;
-	rect.p1.y = 125 + 45 * y;
-	ui_pbutton_set_rect(pb, &rect);
-
-	rc = ui_fixed_add(fixed, ui_pbutton_ctl(pb));
-	if (rc != EOK) {
-		printf("Error adding control to layout.\n");
-		return rc;
-	}
-
-	if (rbutton != NULL)
-		*rbutton = pb;
-	return EOK;
-}
-
-static void print_syntax(void)
-{
-	printf("Syntax: %s [-d <display-spec>]\n", NAME);
-}
-
-int main(int argc, char *argv[])
-{
-	const char *display_spec = UI_DISPLAY_DEFAULT;
-	ui_t *ui;
-	ui_resource_t *ui_res;
-	ui_fixed_t *fixed;
-	ui_wnd_params_t params;
-	ui_window_t *window;
-	ui_pbutton_t *pb_eval;
-	gfx_rect_t rect;
-	calc_t calc;
-	errno_t rc;
-	int i;
-
-	i = 1;
-	while (i < argc) {
-		if (str_cmp(argv[i], "-d") == 0) {
-			++i;
-			if (i >= argc) {
-				printf("Argument missing.\n");
-				print_syntax();
-				return 1;
-			}
-
-			display_spec = argv[i++];
-		} else {
-			printf("Invalid option '%s'.\n", argv[i]);
-			print_syntax();
-			return 1;
-		}
-	}
-
-	rc = ui_create(display_spec, &ui);
-	if (rc != EOK) {
-		printf("Error creating UI on display %s.\n", display_spec);
-		return rc;
-	}
-
-	ui_wnd_params_init(&params);
-	params.caption = "Calculator";
-	params.rect.p0.x = 0;
-	params.rect.p0.y = 0;
-	params.rect.p1.x = 250;
-	params.rect.p1.y = 270;
-
-	rc = ui_window_create(ui, &params, &window);
-	if (rc != EOK) {
-		printf("Error creating window.\n");
-		return rc;
-	}
-
-	ui_window_set_cb(window, &window_cb, (void *) &calc);
-	calc.ui = ui;
-
-	ui_res = ui_window_get_res(window);
-
-	rc = ui_fixed_create(&fixed);
-	if (rc != EOK) {
-		printf("Error creating fixed layout.\n");
-		return rc;
-	}
-
-	rc = ui_label_create(ui_res, NULL_DISPLAY, &display);
-	if (rc != EOK) {
-		printf("Error creating label.\n");
-		return rc;
-	}
-
-	rect.p0.x = 15;
-	rect.p0.y = 50;
-	rect.p1.x = 235;
-	rect.p1.y = 70;
-	ui_label_set_rect(display, &rect);
-	ui_label_set_halign(display, gfx_halign_right);
-
-	rc = ui_fixed_add(fixed, ui_label_ctl(display));
-	if (rc != EOK) {
-		printf("Error adding control to layout.\n");
-		return rc;
-	}
-
-	rc = calc_button_create(ui_res, fixed, 0, 0, "7", &calc_pbutton_cb,
-	    (void *) "7", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 1, 0, "8", &calc_pbutton_cb,
-	    (void *) "8", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 2, 0, "9", &calc_pbutton_cb,
-	    (void *) "9", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 3, 0, "/", &calc_pbutton_cb,
-	    (void *) "/", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 0, 1, "4", &calc_pbutton_cb,
-	    (void *) "4", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 1, 1, "5", &calc_pbutton_cb,
-	    (void *) "5", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 2, 1, "6", &calc_pbutton_cb,
-	    (void *) "6", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 3, 1, "*", &calc_pbutton_cb,
-	    (void *) "*", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 0, 2, "1", &calc_pbutton_cb,
-	    (void *) "1", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 1, 2, "2", &calc_pbutton_cb,
-	    (void *) "2", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 2, 2, "3", &calc_pbutton_cb,
-	    (void *) "3", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 3, 2, "-", &calc_pbutton_cb,
-	    (void *) "-", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 0, 3, "0", &calc_pbutton_cb,
-	    (void *) "0", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 1, 3, "C", &calc_clear_cb,
-	    (void *) "C", NULL);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 2, 3, "=", &calc_eval_cb,
-	    (void *) "=", &pb_eval);
-	if (rc != EOK)
-		return rc;
-
-	rc = calc_button_create(ui_res, fixed, 3, 3, "+", &calc_pbutton_cb,
-	    (void *) "+", NULL);
-	if (rc != EOK)
-		return rc;
-
-	ui_pbutton_set_default(pb_eval, true);
-
-	ui_window_add(window, ui_fixed_ctl(fixed));
-
-	rc = ui_window_paint(window);
-	if (rc != EOK) {
-		printf("Error painting window.\n");
-		return rc;
-	}
-
-	ui_run(ui);
-	ui_window_destroy(window);
-	ui_destroy(ui);
-
-	return 0;
-}
