USG_PG3/usr/source/cmd2/goto.c

Compare this file to the similar file:
Show the results in this format:

int	offset	0;
main(argc, argv)
char *argv[];
{
	extern fin;
	char line[64];
	int	ln;
	struct{
		char	lobyte;
		char	hibyte;
	};
	ln = lnxx(0);
	if(argc<2 || (ln.lobyte != 'x' || ln.hibyte != 'x')){
		write(2, "goto error\n", 11);
		seek(0, 0, 2);
		exit(12);
	}
	seek(0, 0, 0);
	fin = 0;
loop:
	if (getlin(line)) {
		write(2, "label not found\n", 16);
		exit(1);
		}
	if (compar(line, argv[1])) goto loop;
}
getlin(s)
char s[];
{
	register char ch;
	char getc();
l:
	if ((ch=getc())=='\0') return(1);
	if (ch!=':') {
		while(ch!='\n' && ch!='\0')
			ch = getc();
		goto l;
		}
	do ch=getc();
		while(ch==' ' || ch=='\t');
	while (ch!=' ' && ch!='\t' && ch!='\n' && ch!='\0') {
		*s++ = ch;
		ch = getc();
		}
	while(ch != '\n')
		ch = getc();
	*s = '\0';
	return(0);
}
compar(s1, s2)
char s1[], s2[];
{
	do {
		if(*s1 != *s2++) return(1);
	} while(*s1++);
	return(0);
}
char getc() {
	char c;
	if(read(0, &c, 1) != 1) c=0;
	return(c);
}