#include <stdio.h>
#include <stdio.h>
#include <string.h>

#ifdef __MSDOS__
#define OBJ "obj"
#else
#define OBJ "o"
#endif


int
main(argc,argv)
int argc;
char *argv[];
{
int i, found;
FILE *fp;
char buf[512],buf2[512],origname[512],*cp;

	if (argc < 3)	{
		printf ("deldep: no files given!\nusage: deldep searchstr <file> [<file> ...]\n");
		return 1;
	}
	for(i=2;i<argc;i++){
		strcpy(buf,argv[i]);
		if((cp = strchr(buf,'.')) == NULL)
			continue;
		strcpy (origname, buf);
		*cp = '\0';
		fp = fopen(argv[i],"r");
		found = 0;
		while(fgets(buf2,512,fp) != NULL){
			if(strstr(buf2,argv[1]) == 0)
				continue;
			found = 1;
			sprintf (buf2, "%s.%s", buf, OBJ);
			unlink (buf2);
			break;
		}
		if (found)
		printf("%s: deleted %s.%s ...\n", origname, buf, OBJ);
		fclose(fp);
	}
	return 0;
}

