xref: /original-bsd/usr.bin/struct/struct/1.line.c (revision 4eeb57e9)
1438c295bSbostic /*-
2438c295bSbostic  * %sccs.include.proprietary.c%
3438c295bSbostic  */
4438c295bSbostic 
568a94c65Srrh #ifndef lint
6*4eeb57e9Sbostic static char sccsid[] = "@(#)1.line.c	8.1 (Berkeley) 06/06/93";
7438c295bSbostic #endif /* not lint */
868a94c65Srrh 
968a94c65Srrh #include <stdio.h>
1068a94c65Srrh #
1168a94c65Srrh #include "def.h"
1268a94c65Srrh #define bufsize 1601
1368a94c65Srrh char buffer[bufsize];
1468a94c65Srrh int bufcount;
1568a94c65Srrh extern int errflag;
1668a94c65Srrh long stchars;			/* counts number of chars at most recent \n read */
1768a94c65Srrh #ifndef unix
1868a94c65Srrh long ostchars;
1968a94c65Srrh extern long ftell();
2068a94c65Srrh #endif
2168a94c65Srrh int newline;			/* counts number of lines read so far in file */
2268a94c65Srrh extern int rdfree(), comfree(),labfree(), contfree();
2368a94c65Srrh extern int rdstand(), comstand(), labstand(), contstand();
2468a94c65Srrh extern int (*rline[])();
2568a94c65Srrh extern int (*comment[])();
2668a94c65Srrh extern int (*getlabel[])();
2768a94c65Srrh extern int (*chkcont[])();
2868a94c65Srrh 
2968a94c65Srrh 
3068a94c65Srrh 
flush()3168a94c65Srrh flush()
3268a94c65Srrh 	{bufcount = 0; }
3368a94c65Srrh 
addchar(c)3468a94c65Srrh addchar(c)
3568a94c65Srrh 	{
3668a94c65Srrh 	buffer[bufcount++] = c;
3768a94c65Srrh 	}
3868a94c65Srrh 
getline(lastline,lastchar,linecom,charcom)3968a94c65Srrh getline(lastline,lastchar,linecom,charcom)
4068a94c65Srrh int *lastline, *linecom;
4168a94c65Srrh long *lastchar, *charcom;
4268a94c65Srrh 				/* set *lastline to number of last line of statement,
4368a94c65Srrh 				set *lastchar to number of last char of statement,
4468a94c65Srrh 				set *linecom to number of last line of comment preceding statement */
4568a94c65Srrh 	{
4668a94c65Srrh 
4768a94c65Srrh 	int i;
4868a94c65Srrh 	flush();
4968a94c65Srrh 	while ( unput1(input1()) != EOF)
5068a94c65Srrh 		{
5168a94c65Srrh 		while ( (*comment[inputform])(0)  || blankline() )
5268a94c65Srrh 			{
5368a94c65Srrh 			(*rline[inputform])(addchar);
5468a94c65Srrh 			flush();
5568a94c65Srrh 			}
5668a94c65Srrh 		*linecom = newline;
5768a94c65Srrh 			/* set charcom to number of last char of comment, starting at 0
5868a94c65Srrh 					if at start of file and no comment, will be -1  */
5968a94c65Srrh 		*charcom = stchars - 1;
6068a94c65Srrh 		if (unput1(input1()) == EOF)  break;
6168a94c65Srrh 		(*getlabel[inputform])(addchar);
6268a94c65Srrh 		(*rline[inputform])(addchar);
6368a94c65Srrh 
6468a94c65Srrh 		while ( blankline() || ( !(*comment[inputform])(0) &&  (*chkcont[inputform])() ))
6568a94c65Srrh 			(*rline[inputform])(addchar);
6668a94c65Srrh 
6768a94c65Srrh 		addchar('\0');
6868a94c65Srrh 		*lastline = newline;
6968a94c65Srrh 		*lastchar = stchars - 1;
7068a94c65Srrh if (debug == 40)
7168a94c65Srrh fprintf(stderr,"line %d; bufcount: %d\n",newline,bufcount);
7268a94c65Srrh 
7368a94c65Srrh 		for (i = 5; i < bufcount; ++i)
7468a94c65Srrh 			if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n')
7568a94c65Srrh 				buffer[i] = '~';
7668a94c65Srrh 		return(bufcount);
7768a94c65Srrh 		}
7868a94c65Srrh 	return(-1);
7968a94c65Srrh 	}
8068a94c65Srrh 
8168a94c65Srrh 
8268a94c65Srrh int linechars;			/* counts number of chars read so far in current line */
8368a94c65Srrh long newchar;			/* counts number of chars read so far in file */
8468a94c65Srrh 
8568a94c65Srrh 
input1()8668a94c65Srrh input1()
8768a94c65Srrh 	{
8868a94c65Srrh 	static int c;
8968a94c65Srrh 	if (c == '\n') linechars = 0;
9068a94c65Srrh 	c = inchar();
9168a94c65Srrh 	++linechars;
9268a94c65Srrh 	++newchar;
9368a94c65Srrh 	if (c == '\n')
9468a94c65Srrh 		{
9568a94c65Srrh 		++newline;
9668a94c65Srrh #ifdef unix
9768a94c65Srrh  		stchars = newchar;
9868a94c65Srrh #else
9968a94c65Srrh 		ostchars=stchars; stchars=ftell(infd);
10068a94c65Srrh #endif
10168a94c65Srrh 		}
10268a94c65Srrh 	return(c);
10368a94c65Srrh 	}
10468a94c65Srrh 
unput1(c)10568a94c65Srrh unput1(c)
10668a94c65Srrh 	{
10768a94c65Srrh 	--linechars;
10868a94c65Srrh 	--newchar;
10968a94c65Srrh 	unchar(c);
11068a94c65Srrh 	if (c == '\n')
11168a94c65Srrh 		{
11268a94c65Srrh #ifdef unix
11368a94c65Srrh  		stchars = newchar;
11468a94c65Srrh #else
11568a94c65Srrh 		stchars=ostchars;
11668a94c65Srrh #endif
11768a94c65Srrh 		--newline;
11868a94c65Srrh 		}
11968a94c65Srrh 	return(c);
12068a94c65Srrh 	}
12168a94c65Srrh 
12268a94c65Srrh 
12368a94c65Srrh 
12468a94c65Srrh 
125