]> git.sur5r.net Git - c128-kasse/blob - src/general.c
Update copyright notice, convert files to utf8, add git version to itemz
[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         static char output[32];
24         BYTE c;
25         memset(output, '\0', 32);
26         while (1) {
27                 if (i == 31)
28                         break;
29                 c = getchar();
30                 if (c == 13)
31                         break;
32                 else output[i++] = c;
33         }
34         return output;
35 }
36
37 char retry_or_quit() {
38         char *c;
39         do {
40                 cprintf("\r\nr)etry or q)uit?\r\n");
41                 c = get_input();
42         } while ((*c != 'r') && (*c != 'q'));
43         return *c;
44 }
45
46 char *format_euro(char *s, int maxlen, int cent){
47         int tmp = cent;
48         int len = strlen(",EUR");
49         while ((tmp /= 10) > 0)
50                 ++len;
51         if (len >= maxlen)
52                 return NULL;
53         // workaround to produce a leading zero for cents.. %0.2d won't work 
54         sprintf(s, "%2d,%s%dEUR", cent / 100, ((cent%100)<10?"0":""), cent % 100);
55         return s;
56 }
57
58 void c128_perror(BYTE c, char *msg) {
59         cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg, _oserror);
60 }