]> git.sur5r.net Git - c128-kasse/blob - src/general.c
right-align price in header
[c128-kasse] / src / general.c
1 /* 
2  * RGB2R-C128-Kassenprogramm
3  * © 2007-2009 phil_fry, sECuRE, sur5r
4  * See LICENSE for license information
5  *
6  */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <conio.h>
11
12 #include "general.h"
13
14 /*
15  * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird.
16  * Vorsicht: Es wird ein statischer Buffer benutzt, sodass man
17  * das Ergebnis via strdup() retten muss, bevor man get_input()
18  * erneut aufruft
19  *
20  */
21 char *get_input() {
22         BYTE i = 0;
23         BYTE c, x, y;
24         static char output[32];
25         x = wherex();
26         y = wherey();
27         memset(output, '\0', 32);
28         while (1) {
29                 if (i == 31)
30                         break;
31                 c = cgetc();
32                 if (c == 13)
33                         break;
34                 /* backspace? */
35                 if (c == 20) {
36                         /* If you are at the left-most position, do nothing */
37                         if (i == 0)
38                                 continue;
39                         output[--i] = '\0';
40                         cputcxy(x+i, y, ' ');
41                         gotoxy(x+i, y);
42                         continue;
43                 }
44                 cputc(c);
45                 output[i++] = c;
46         }
47         return output;
48 }
49
50 char retry_or_quit() {
51         char *c;
52         do {
53                 cprintf("\r\nr)etry or q)uit?\r\n");
54                 c = get_input();
55         } while ((*c != 'r') && (*c != 'q'));
56         return *c;
57 }
58
59 char *format_euro(char *s, int maxlen, int cent){
60         int tmp = cent;
61         int len = strlen(",EUR");
62         while ((tmp /= 10) > 0)
63                 ++len;
64         if (len >= maxlen)
65                 return NULL;
66         // workaround to produce a leading zero for cents.. %0.2d won't work 
67         sprintf(s, "%3d,%s%dEUR", cent / 100, ((cent%100)<10?"0":""), cent % 100);
68         return s;
69 }
70
71 void c128_perror(BYTE c, char *msg) {
72         cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg, _oserror);
73 }