-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathti994a_compat.c
61 lines (51 loc) · 1.25 KB
/
ti994a_compat.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
55
56
57
58
59
60
#include "ti994a_compat.h"
extern int printf(const char *format, ...);
static int tolower(int ch);
FILE* stdin = NULL;
char *strncpy(char *toHere, const char *fromHere, size_t count)
{
char* orig = toHere;
if (toHere != NULL && fromHere != NULL && count > 0)
{
do
{
*toHere = *fromHere;
toHere++;
fromHere++;
count--;
} while ((*fromHere != '\0') && (count > 0));
*toHere = '\0';
}
else if (toHere != NULL)
{
*toHere = '\0';
}
return orig;
}
char* fgets(char *buffer, int size, FILE *f)
{
gets(buffer, size);
// printf("'%s'\n", buffer);
// ti gets routine only supports UPPERCASE input
// for whatever reason.
// Convert all to lc, since this is what the game expects.
char* p = buffer;
while (*p != '\0')
{
*p = tolower(*p);
p++;
}
// add a newline to the end. 'fgets' returns the newline,
// but 'gets' does not. Calling function 'readln' expects
// (and removes) the newline.
*p = '\n';
p++;
*p = '\0';
//printf("'%s'\n", buffer);
return buffer;
}
static int tolower(int ch)
{
if (ch >= (int)'A' && ch <= (int)'Z') ch = ch + ('a' - 'A');
return ch;
}