]> git.sur5r.net Git - c128-kasse/blob - src/credit_manager.c
add license information
[c128-kasse] / src / credit_manager.c
1 /* 
2  * RGB2R-C128-Kassenprogramm
3  * (c) 2007 phil_fry, sECuRE, sur5r
4  * See LICENSE for license information
5  *
6  */
7 #include <conio.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include "config.h"
13 #include "general.h"
14
15 static char *filter = NULL;
16 static BYTE filter_len;
17
18 static void print_credit_screen() {
19         BYTE i = 0;
20         clrscr();
21         cprintf("C128-Kassenprogramm: Credit Manager\r\n\r\n");
22         for (; i < credits.num_items; ++i)
23                 if (filter == NULL || strncmp(credits.credits[i].nickname, filter, filter_len) == 0)
24                         cprintf("Guthaben %s: %d Cents\r\n", credits.credits[i].nickname, credits.credits[i].credit);
25         cprintf("\r\nBefehle: n) Neues Guthaben f) Filtern z) Zurueck\r\n");
26 }
27
28 /* Guthabenverwalter */
29 void credit_manager() {
30         int negative = 1;
31         char *c, *nickname, *credits_input;
32         /* credits_int is a stupid name, but overlaps with struct credits_t credits; else */
33         int credits_int;
34         while (1) {
35                 print_credit_screen();
36                 c = get_input();
37                 if (c == NULL || *c == '\0')
38                         continue;
39                 if (*c == 'n') {
40                         cprintf("\r\nGuthaben eingeben:\r\n");
41                         credits_input = get_input();
42
43                         if (credits_input == NULL || credits_input[0] == '\0')
44                                 continue;
45                         else if (credits_input[0] == '-') {
46                                 negative = -1;
47                                 ++credits_input;
48                         }
49                         credits_int = atoi(credits_input) * negative;
50                         if (credits_int > 0) {
51                                 cprintf("Nickname eingeben:\r\n");
52                                 nickname = get_input();
53                                 if (nickname == NULL || nickname[0] == '\0')
54                                         continue;
55                                 strncpy(credits.credits[credits.num_items].nickname, nickname, 9);
56                                 credits.credits[credits.num_items].credit = credits_int;
57                                 ++credits.num_items;
58                         }
59                 } else if (*c == 'f') {
60                         cprintf("Filter eingeben:\r\n");
61                         filter = get_input();
62                         if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
63                                 filter = NULL;
64                 } else if (*c == 'z' || *c == 'q')
65                         break;
66         }
67 }