keep the most recent DUMPLOG_MSG_COUNT messages */
| 19 | |
| 20 | /* keep the most recent DUMPLOG_MSG_COUNT messages */ |
| 21 | void |
| 22 | dumplogmsg(const char *line) |
| 23 | { |
| 24 | /* |
| 25 | * TODO: |
| 26 | * This essentially duplicates message history, which is |
| 27 | * currently implemented in an interface-specific manner. |
| 28 | * The core should take responsibility for that and have |
| 29 | * this share it. |
| 30 | */ |
| 31 | unsigned indx = gs.saved_pline_index; /* next slot to use */ |
| 32 | char *oldest = gs.saved_plines[indx]; /* current content of that slot */ |
| 33 | |
| 34 | if (!strncmp(line, "Unknown command", 15)) |
| 35 | return; |
| 36 | if (oldest && strlen(oldest) >= strlen(line)) { |
| 37 | /* this buffer will gradually shrink until the 'else' is needed; |
| 38 | there's no pressing need to track allocation size instead */ |
| 39 | Strcpy(oldest, line); |
| 40 | } else { |
| 41 | if (oldest) |
| 42 | free((genericptr_t) oldest); |
| 43 | gs.saved_plines[indx] = dupstr(line); |
| 44 | } |
| 45 | gs.saved_pline_index = (indx + 1) % DUMPLOG_MSG_COUNT; |
| 46 | } |
| 47 | |
| 48 | /* called during save (unlike the interface-specific message history, |
| 49 | this data isn't saved and restored); end-of-game releases saved_plines[] |
no test coverage detected