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
107
108
109
110
111
|
$NetBSD: patch-focal0_c,v 1.1 2012/05/31 23:42:01 dholland Exp $
- place a big comment within a comment (just within a false ifdef is
not sufficient)
- do not use gets()
- use ctype.h functions correctly
- avoid symbol conflict with getline()
- don't use implicit int
--- focal0.c.orig 1995-04-17 13:03:43.000000000 +0000
+++ focal0.c
@@ -13,6 +13,7 @@
$(ATOD) = 1
$(DTOA) = 1
*/
+/*
#ifdef DOCUMENTATION
title focal Ancient Interpretive Language
@@ -35,6 +36,7 @@ author
Dave Conroy
#endif
+*/
#include "focal.h"
#ifdef vms
@@ -66,6 +68,24 @@ int intflag; /* Interrupt flag */
struct sym *sym[N_HASH + 1]; /* Symbol table */
+static char *
+dogets(char *buf, size_t len)
+{
+ char *ret;
+
+ ret = fgets(buf, len, stdin);
+ if (ret != NULL) {
+ len = strlen(buf);
+ if (len > 0 && buf[len-1] == '\n') {
+ buf[--len] = '\0';
+ }
+ if (len > 0 && buf[len-1] == '\r') {
+ buf[--len] = '\0';
+ }
+ }
+ return ret;
+}
+
int main()
{
register int c;
@@ -86,7 +106,7 @@ int main()
catchcc();
for (;;) {
putchar('*');
- if (gets(cbuf) == NULL) {
+ if (dogets(cbuf, sizeof(cbuf)) == NULL) {
putchar('\n');
break;
}
@@ -205,7 +225,7 @@ loop:
popdo();
goto loop;
}
- while (isalpha(*ctp))
+ while (isalpha((unsigned char)*ctp))
++ctp;
if (isupper(c))
c = tolower(c);
@@ -427,7 +447,7 @@ void ask()
--ctp;
sp = getsym();
printf(": ");
- if (gets(abuf) == NULL) {
+ if (dogets(abuf, sizeof(abuf)) == NULL) {
putchar('\n');
diag("EOF in ask");
}
@@ -649,11 +669,11 @@ register int c;
}
-int getline(cp, fp)
+int get_line(cp, fp)
register char *cp;
register FILE *fp;
{
- register c;
+ register int c;
while ((c=getc(fp))!=EOF && c!='\n')
*cp++ = c;
@@ -667,7 +687,7 @@ register FILE *fp;
void type()
{
register char *fmt;
- register c;
+ register int c;
static char fmtb[20];
static int ifmtb = 1;
int x, y;
@@ -724,7 +744,7 @@ FILE *fp;
{
struct lno lno;
register struct line *lp;
- register tgroup, lgroup;
+ register int tgroup, lgroup;
if (lnop == NULL) {
lno.ln_type = LN_ALL;
|