]> git.sur5r.net Git - c128-kasse/blobdiff - src/general.c
kasse: use cgetn_input() to simplify logic
[c128-kasse] / src / general.c
index 668bdcf4b9c1765143bfcc0ab5f57829624fb2a9..91318aa9faa51269439ab846bd7f3b1000aa614a 100644 (file)
@@ -10,6 +10,7 @@
 #include <conio.h>
 
 #include "general.h"
+#include "vdc_patch_charset.h"
 
 /*
  * get_input_terminated_by() reads input (handling backspace correctly) until
@@ -65,6 +66,22 @@ char *get_input(void) {
   return output;
 }
 
+BYTE cgetn_input(char *s, BYTE len) {
+  memset(s, '\0', len);
+  get_input_terminated_by(INPUT_TERMINATOR_RETURN, s, len);
+  return strlen(s);
+}
+
+void cget_return() {
+  BYTE c;
+  while (1) {
+    c = cgetc();
+    if (c == PETSCII_CR) {
+      return;
+    }
+  }
+}
+
 char retry_or_quit(void) {
   char *c;
   do {
@@ -75,15 +92,8 @@ char retry_or_quit(void) {
 }
 
 char *format_euro(char *s, int maxlen, int cent) {
-  int tmp = cent;
-  int len = strlen(",EUR");
-  while ((tmp /= 10) > 0)
-    ++len;
-  if (len >= maxlen)
+  if (snprintf(s, maxlen, "%3d,%02d" EURSYM, cent / 100, cent % 100) > maxlen)
     return NULL;
-  // workaround to produce a leading zero for cents.. %0.2d won't work
-  sprintf(s, "%3d,%s%dEUR", cent / 100, ((cent % 100) < 10 ? "0" : ""),
-          cent % 100);
   return s;
 }