Skip to content

Commit

Permalink
Print save operations and automatically save on quit (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysogeny authored Nov 4, 2023
1 parent 1d8dd35 commit 349e3f2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,21 @@ void load_credits(void) {
}

void save_items(void) {
cprintf("\r\nspeichere items.. ");
if (items_exists)
_sysremove("items");
cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
items_exists = true;
cprintf("ok");
}

void save_credits(void) {
cprintf("\r\nspeichere credits.. ");
if (credits_exists)
_sysremove("credits");
cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
credits_exists = true;
cprintf("ok");
}

void load_config(void) { lookup_needed_files(); }
4 changes: 4 additions & 0 deletions src/credit_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ void credit_manager(void) {
break;
case 's':
save_credits();
cprintf("\r\nDr" uUML "cke RETURN...\r\n");
cget_return();
break;
case 'f':
if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE))
Expand Down Expand Up @@ -304,6 +306,8 @@ void credit_manager(void) {
break;
case 'z':
save_credits();
cprintf("\r\nDr" uUML "cke RETURN...\r\n");
cget_return();
return;
default:
cprintf("Unbekannter Befehl, dr" uUML "cke RETURN...\r\n");
Expand Down
2 changes: 2 additions & 0 deletions src/itemz.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void itemz_manager() {
break;
case 'z':
save_items();
cprintf("\r\nDr" uUML "cke RETURN...\r\n");
cget_return();
return;
default:
cprintf("Unbekannter Befehl, dr" uUML "cke RETURN...\r\n");
Expand Down
15 changes: 8 additions & 7 deletions src/kasse.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,24 +389,25 @@ int main(void) {
} else if (*c == 'f') {
buy_custom();
} else if (*c == 's') {
cprintf("\r\nsaving items.. ");
save_items();
cprintf("ok\r\nsaving credits.. ");
save_credits();
cprintf("ok\r\nflushing log.. ");
log_flush();
cprintf("ok\r\nStatefile/Creditfile/Log gesichert, dr" uUML
"cke RETURN...\r\n");
cget_return();
cprintf("\r\nDr" uUML "cke RETURN...\r\n");
} else if (*c == 'g') {
credit_manager();
} else if (*c == 'i') {
itemz_manager();
load_items();
} else if (*c == 'z') {
set_time_interactive();
} else if (*c == 'q')
} else if (*c == 'q') {
save_items();
save_credits();
log_flush();
cprintf("\r\nDr" uUML "cke RETURN...\r\n");
cget_return();
break;
}
}
clrscr();
cprintf("\r\nBYEBYE\r\n");
Expand Down
2 changes: 2 additions & 0 deletions src/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void print_header(void) {
void log_flush(void) {
int c;
static char filename[8];
cprintf("\r\nspeichere log.. ");
sprintf(filename, "log-%d", log_num);

/* If we have written to this logfile before, we need to remove it first */
Expand All @@ -123,6 +124,7 @@ void log_flush(void) {
cbm_close((BYTE)8);

log_heap_flushed = log_heap_offset;
cprintf("ok");
}

/*
Expand Down

0 comments on commit 349e3f2

Please sign in to comment.