Repository navigation
Expand file tree
/
Copy pathreader.c
More file actions
executable file
·134 lines (112 loc) · 2.97 KB
/
Copy pathreader.c
File metadata and controls
executable file
·134 lines (112 loc) · 2.97 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*************************************************************************
*
* m a k e : r e a d e r . c
*
* Read in makefile
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 23.08.89 cast to NULL added RAL
* 3 30.08.89 indention changed PSH,RAL
* 4 03.09.89 fixed LZ eliminated RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#include "h.h"
/*
* Syntax error handler. Print message, with line number, and exits.
*/
void error(msg, a1)
char *msg;
char *a1;
{
fprintf(stderr, "%s: ", myname);
fprintf(stderr, msg, a1);
if (lineno) fprintf(stderr, " in %s near line %d", makefile, lineno);
fputc('\n', stderr);
exit(1);
}
/*
* Read a line into the supplied string. Remove
* comments, ignore blank lines. Deal with quoted (\) #, and
* quoted newlines. If EOF return TRUE.
*
* The comment handling code has been changed to leave comments and
* backslashes alone in shell commands (lines starting with a tab).
* This is not what POSIX wants, but what all makes do. (KJB)
*/
bool getline(strs, fd)
struct str *strs;
FILE *fd;
{
register char *p;
char *q;
int c;
for (;;) {
strs->pos = 0;
for (;;) {
do {
if (strs->pos >= strs->len)
strrealloc(strs);
if ((c = getc(fd)) == EOF)
return TRUE; /* EOF */
(*strs->ptr)[strs->pos++] = c;
} while (c != '\n');
lineno++;
if (strs->pos >= 2 && (*strs->ptr)[strs->pos - 2] == '\\') {
(*strs->ptr)[strs->pos - 2] = '\n';
strs->pos--;
} else {
break;
}
}
if (strs->pos >= strs->len)
strrealloc(strs);
(*strs->ptr)[strs->pos] = '\0';
p = q = *strs->ptr;
while (isspace(*q)) q++;
if (*p != '\t' || *q == '#') {
while (((q = strchr(p, '#')) != (char *)0) &&
(p != q) && (q[-1] == '\\'))
{
char *a;
a = q - 1; /* Del \ chr; move rest back */
p = q;
while (*a++ = *q++)
;
}
if (q != (char *)0)
{
q[0] = '\n';
q[1] = '\0';
}
}
p = *strs->ptr;
while (isspace(*p)) /* Checking for blank */
p++;
if (*p != '\0')
return FALSE;
}
}
/*
* Get a word from the current line, surounded by white space.
* return a pointer to it. String returned has no white spaces
* in it.
*/
char *gettok(ptr)
register char **ptr;
{
register char *p;
while (isspace(**ptr)) /* Skip spaces */
(*ptr)++;
if (**ptr == '\0') /* Nothing after spaces */
return ((char *)NULL);
p = *ptr; /* word starts here */
while ((**ptr != '\0') && (!isspace(**ptr)))
(*ptr)++; /* Find end of word */
*(*ptr)++ = '\0'; /* Terminate it */
return(p);
}