/*  This program takes an RCS directory, and sees if the files in the
 *  diretory above it are out of date, and need to be checked out.
 */
#include <stdio.h>
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <strings.h>

main(argc,argv)
     int argc;
     char *argv[];
{
  DIR *cur_dir;
  struct direct this_file;
  struct direct *this_filep;
  char rcs_filename[MAXPATHLEN],filename[MAXPATHLEN];
  char *tmp;
  struct stat file_stat,rcs_file_stat;

  if (argc != 2) {
    fprintf(stderr,"usage: %s rcsdirectoryname\n",argv[0]);
    exit(1);
  }
  this_filep = &this_file;
  if ((cur_dir = opendir(argv[1])) == NULL) {
    fprintf(stderr,"%s: diretory %s could not be opened\n",argv[1]);
    exit(1);
  }
  while ((this_filep = readdir(cur_dir)) != NULL) {
    sprintf(rcs_filename,"%s/%s",argv[1],this_filep->d_name);
    strcpy(filename,argv[1]);
    tmp = rindex(filename,'/');
    if (tmp != NULL) *tmp = '\0';
    strcat(filename,"/");
    strcat(filename,this_filep->d_name);
    tmp = rindex(filename,',');
    if (tmp != NULL) *tmp = '\0';
    stat(rcs_filename,&rcs_file_stat);
    if (rcs_file_stat.st_mode & S_IFDIR) continue;
    if (stat(filename,&file_stat) || (rcs_file_stat.st_mtime >
				       file_stat.st_mtime))
      printf("%s\n",filename);
  }
}
      
