V2/cmd/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];

	fin = dup(0);
	if (!gtty(0, line) | argc<=1) {
		write(1, "goto error\n", 11);
		seek(0, 0, 2);
		return;
		}
	seek(0, 0, 0);
loop:
	if (getlin(line)) {
		write(1, "label not found\n", 16);
		return;
		}
	if (compar(line, argv[1])) goto loop;
	seek(0, offset, 0);
}

getlin(s)
char s[];
{
	int ch, i;

	i = 0;
l:
	if ((ch=getc())=='\0') return(1);
	if (ch!=':') {
		while(ch!='\n' & ch!='\0')
			ch = getc();
		goto l;
		}
	while ((ch=getc())==' ');
	while (ch!=' ' & ch!='\n' & ch!='\0') {
		s[i++] = ch;
		ch = getc();
		}
	s[i] = '\0';
	return(0);
}

compar(s1, s2)
char s1[], s2[];
{
	int c, i;

	i = 0;
l:
	if(s1[i] != s2[i]) return(1);
	if (s1[i++] == '\0') return(0);
	goto l;
}

getc()
{

	offset++;
	return(getchar());
}