srt0.c
1.64 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*****************************************************************************/
/* */
/* Projecto de Compiladores ---------------------------------- VSPL */
/* Level 0 */
/* */
/* VSPL run-time library (C part). */
/* */
/* Salvador Pinto Abreu */
/* */
/*****************************************************************************/
main (argc, argv)
int argc;
char *argv[];
{
sspl_main();
}
int writeInt(i)
int i;
{
printf("%d", i);
}
int writeReal(f)
float f;
{
printf ("%g", f);
}
int writeBool(i)
int i;
{
printf (i? "true": "false");
}
int writeChar (c)
int c;
{
putchar (c);
}
void writeString (l, p)
register int l;
register char *p;
{
while (l-- > 0)
putchar (*p++);
}
/* INPUT */
int readInt()
{
char line[128];
int i;
do {
gets(line);
if (sscanf(line, "%d", &i))
return (i);
printf ("integer expected -- retry.\n");
} while (1);
}
float readReal()
{
char line[128];
float i;
do {
gets(line);
if (sscanf(line, "%g", &i))
return (i);
printf ("real expected -- retry.\n");
} while (1);
}
int readBool()
{
int i;
char line[128];
char s[100];
do {
gets(line);
sscanf(line, "%s", s);
if (!strcmp(s,"true"))
return (1);
else if (!strcmp(s,"false"))
return (0);
printf ("boolean expected -- retry.\n");
} while (1);
}
void readString (l, s)
register short *l;
register char *s;
{
if (gets(s))
*l = strlen(s);
else
*l = 0;
}