home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
CPM3
/
CPMMAKE.ARK
/
READER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-08-31
|
3KB
|
156 lines
/*
* Read in makefile
*/
#include "c:stdio.h"
#include "h.h"
int lineno;
int endoffile = FALSE;
/*
* Syntax error handler. Print message, with line number, and exits.
*/
void
error(msg, a1, a2, a3)
char * msg;
{
fprintf(stderr, "%s: ", myname);
fprintf(stderr, msg, a1, a2, a3);
if (lineno)
fprintf(stderr, " on line %d", lineno);
fputc('\n', stderr);
exit(1);
}
/*
* Read a line into the supplied string of length LZ. Remove
* comments, ignore blank lines. Deal with quoted (\) #, and
* quoted newlines. If EOF return TRUE.
*/
bool
getline(str, fd)
char * str;
FILE * fd;
{
register char * p;
char * q;
int pos = 0;
int concatflag = 0;
int size;
for (;;)
{
if (fgets(str+pos, LZ-pos, fd) == (char *)0) {
endoffile = TRUE;
return (TRUE); /* EOF */
}
if (index(str+pos,'\032') != (char *)0) {
endoffile = TRUE;
return(TRUE);
}
/*
* Strip CP/M CR characters
*/
if ((p=index(str+pos,'\015')) != (char *)0) {
do {
*p = p[1];
} while (*(++p) != '\0');
}
/*
* Shorten leading whitespace on line extensions.
*/
if (concatflag != 0) {
for (p = str+pos ; iswhite(*p) ; p++ ) ;
size = p-str-pos-1;
if (size > 0) {
p = str+pos+1;
while ((*p = p[size]) != '\0') {
p++;
}
}
}
strlower(str+pos); /* let's do everything inlower case */
lineno++;
if ((p = index(str+pos, '\n')) == (char *)0)
error("Line too long");
/*
* I want to actually join lines that are logically joined
* so that when link commands are generated for CP/M,
* a usable CCP command line will be generated.
*/
if (p[-1] == '\\') {
*(--p) = '\0';
pos = p - str;
concatflag = 1;
continue;
}
p = str;
while (((q = index(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 = str;
while (isspace(*p)) /* Checking for blank */
p++;
if (*p != '\0')
return FALSE;
pos = 0;
}
}
/*
* 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)
char **ptr;
{
register char * p;
while (isspace(**ptr)) /* Skip spaces */
(*ptr)++;
if (**ptr == '\0') /* Nothing after spaces */
return NULL;
p = *ptr; /* word starts here */
while ((**ptr != '\0') && (!isspace(**ptr)))
(*ptr)++; /* Find end of word */
*(*ptr)++ = '\0'; /* Terminate it */
return(p);
}