]> git.sur5r.net Git - c128-kasse/blob - src/general.c
patch charset to include umlauts
[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 #include "vdc_patch_charset.h"
14
15 /*
16  * get_input_terminated_by() reads input (handling backspace correctly) until
17  * a terminator of |terminators| is encountered or |out| is full (outlen-1
18  * characters were read).
19  *
20  * get_input_terminated_by() returns the terminator it encountered.
21  *
22  */
23 input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators,
24                                            char *out, BYTE outlen) {
25   BYTE i = strlen(out);
26   BYTE c, x, y;
27   x = wherex() - i;
28   y = wherey();
29   while (1) {
30     c = cgetc();
31     if (((terminators & INPUT_TERMINATOR_RETURN) == INPUT_TERMINATOR_RETURN) &&
32         (c == PETSCII_CR)) {
33       return INPUT_TERMINATOR_RETURN;
34     } else if (((terminators & INPUT_TERMINATOR_SPACE) ==
35                 INPUT_TERMINATOR_SPACE) &&
36                (c == PETSCII_SP)) {
37       return INPUT_TERMINATOR_SPACE;
38     } else if (c == PETSCII_DEL) {
39       /* If you are at the left-most position, do nothing */
40       if (i == 0)
41         continue;
42       out[--i] = '\0';
43       cputcxy(x + i, y, ' ');
44       gotoxy(x + i, y);
45       continue;
46     }
47     if (i == (outlen - 1)) {
48       continue;
49     }
50     cputc(c);
51     out[i++] = c;
52   }
53 }
54
55 /*
56  * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird.
57  * Vorsicht: Es wird ein statischer Buffer benutzt, sodass man
58  * das Ergebnis via strdup() retten muss, bevor man get_input()
59  * erneut aufruft
60  *
61  */
62 char *get_input(void) {
63   static char output[32];
64   memset(output, '\0', sizeof(output));
65   get_input_terminated_by(INPUT_TERMINATOR_RETURN, output, sizeof(output));
66   return output;
67 }
68
69 char retry_or_quit(void) {
70   char *c;
71   do {
72     cprintf("\r\nr)etry or q)uit?\r\n");
73     c = get_input();
74   } while ((*c != 'r') && (*c != 'q'));
75   return *c;
76 }
77
78 char *format_euro(char *s, int maxlen, int cent) {
79   if (snprintf(s, maxlen, "%3d,%02d" EURSYM, cent / 100, cent % 100) > maxlen)
80     return NULL;
81   return s;
82 }
83
84 void c128_perror(BYTE c, char *msg) {
85   cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg,
86           _oserror);
87 }