]> git.sur5r.net Git - c128-kasse/blobdiff - src/general.c
make cat.c compile again
[c128-kasse] / src / general.c
index 74d57b1a4ecd31cd4454f95d862fd5ff79d7b794..0e50a7208a622f2b2fa4b7943b508f5f93d3c493 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * RGB2R-C128-Kassenprogramm
- * (c) 2007 phil_fry, sECuRE, sur5r
+ * © 2007-2009 phil_fry, sECuRE, sur5r
  * See LICENSE for license information
  *
  */
@@ -12,7 +12,7 @@
 #include "general.h"
 
 /*
- * Liest (maximal 31) Zeichen ein, bis Enter gedrckt wird.
+ * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird.
  * Vorsicht: Es wird ein statischer Buffer benutzt, sodass man
  * das Ergebnis via strdup() retten muss, bevor man get_input()
  * erneut aufruft
  */
 char *get_input() {
        BYTE i = 0;
+       BYTE c, x, y;
        static char output[32];
-       BYTE c;
+       x = wherex();
+       y = wherey();
        memset(output, '\0', 32);
        while (1) {
                if (i == 31)
                        break;
-               c = getchar();
+               c = cgetc();
                if (c == 13)
                        break;
-               else output[i++] = c;
+               /* backspace? */
+               if (c == 20) {
+                       /* If you are at the left-most position, do nothing */
+                       if (i == 0)
+                               continue;
+                       output[--i] = '\0';
+                       cputcxy(x+i, y, ' ');
+                       gotoxy(x+i, y);
+                       continue;
+               }
+               cputc(c);
+               output[i++] = c;
        }
        return output;
 }
 
+char retry_or_quit() {
+       char *c;
+       do {
+               cprintf("\r\nr)etry or q)uit?\r\n");
+               c = get_input();
+       } while ((*c != 'r') && (*c != 'q'));
+       return *c;
+}
+
 char *format_euro(char *s, int maxlen, int cent){
        int tmp = cent;
        int len = strlen(",EUR");
@@ -42,7 +64,7 @@ char *format_euro(char *s, int maxlen, int cent){
        if (len >= maxlen)
                return NULL;
        // workaround to produce a leading zero for cents.. %0.2d won't work 
-       sprintf(s, "%d,%s%dEUR", cent / 100, (cent<10?"0":""), cent % 100);
+       sprintf(s, "%3d,%s%dEUR", cent / 100, ((cent%100)<10?"0":""), cent % 100);
        return s;
 }