
/*
 *  UIDENT.C
 *
 *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
 *
 *  UIDENT files...
 *
 *  Searches for @($) <string> \0 and prints out
 */

#include <stdio.h>
#include <fcntl.h>
#include "/version.h"

IDENT(".01");

void FindIdent();

char Buf[8192];

void
main(ac, av)
char **av;
{
    short i;
    int fd;

    for (i = 1; i < ac; ++i) {
	printf("%-15s ", av[i]);
	fd = open(av[i], O_RDONLY);
	if (fd > 0)
	    FindIdent(fd);
	else
	    printf("(unable to open)");
	puts("");
	fflush(stdout);
	if (fd > 0)
	    close(fd);
    }
}

void
FindIdent(fd)
int fd;
{
    long n;
    long i;
    long x = 0;

    while ((n = read(fd, Buf + x, sizeof(Buf) - x)) > 0) {
	n += x;
	for (i = n - 128; i >= 0; --i) {
	    if (Buf[i] == '@' && Buf[i+1] == '(' && Buf[i+2] == '$' && Buf[i+3] == ')') {
		printf("%s", Buf + i);
	    }
	}
	x = 128;
	if (n < x)
	    x = n;
	movmem(Buf + n - x, Buf, x);
    }
}

