/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred."
 *
 */
/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: syn.c 1.2 89/10/10 $@(#)search:syn.c	1.4"
#include "msearch.h"
extern char err_label[STRSIZE];

getsyn(fp, wd, wdfile)
FILE *fp;
char *wd;
char *wdfile;
{
     char linebuf[BUFSIZ];
     char leftword[STRSIZE], rhtword[STRSIZE];
     FILE *fpword;
     int matchstate = FALSE;
     int wordsize = strlen(wd);
     while( fgets(linebuf, BUFSIZ, fp) != NULL) {
        sscanf(linebuf,"%s %s",  leftword, rhtword);	
        if(strncmp(wd,leftword,wordsize)==0) {
             if(matchstate == FALSE) {
                 matchstate = TRUE;
                 fpword = fopen(wdfile,"w");
                 if(fpword == NULL) {
                      sprintf(linebuf,"%s: getsyn: %s",err_label, wdfile);
                      perror(linebuf);
                      exit(1);
                 }
                 fprintf(fpword," %s\n", wd);
                 printf(" %s", wd);
              }
              fprintf(fpword," %s\n",rhtword);
              printf(" %s", rhtword);
        }
     }
     if (matchstate == TRUE) fclose(fpword);
     rewind(fp);
     return(matchstate);
}
