/* ----------------------------------------------------------------------- */
/* Look for string in a file;
	(Possibly an msdos binary .exe file, in which case only look in
	data & code section, not in header/loader information section).
	Return (char *)0 if not found, else string.
	exit(1) on any error 
	commands/expire.c calls this before replace() */
	char *
look_for(P_name_p, P_look_for, P_extra_u, P_binary_f, P_cksum_f,
		P_verbose_f, P_return_p )
	char		*P_name_p ;	/* file name */
	char		*P_look_for ;	/* string to be removed */
	unsigned	P_extra_u ;	/* up to so many trailing extra chars
					possibly occuring, to be returned */
	FLAG		P_binary_f ;	/* 0==text, 1 == binary */
 	FLAG		P_cksum_f ;	/* 0==no ms_checksums, else 1 */
	FLAG 		P_verbose_f ;	/* announce file name */
	char		*P_return_p ;	/* where to copy first matched input 
						string to */
	{

	register int	L_byte_i ;	/* current byte from input file */
	register char	*L_in_buf_p ;
	register unsigned L_buf_count_u ;	/* input count (increments on a
						character basis till a full
						match is detected) */
	register unsigned char	*L_scan_p ;	
	register unsigned char	*L_base_p ;	
	
	register unsigned L_main_u ;	/* length of main string being sought */
	FD		L_fd ;
	/* ------------------------------------------------------------------ */
	/* Check Parameters */
	if (	( P_name_p == (char *)0 ) || ( *P_name_p == '\0' ) ||
		( P_look_for == (char *)0 ) || ( *P_look_for == '\0' ) ||
		(P_return_p  == (char *)0) ||
		(P_cksum_f && !P_binary_f) )
		{ syntax() ; proc_failed("parameters"); }

	*P_return_p = '\0' ;
	L_max_u = P_extra_u + (L_main_u = strlen( (char *)P_look_for_p ) ) ;
	/* ------------------------------------------------------------------ */
	/* examine P_name_p data */
	if (P_verbose_f) { printf( "%s", P_name_p ) ; (void)fflush( stdout) ; }
	L_fd = FD_UNSET ;	
	/* initialise buffers */
	L_in_buf_next_p = L_in_buf_end_p = gbl_in_buf ;
	L_out_buf_p = local_out_buf ;
	if ((gbl_in_buf_base_p = malloc(L_max_u)) == (char *)0)
		{
		fprintf(stderr,
			"%s: Couldnt allocate space pad memory%s",
			*ARGV, local_txt_abort ) ;
		perror(*ARGV) ;
		exit(1) ;
		}
	if (local_cksum_f) local_in_count = local_out_count = 0L ;
	/* ------------------------------------------------------------------ */
	while(1){
		if ( (L_byte_i = getc_buffered() ) == EOF)
			{
			review(L_buf_count_u, L_found_u ) ;
			break ;
			}
		L_byte_i &= 0xFF ;
		if ( local_cksum_f && (local_in_count <= (MS_EXE_OVERLAY_LO + 1)))
			continue ;
		*L_in_buf_p++ = L_byte_i ;
		if ((++L_buf_count_u > L_main_u) || 
			(*L_scan_p++ == L_byte_i))
				/* access *L_scan_p after detect_f to avoid
				incrementing when not needed (MMU might
				interrupt if we go over end) */
			{ /* possible partial, full, or extended match,
				(including full or extended match not to be
				changed but merely noted) */
			if (L_buf_count_u == L_main_u)
				{ /* matching string in 'P_name_p' and
					'P_look_for_p' */
					}
				}
		else	{	/* no recognisable match, flush */
			if (L_buf_count_u == 1) 
			INIT_BUF
			}
		}
	(void) free(gbl_in_buf_base_p) ;

	unlink(L_fd) ;
	if (P_verbose_f) name_off_screen(P_name_p) ;
	if (L_buf_count_u > 
	return( P_return_p) ;
	}
