summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/knob/format.c52
-rw-r--r--src/user/mdemo/main.c42
2 files changed, 74 insertions, 20 deletions
diff --git a/src/user/knob/format.c b/src/user/knob/format.c
index c5d2447..cdc1687 100644
--- a/src/user/knob/format.c
+++ b/src/user/knob/format.c
@@ -42,8 +42,8 @@ struct format_spec {
CHAR,
STRING,
UNSIGNED_DECIMAL,
- HEXADECIMAL
- //TODO: signed decimal
+ HEXADECIMAL,
+ SIGNED_DECIMAL
} kind;
};
@@ -73,6 +73,9 @@ static const char *get_format(const char *from, struct format_spec *format_out)
case 'x':
format_out->kind = HEXADECIMAL;
break;
+ case 'd':
+ format_out->kind = SIGNED_DECIMAL;
+ break;
default:
format_out->kind = UNKNOWN;
break;
@@ -81,7 +84,17 @@ static const char *get_format(const char *from, struct format_spec *format_out)
return from + 1;
}
-//char debug[] = "-- format_v: fmt = \" \"...";
+static uint8_t get_digits(uint32_t k) {
+ if (k >= 1000000000)
+ return 10;
+ uint8_t r = 1;
+ uint32_t n = 10;
+ while (k >= n) {
+ ++r;
+ n *= 10;
+ }
+ return r;
+}
//allocates new memory
char *format_v(const char *fmt, va_list args) {
@@ -92,11 +105,6 @@ char *format_v(const char *fmt, va_list args) {
buf_i = buf;
while (*fmt) {
- //debug[20] = *fmt;
- //debug[21] = fmt[1];
- //debug[22] = fmt[2];
- //_system_log(debug);
-
if (*fmt != '%') {
ensure(1);
*(buf_i++) = *(fmt++);
@@ -137,20 +145,24 @@ char *format_v(const char *fmt, va_list args) {
continue;
uint32_t k;
- case UNSIGNED_DECIMAL:
+ case SIGNED_DECIMAL:
k = va_arg(args, uint32_t);
- if (!form.len) {
- if (k >= 1000000000)
- form.len = 10;
- else {
- uint32_t n = 10;
- ++form.len;
- while (k >= n) {
- ++form.len;
- n *= 10;
- }
- }
+ bool is_neg = k & 0x80000000;
+ if (is_neg) {
+ ensure(1);
+ *(buf_i++) = '-';
+ k = -k;
}
+ if (!form.len)
+ form.len = get_digits(k);
+ else if (is_neg)
+ --form.len;
+ goto print_dec;
+ case UNSIGNED_DECIMAL:
+ k = va_arg(args, uint32_t);
+ if (!form.len)
+ form.len = get_digits(k);
+ print_dec:
ensure(form.len);
const uint32_t len_backup = form.len;
while (form.len--) {
diff --git a/src/user/mdemo/main.c b/src/user/mdemo/main.c
new file mode 100644
index 0000000..fc7de80
--- /dev/null
+++ b/src/user/mdemo/main.c
@@ -0,0 +1,42 @@
+#include <pland/syscall.h>
+#include <popups/info.h>
+
+#define TEXT_COLOR ((_pixel_t){.r = 0x00, .g = 0x00, .b = 0x00})
+#define BG_COLOR ((_pixel_t){.r = 0xbf, .g = 0xbf, .b = 0xbf})
+
+static const char *const mb_names[] = {
+ "left", "right", "middle"
+};
+
+void main() {
+ struct popup main_win;
+ info_popup(&main_win, "Click me!", TEXT_COLOR, BG_COLOR);
+
+ while (1) {
+ struct window_action winact;
+ _get_win_action(main_win.handle, &winact);
+
+ switch (winact.action_type) {
+ struct popup modal;
+ case NOT_READY:
+ _wait_for_action();
+ _yield_task();
+ continue;
+
+ case KEY_DOWN:
+ return;
+
+ case MOUSE_DOWN:
+ info_popupf(&modal,
+ "Got %s click at (%d, %d)!",
+ TEXT_COLOR, BG_COLOR,
+ mb_names[winact.as_mouse.which],
+ winact.as_mouse.x, winact.as_mouse.y);
+ make_modal(&modal);
+ continue;
+
+ default:
+ continue;
+ }
+ }
+} \ No newline at end of file