USG_PG3/usr/source/sccscmds/help.c

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

# include "../sccshead/sfile.h"

char help___[] "@(#)help.c:	2.6";
/*
	Program to locate helpful info in an ascii file.
	File is formatted as follows:

		* comment
		* comment
		-str1
		-str2
		text1
		text2
		-str3
		text3
		* comment
		text4

	The "str?" that matches the argument is found and
	the following text lines are printed.  If the argument
	is omitted, the program requests it.
*/

char hfile[] "/usr/lib/sccs.hf";


main(argc,argv)
int argc;
char *argv[];
{
	register char *key, *line;
	struct Ibufr buf;

	opnl(&buf,hfile);

	switch(argc) {
		case 1:		key = ask();
				break;
		case 2:		key = argv[1];
				break;
		default:	printf("arg count (4)\n");
				exit(1);
	}


	find(&buf,key);

	while ((line=getl(&buf))!=1 && line[0] == '-') ;
	if (line==1) fatal();

	do {
		if (line[0]!='*') {
			line[buf.Ilen-1] = 0;
			printf("%s\n",line);
		}
	} while ((line=getl(&buf))!=1 && line[0] != '-');

	exit(0);
}


ask()
{
	static char resp[50];
	register char *r;

	printf("msg number or comd name? ");

	r = resp;
	while((*r++ = getchr()) != '\n');
	*--r = '\0';

	return(resp);
}


find(abuf,key)
struct Ibufr *abuf;
char *key;
{
	register struct Ibufr *buf;
	register char *p;

	for (buf=abuf; getl(buf)!=1; ) {
		if (*(p=buf->Irecptr)=='*') continue;
		if (*p=='-') {
			p[buf->Ilen-1] = 0;
			if (equal(++p,key)) return;
		}
	}
	fatal("not found (83)");
}