Esempio n. 1
0
static void
delete_membership_internal(int conf, int uid)
{
	struct membership_store *mb, *omb;
	struct person_store *pp;

	if ((pp = findperson(uid)) == 0)
		return; /* Nothing in cache */

	if (pp->confs) {
		free(pp->confs);
		pp->confs = NULL;
	}
	if (pp->next == 0)
		return;

	if (pp->next->mid == conf) {
		mb = pp->next->next;
		free(pp->next);
		pp->next = mb;
		return;
	}
	omb = pp->next;
	mb = pp->next->next;
	while (mb) {
		if (mb->mid == conf) {
			omb->next = mb->next;
			free(mb);
			return;
		}
		omb = mb;
		mb = mb->next;
	}
}
Esempio n. 2
0
individual *newperson (void)
{
  individual *ind;

  ind = cmalloc (sizeof (individual));
  memset (ind,0,sizeof (individual));

  ind->sex = S_UNKNOWN;

  if (findperson(ind->id))
  {
    printf("Not possible to create a new person as ID already exists\n");
    return findperson(ind->id);
  }
  else
    addlist (&individuals,ind);
  return ind;
}
Esempio n. 3
0
struct rk_membership *
rk_membership(u_int32_t uid, u_int32_t conf)
{
	struct membership_store *mb;
	struct rk_membership *m;
	struct person_store *pp;
	int len;

	/* First, force the user into the cache */
	if (rk_persinfo(uid) == NULL)
		return NULL; /* The person do not exist, or something */

	pp = findperson(uid);
	if (pp->next) {
		mb = findmember(conf, pp->next);
		if (mb)
			return &mb->member;
	}

	/* No, we failed cache search. Fetch from server. */
	if (send_reply("98 %d %d\n", uid, conf)) {
		komerr = get_int();
		get_eat('\n');
		return NULL;
	}
	mb = calloc(sizeof(struct membership_store), 1);
	m = &mb->member;
	m->rm_position = get_int();
	read_in_time(&m->rm_last_time_read);
	m->rm_conference = get_int();
	m->rm_priority = get_int();
	m->rm_last_text_read = get_int();
	len = m->rm_read_texts_len = get_int();
	if (len) {
		int *txts, j;

		txts = malloc(sizeof(int) * len);
		get_accept('{');
		for (j = 0; j < len; j++)
			txts[j] = get_int();
		get_accept('}');
		m->rm_read_texts_val = txts;
	} else
		get_accept('*');
	m->rm_added_by = get_int();
	read_in_time(&m->rm_added_at);
	m->rm_type = get_int();

	mb->mid = m->rm_conference;
	mb->next = pp->next;
	pp->next = mb;
	get_accept('\n');
	return m;
}
Esempio n. 4
0
/*
 * XXX - should remember the membership structs also.
 */
u_int32_t *
rk_memberconf(u_int32_t uid)
{
	struct person_store *ps;
	int i, nconfs;

	ps = findperson(uid);
	if (ps == 0) {
		if (rk_persinfo(uid) == NULL)
			return NULL;
		ps = findperson(uid); /* Cannot fail here */
		if (ps == 0)
			printf("EEEK! Person %d finns inte!\n", uid);
	}
	if (ps->confs == NULL) {
		if (send_reply("46 %d 0 65535 0\n", uid)) {
			komerr = get_int();
			get_eat('\n');
			return NULL;
		}
		nconfs = get_int();
		ps->confs = calloc(sizeof(u_int32_t), nconfs+1);
		if (nconfs) {
			get_accept('{');
			for (i = 0; i < nconfs; i++) {
				struct rk_time t;

				read_in_time(&t);
				ps->confs[i] = get_int();
				get_int();get_int();get_int();get_accept('*');
			}
			get_accept('}');
		} else
			get_accept('*');
		get_accept('\n');
	}
	return ps->confs;
}
Esempio n. 5
0
void
newname(int uid)
{
	struct person_store *pp;
	struct get_conf_stat_store *walker;

	pp = findperson(uid);
	if (pp == 0)
		return;
	walker = findconf(uid);
	if (walker == 0)
		return;
	free(pp->person.rp_username);
	pp->person.rp_username = strdup(walker->confer.rc_name);
}
Esempio n. 6
0
static void
set_last_read_internal(int conf, int local)
{
	struct membership_store *mb;
	struct person_store *pp;

	if ((pp = findperson(myuid)) == 0)
		return; /* Nothing in cache */

	if (pp->next) {
		mb = findmember(conf, pp->next);
		if (mb == 0)
			return;
		mb->member.rm_last_text_read = local;
		if (mb->member.rm_read_texts_len) {
			free(mb->member.rm_read_texts_val);
			mb->member.rm_read_texts_val = NULL;
		}
		mb->member.rm_read_texts_len = 0;
	}
}
Esempio n. 7
0
/*
 * Return the person struct.
 */
