-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.c
55 lines (40 loc) · 993 Bytes
/
messages.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Messages are the scrolling messages within the UI.
// This file contains update and retrieval functions.
#include "7drltypes.h"
#define MAX_MSG_SIZE ( NCOLS - 2 )
static int write_ptr = 0;
char messages[ MAX_MESSAGES ][ MAX_MSG_SIZE ];
void init_messages( void )
{
bzero( messages, sizeof( messages ) );
return;
}
void add_message( char *msg )
{
int i = 0;
size_t len = strlen( msg );
// Copy the message into the buffer and pad with spaces
while ( i < ( MAX_MSG_SIZE - 1 ) )
{
if ( i < len ) messages[ write_ptr ][ i ] = msg[ i ];
else messages[ write_ptr ][ i ] = ' ';
i++;
}
// Null terminate
messages[ write_ptr ][ ( MAX_MSG_SIZE - 1 ) ] = 0;
if ( ++write_ptr >= MAX_MESSAGES )
{
write_ptr = 0;
}
return;
}
char *get_message( int pos )
{
int read_ptr;
read_ptr = write_ptr + pos;
if (read_ptr >= MAX_MESSAGES )
{
read_ptr -= MAX_MESSAGES;
}
return &messages[ read_ptr ][ 0 ];
}