}
/*
- * when depositing money with this and returning to the main menu, the program
- * will crash with a message like the following:
+ * Deposits credit for a user. Called in the credit manager (with input ==
+ * NULL) or interactively when the user does not have enough money for his
+ * intended purchase (with input == nickname).
*
*/
-static void deposit_credit() {
+void deposit_credit(char *input) {
char *time = get_time();
- char *input;
struct credits_t *credit;
unsigned int deposit;
- cprintf("\r\nName:\r\n");
- if ((input = get_input()) == NULL || *input == '\0')
- return; // no name given
-
+ if (input == NULL) {
+ cprintf("\r\nName:\r\n");
+ if ((input = get_input()) == NULL || *input == '\0')
+ return; // no name given
+ }
+
if ((credit = find_credit(input)) == NULL)
return; // cannot find named credit
current_credits_page--;
break;
case 'p':
- deposit_credit(); break;
+ deposit_credit(NULL); break;
case 'g':
cprintf("Filter eingeben:\r\n");
filter = get_input();
* to NULL if no such credit could be found */
credit = find_credit(nickname);
if (credit != NULL) {
- if ((signed int)credit->credit < ((signed int)price * einheiten)) {
- cprintf("Sorry, %s hat nicht genug Geld :-(\r\n", nickname);
- get_input();
- return 0;
+ while ((signed int)credit->credit < ((signed int)price * einheiten)) {
+ cprintf("%s hat nicht genug Geld. e) einzahlen a) abbruch \r\n", nickname);
+ c = cgetc();
+ if (c == 'e') {
+ deposit_credit(nickname);
+ } else {
+ return 0;
+ }
}
/* substract money */
credit->credit -= (price * einheiten);