#include "shared_drop_add_list.h"

P_NODE *
build_drop_person_list (const char *path, char *time_string,int len)
{
  FILE *fp;
  int fd;
  char line[200];
  P_NODE *person, *pptr = 0;
  P_NODE *pers_head = 0;

  fp = fopen (path, "r");
  if (!fp)
    cs_critical_error (ERR_PASSWD_OPEN_FAILED, path);
  
  fd = fileno(fp);  

  get_shared_lock(fd, 1);                      /* shared_lock.c */   
  
  fgets (time_string, len - 1, fp);

  while (fgets (line, 200, fp))
    {
      person = (P_NODE *) malloc (sizeof (P_NODE));
      if (!person)
	cs_critical_error (ERR_MALLOC_FAILED, "");
      get_passwd_line_data(line, &(person->data));
           /* now add it to the linked list */
      person->next = 0;
      if (!pers_head)
	pers_head = person;
      else
	pptr->next = person;

      pptr = person;
    }
    release_lock(fd); /* shared_lock.c */
    fclose (fp);
    pers_head = sort_person_list (pers_head);
    return pers_head;

}

int find_student_in_passwd(P_NODE *curr, P_NODE *drop_student)
{
     P_NODE *ptr;
	 for(ptr = curr; ptr; ptr = ptr->next)
	 {
	     if(!strcmp(ptr->data.username, drop_student->data.username))
		      return 1;
		 
	 }
     return 0;
}