struct rk_person *
rk_persinfo(u_int32_t uid)
{
	struct person_store *pp;
	struct rk_person *p;

	if ((pp = findperson(uid)))
		return &pp->person;

	if (send_reply("49 %d\n", uid)) {
		komerr = get_int();
		get_eat('\n');
		return NULL;
	}

	pp = calloc(sizeof(struct person_store), 1);
	pp->uid = uid;
	p = &pp->person;
	p->rp_username = get_string();
	p->rp_privileges = get_int();
	p->rp_flags = get_int();
	read_in_time(&p->rp_last_login);
	p->rp_user_area = get_int();
	p->rp_total_time_present = get_int();
	p->rp_sessions = get_int();
	p->rp_created_lines = get_int();
	p->rp_created_bytes = get_int();
	p->rp_read_texts = get_int();
	p->rp_no_of_text_fetches = get_int();
	p->rp_created_persons = get_int();
	p->rp_created_confs = get_int();
	p->rp_first_created_local_no = get_int();
	p->rp_no_of_created_texts = get_int();
	p->rp_no_of_marks = get_int();
	p->rp_no_of_confs = get_int();
	get_accept('\n');
	pp->nextp = gps;
	gps = pp;
	return p;
}
Esempio n. 8
0
void importlinkagepedigree (void)
{
  char minibuf[NAMESIZE];
  individual *ind, *ind2;
  

  //  IDlist *idlist;
  markerlist *marker;
  namelist *nl;
  quanttrait *qt;
  int i, families, persons, nmarkers, ntraits, code;

  printf("Number of markers in file: ");
  InputLine(buf, BUFFERSIZE);
  nmarkers = atoip(buf);

  printf("Number of traits in file : ");
  InputLine(buf, BUFFERSIZE);
  ntraits = atoip(buf);

  printf ("Name of linkage pedigree file to input: ");
  InputLine(buf, BUFFERSIZE);
  cfopen (buf,"r");

  getbuf ();

  persons = 0;
  families = 0;

  if (options->Index[O_CONVERTLINKAGEID])
    printf("WARNING: ID's are converted from number to fam-number\n");

  while (buf[0] != EOF)
  {

    // If empty line then read next line
    if (!buf[0] || !strpbrk(buf, "0123456789"))
    {
      getbuf ();
      continue;
    }

    ind = newperson ();
    persons++;
    ind->globalid = persons;
    ind->localid = persons;

    strcpy(ind->pedigree, igetstr (buf));
    strcpy(ind->id, getstr ());

    strcpy(ind->tmpstr1, getstr ()); // Father ID
    strcpy(ind->tmpstr2, getstr ()); // Mother ID

    // If conversion of IDs
    if (options->Index[O_CONVERTLINKAGEID]) {
      sprintf(minibuf,"%s-%s", ind->pedigree,ind->id);
      strcpy(ind->id,minibuf);
      sprintf(minibuf, "%s-%s", ind->pedigree,ind->tmpstr1);
      strcpy(ind->tmpstr1,minibuf);
      sprintf(minibuf, "%s-%s", ind->pedigree,ind->tmpstr2);
      strcpy(ind->tmpstr2,minibuf);
    }
    switch (geti ())
    {
      case  1 : ind->sex = S_MALE; break;
      case  2 : ind->sex = S_FEMALE; break;
      default : ind->sex = S_UNKNOWN;
    }
//    atof(getstr());

    for (i = 0 ; i<nmarkers; i++)
    {
      marker = cmalloc (sizeof (markerlist));
      memset (marker,0,sizeof (markerlist));
      marker->allele1 = geti();
      marker->allele2 = geti ();

      addlist(&ind->marker, marker);
    }

    // Reading traits
    for (i = 0 ; i<ntraits; i++)
    {
      qt = cmalloc (sizeof (quanttrait));
      memset (qt,0,sizeof (quanttrait));
      ReadATrait(qt);

      addlist(&ind->qttrait,qt);
    }

//    printf("\n");
    getbuf ();
  }

  fclose (F);
  printf ("%d persons from %d pedigree(s) read\n", 
          persons, numberofpedigrees());

  code = 0;
  // Should now fix fathers and mothers
  forind
  {
    ind->father = findperson(ind->tmpstr1);
    ind->mother = findperson(ind->tmpstr2);

    // if a person has a father and a mother, then add the
    //  person to the parents lists
    if (ind->father && ind->mother)
    {
      adduniqueidlist (&ind->father->offspring, ind);
      adduniqueidlist (&ind->father->mate, ind->mother);
      adduniqueidlist (&ind->mother->offspring, ind);
      adduniqueidlist (&ind->mother->mate,ind->father);
    }
    else if (ind->father || ind->mother) // The person has only one parent
      {
        code = 1;
        sprintf(buf2, "%s has only one parent in pedigree file\n", ind->id);
        WriteErrorMsg(buf2);
      }
     
  }

  if (code)
    printf("ERROR: A least one parent not found in pedigree file\n");

  // Fixing sibs
  forind
  {
    for (ind2 = ind->next; ind2; ind2 = ind2->next)
    {
      // If same father or mother then add to list of both
      if (((ind->father == ind2->father) && (ind->father)) || 
          ((ind->mother == ind2->mother) && (ind->mother)))
      {
        adduniqueidlist(&ind->sib, ind2);
        adduniqueidlist(&ind2->sib, ind);
      }
    }
  }

  // Have now read the file and made the dataset
  // Should fix the missing parts
  // This part definately needs some error checking

  // First set the marker names:
  for (i=1; i<=nmarkers; i++)
  {
    nl = cmalloc (sizeof (namelist));
    memset (nl,0,sizeof (namelist));

    sprintf(nl->name, "Marker %d",i);
    addlist(&markernames, nl);
  }

  // Then add trait names
  for (i=1; i<=ntraits; i++)
  {
    nl = cmalloc (sizeof (namelist));
    memset (nl,0,sizeof (namelist));

    sprintf(nl->name, "Trait %d",i);
    addlist(&traitnames, nl);
  }

  InitializeFrequencies(nmarkers);

  // Initialize order and distances
  order = ivector(1,nmarkers);
  invorder = ivector(1,nmarkers);
  distance = vector(1, nmarkers-1);
  for (i=1; i<=nmarkers; i++)
  {
    order[i] = i;
    invorder[i] = i;
  }

  for (i=1; i<nmarkers; i++)
    distance[i] = InverseMapFunction(0.1);
  
}