source: trunk/minix/commands/make/reader.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 3.0 KB
Line 
1/*************************************************************************
2 *
3 * m a k e : r e a d e r . c
4 *
5 * Read in makefile
6 *========================================================================
7 * Edition history
8 *
9 * # Date Comments By
10 * --- -------- ---------------------------------------------------- ---
11 * 1 ?? ??
12 * 2 23.08.89 cast to NULL added RAL
13 * 3 30.08.89 indention changed PSH,RAL
14 * 4 03.09.89 fixed LZ eliminated RAL
15 * ------------ Version 2.0 released ------------------------------- RAL
16 *
17 *************************************************************************/
18
19#include "h.h"
20
21
22/*
23 * Syntax error handler. Print message, with line number, and exits.
24 */
25void error(msg, a1)
26char *msg;
27char *a1;
28{
29 fprintf(stderr, "%s: ", myname);
30 fprintf(stderr, msg, a1);
31 if (lineno) fprintf(stderr, " in %s near line %d", makefile, lineno);
32 fputc('\n', stderr);
33 exit(1);
34}
35
36
37/*
38 * Read a line into the supplied string. Remove
39 * comments, ignore blank lines. Deal with quoted (\) #, and
40 * quoted newlines. If EOF return TRUE.
41 *
42 * The comment handling code has been changed to leave comments and
43 * backslashes alone in shell commands (lines starting with a tab).
44 * This is not what POSIX wants, but what all makes do. (KJB)
45 */
46bool getline(strs, fd)
47struct str *strs;
48FILE *fd;
49{
50 register char *p;
51 char *q;
52 int c;
53
54 for (;;) {
55 strs->pos = 0;
56 for (;;) {
57 do {
58 if (strs->pos >= strs->len)
59 strrealloc(strs);
60 if ((c = getc(fd)) == EOF)
61 return TRUE; /* EOF */
62 (*strs->ptr)[strs->pos++] = c;
63 } while (c != '\n');
64
65 lineno++;
66
67 if (strs->pos >= 2 && (*strs->ptr)[strs->pos - 2] == '\\') {
68 (*strs->ptr)[strs->pos - 2] = '\n';
69 strs->pos--;
70 } else {
71 break;
72 }
73 }
74
75 if (strs->pos >= strs->len)
76 strrealloc(strs);
77 (*strs->ptr)[strs->pos] = '\0';
78
79 p = q = *strs->ptr;
80 while (isspace(*q)) q++;
81 if (*p != '\t' || *q == '#') {
82 while (((q = strchr(p, '#')) != (char *)0) &&
83 (p != q) && (q[-1] == '\\'))
84 {
85 char *a;
86
87 a = q - 1; /* Del \ chr; move rest back */
88 p = q;
89 while (*a++ = *q++)
90 ;
91 }
92 if (q != (char *)0)
93 {
94 q[0] = '\n';
95 q[1] = '\0';
96 }
97 }
98
99 p = *strs->ptr;
100 while (isspace(*p)) /* Checking for blank */
101 p++;
102
103 if (*p != '\0')
104 return FALSE;
105 }
106}
107
108
109/*
110 * Get a word from the current line, surounded by white space.
111 * return a pointer to it. String returned has no white spaces
112 * in it.
113 */
114char *gettok(ptr)
115register char **ptr;
116{
117 register char *p;
118
119
120 while (isspace(**ptr)) /* Skip spaces */
121 (*ptr)++;
122
123 if (**ptr == '\0') /* Nothing after spaces */
124 return ((char *)NULL);
125
126 p = *ptr; /* word starts here */
127
128 while ((**ptr != '\0') && (!isspace(**ptr)))
129 (*ptr)++; /* Find end of word */
130
131 *(*ptr)++ = '\0'; /* Terminate it */
132
133 return(p);
134}
Note: See TracBrowser for help on using the repository browser.