Ejemplo n.º 1
0
SEXP
read_mtp(SEXP fname)
{
    FILE *f;
    char buf[MTP_BUF_SIZE], blank[1], *pres;
    MTB  *mtb, thisRec;
    int i, j, res, nMTB = MTB_INITIAL_ENTRIES;

    PROTECT(fname = asChar(fname));
#ifdef WIN32 /* force text-mode read */
    if ((f = fopen(R_ExpandFileName(CHAR(fname)), "rt")) == NULL)
#else
    if ((f = fopen(R_ExpandFileName(CHAR(fname)), "r")) == NULL)
#endif
	error(_("unable to open file '%s': '%s'"), 
	      CHAR(fname), strerror(errno));
    if ((fgets(buf, MTP_BUF_SIZE, f) == NULL) ||
	strncmp(buf, "Minitab Portable Worksheet ", 27) != 0)
	error(_("file '%s' is not in Minitab Portable Worksheet format"),
	      CHAR(fname));
    pres = fgets(buf, MTP_BUF_SIZE, f);
    if(pres != buf) error(_("file read error"));
    UNPROTECT(1);

    mtb = Calloc(nMTB, MTB);
    for (i = 0; !feof(f); i++) {
	if (i >= nMTB) {
	    nMTB *= 2;
	    mtb = Realloc(mtb, nMTB, MTB);
	}
	thisRec = mtb[i] = Calloc(1, MTBDATC);
	if (sscanf(buf, "%%%7d%7d%7d%7d%c%8c", &(thisRec->type),
		   &(thisRec->cnum), &(thisRec->len),
		   &(thisRec->dtype), blank, thisRec->name) != 6)
	    error(_("first record for entry %d is corrupt"), i+1);
	thisRec->name[8] = '\0';
	strtrim(thisRec->name);	/* trim trailing white space on name */
	switch (thisRec->dtype) {
	case 0:		/* numeric data */
	    thisRec->dat.ndat = Calloc(thisRec->len, double);
	    for (j = 0; j < thisRec->len; j++) {
		res = fscanf(f, "%lg", thisRec->dat.ndat + j);
		if(res == EOF) error(_("file read error"));
	    }
	    break;
	default:
	    if (thisRec->type == 4) { /* we have a matrix so dtype is number of columns */
		thisRec->dat.ndat = Calloc(thisRec->len, double);
		for (j = 0; j < thisRec->len; j++) {
		    res = fscanf(f, "%lg", thisRec->dat.ndat + j);
		    if(res == EOF) error(_("file read error"));
		}
	    } else {
		error(_("non-numeric data types are not yet implemented"));
	    }
	}
Ejemplo n.º 2
0
SLABELS *CreateSLabels(void){
  uint32_t n;
  SLABELS *SL = (SLABELS *) Calloc(1, sizeof(SLABELS));
  SL->idx     = 0;
  SL->maxV    = SLCACHE;
  SL->maxH    = SLMAXSTR;
  SL->names   = (uint8_t **) Calloc(SL->maxV, sizeof(uint8_t *));
  for(n = 0 ; n < SL->maxV ; ++n)
    SL->names[n] = (uint8_t *) Calloc(SL->maxH+1, sizeof(uint8_t));
  return SL;
  }
Ejemplo n.º 3
0
/**
 * Establish a fill-reducing permutation for the sparse symmetric
 * matrix of order n represented by the column pointers Tp and row
 * indices Ti.
 *
 * @param n  order of the sparse symmetric matrix
 * @param Tp  column pointers (total length n + 1)
 * @param Ti  row indices (total length Tp[n])
 * @param Perm array of length n to hold the permutation
 * @param iPerm array of length n to hold the inverse permutation
 *
 */
void ssc_metis_order(int n, const int Tp [], const int Ti [],
                     int Perm[], int iPerm[])
{
    int  j, num_flag = 0, options_flag = 0;
    idxtype
    *perm = Calloc(n, idxtype), /* in case idxtype != int */
     *iperm = Calloc(n, idxtype),
      *xadj = Calloc(n+1, idxtype),
       *adj = Calloc(2 * (Tp[n] - n), idxtype);

    /* check row indices for correct range */
    for (j = 0; j < Tp[n]; j++)
        if (Ti[j] < 0 || Ti[j] >= n)
            error(_("row index Ti[%d] = %d is out of range [0,%d]"),
                  j, Ti[j], n - 1);
    /* temporarily use perm to store lengths */
    AZERO(perm, n);
    for (j = 0; j < n; j++) {
        int ip, p2 = Tp[j+1];
        for (ip = Tp[j]; ip < p2; ip++) {
            int i = Ti[ip];
            if (i != j) {
                perm[i]++;
                perm[j]++;
            }
        }
    }
    xadj[0] = 0;
    for (j = 0; j < n; j++) xadj[j+1] = xadj[j] + perm[j];
    /* temporarily use perm to store pointers */
    Memcpy(perm, xadj, n);
    for (j = 0; j < n; j++) {
        int ip, p2 = Tp[j+1];
        for (ip = Tp[j]; ip < p2; ip++) {
            int i = Ti[ip];
            if (i != j) {
                adj[perm[i]] = j;
                adj[perm[j]] = i;
                perm[i]++;
                perm[j]++;
            }
        }
    }
    METIS_NodeND(&n, xadj, adj, &num_flag, &options_flag, perm, iperm);
    for (j = 0; j < n; j++) {
        Perm[j] = (int) perm[j];
        iPerm[j] = (int) iperm[j];
    }
    Free(iperm);
    Free(perm);
    Free(xadj);
    Free(adj);
}
Ejemplo n.º 4
0
/*
 *  woo.. no args? we use CurrentChan, CurrentNick and CurrentUser.
 */
void greet(void)
{
	Strp	*sp,**pp;
	char	linebuf[MSGLEN],readbuf[MSGLEN];
	char	*str;
	int	fd,sz;

	pp = &current->sendq;
	while(*pp)
		pp = &(*pp)->next;

	if (CurrentUser->x.x.greetfile)
	{
		if ((fd = open(CurrentUser->greet,O_RDONLY)) < 0)
			return;

		sz = sizeof(Strp) + 9 + strlen(CurrentNick);

		memset(readbuf,0,sizeof(readbuf));
		while(TRUE)
		{
			str = sockread(fd,readbuf,linebuf);
			if (str)
			{
				*pp = sp = (Strp*)Calloc(sz + strlen(str));
				/* Calloc sets to zero sp->next = NULL; */
				pp = &sp->next;
				sprintf(sp->p,"NOTICE %s :%s",CurrentNick,str);
			}
			else
			if (errno != EAGAIN)
				break;
		}

		close(fd);
	}
	else
	if (CurrentUser->x.x.randline)
	{
		if ((str = randstring(CurrentUser->greet)))
			goto single_line;
		return;
	}
	else
	{
		str = CurrentUser->greet;
single_line:
		*pp = sp = (Strp*)Calloc(sizeof(Strp) + 13 + Strlen(CurrentChan->name,CurrentNick,str,NULL));
		sprintf(sp->p,"PRIVMSG %s :[%s] %s",CurrentChan->name,CurrentNick,str);
		/* Calloc sets to zero sp->next = NULL; */
	}
}
Ejemplo n.º 5
0
Archivo: mi.c Proyecto: cran/rsgcc
int make_mi(mi_t* const m, const int n, const int k) {
  if (n < k) return 0;

  m->k = k;
  m->n = n;
  init_psi(m);
  m->sxs  = Calloc(n, coord_t);
  m->xiis = Calloc(n, int);
  m->sys  = Calloc(n, coord_t);
  m->yiis = Calloc(n, int);

  return 1;
}
Ejemplo n.º 6
0
Archivo: lh.c Proyecto: mcromaz/petcat
lh *lh_init(char *name, int dim) {
  lh *x;

  assert(name != 0);			/* pre */
  assert(dim > 0 && dim < LH_MAX_DIM);

  x = Calloc(1, sizeof(lh));
  x->name = name;
  x->h = Calloc(dim, sizeof(float));
  x->dim = dim;
  x->cnt = 0, x->outlyers = 0;
  return x;
}
Ejemplo n.º 7
0
CModel *CreateCModel(uint32_t ctxSize, uint32_t nSymbols, uint32_t deltaNum, 
	uint32_t deltaDen)
{
	uint32_t  n, prod = 1;
	CModel    *cModel;

	if(ctxSize < 1)
	{
		fprintf(stderr, "Error (CreateCModel): context size must be greater than 0!\n");
		fprintf(stderr, "Error (CreateCModel): context size read = %"PRIu32"\n", ctxSize);
		exit(EXIT_FAILURE);
	}
	
	if(nSymbols < 1)
	{
		fprintf(stderr, "Error (CreateCModel): number of symbols must be greater than 0!\n");
		fprintf(stderr, "Error (CreateCModel): number of symbols read = %"PRIu32"\n", nSymbols);
		exit(EXIT_FAILURE);
	}

	cModel               = (CModel   *) Calloc(1,       sizeof(CModel  ));
	cModel->multipliers  = (uint32_t *) Calloc(ctxSize, sizeof(uint32_t));
	cModel->nPModels     = (uint64_t)   pow(nSymbols, ctxSize);
	cModel->ctxSize      = ctxSize;
	cModel->nSymbols     = nSymbols;
	cModel->pModelIdx    = 0;
	cModel->deltaNum = deltaNum;
	cModel->deltaDen = deltaDen;

	switch(nSymbols)
	{
    	case 2:
			cModel->kMinusOneMask = (0x01 << (ctxSize - 1)) - 1;
			break;

		case 4:
			cModel->kMinusOneMask = (0x01 << 2 * (ctxSize - 1)) - 1;
			break;
    }

	for(n = 0 ; n != ctxSize ; ++n)
    {
		cModel->multipliers[n] = prod;
    	prod                  *= nSymbols;
    }
	
	cModel->counters = (ACCounter *) Calloc(cModel->nPModels * nSymbols,
		sizeof(ACCounter));
	return cModel;
}
Ejemplo n.º 8
0
void ShowTemplate(CTemplate *cTemplate)
{
	int8_t minRow, maxRow, minCol, maxCol, n, row, col;
	int8_t **templateMatrix=NULL;
	minRow = maxRow = cTemplate->position[0].row;
	minCol = maxCol = cTemplate->position[0].col;
  
	for(n = 1 ; n != cTemplate->size ; ++n)
 	{
		if(cTemplate->position[n].row > maxRow)
			maxRow = cTemplate->position[n].row;

		if(cTemplate->position[n].row < minRow)
			minRow = cTemplate->position[n].row;

		if(cTemplate->position[n].col > maxCol)
			maxCol = cTemplate->position[n].col;

		if(cTemplate->position[n].col < minCol)
			minCol = cTemplate->position[n].col;
	}

	templateMatrix = (int8_t **)Calloc(maxRow - minRow + 2, sizeof(int8_t *));

	for(row = 0 ; row != maxRow - minRow + 2 ; ++row)
		templateMatrix[row] = (int8_t *)Calloc(maxCol - minCol + 2, sizeof(int8_t));
	
	for(n = 0 ; n < cTemplate->size ; n++)
		templateMatrix[cTemplate->position[n].row - minRow][cTemplate->position[n].col - minCol] = n + 1;

	templateMatrix[-minRow][-minCol] = -1;
	for(row = 0 ; row != maxRow - minRow + 2 ; ++row)
	{
		for(col = 0 ; col != maxCol - minCol + 2 ; ++col)
			if(templateMatrix[row][col])
			{
				if(templateMatrix[row][col] == -1)
					printf("  X");
				else
					printf("%3"PRIu8"", templateMatrix[row][col]);
			}
			else printf("   ");

		putchar('\n');
	}
	
  	for(row = 0 ; row != maxRow - minRow + 2 ; ++row)
  		Free(templateMatrix[row], (maxCol-minCol+2)* sizeof(int8_t));
  	Free(templateMatrix, (maxRow - minRow + 2) * sizeof(int8_t *));
}
Ejemplo n.º 9
0
/*********************
 void WtMHProposalInitialize

 A helper function to process the MH_* related initialization.
*********************/
WtMHProposal *WtMHProposalInitialize(
	     char *MHProposaltype, char *MHProposalpackage, 
	       double *inputs,
	     int fVerbose,
	     WtNetwork *nwp){
  WtMHProposal *MHp = Calloc(1, WtMHProposal);

  char *fn, *sn;
  int i;
  for (i = 0; MHProposaltype[i] != ' ' && MHProposaltype[i] != 0; i++);
  MHProposaltype[i] = 0;
  /* Extract the required string information from the relevant sources */
  fn = Calloc(i+4, char);
  fn[0]='M';
  fn[1]='H';
  fn[2]='_';
  for(int j=0;j<i;j++)
    fn[j+3]=MHProposaltype[j];
  fn[i+3]='\0';
  /* fn is now the string 'MH_[name]', where [name] is MHProposaltype */
  for (i = 0; MHProposalpackage[i] != ' ' && MHProposalpackage[i] != 0; i++);
  MHProposalpackage[i] = 0;
  sn = Calloc(i+1, char);
  sn=strncpy(sn,MHProposalpackage,i);
  sn[i]='\0';
  
  /* Search for the MH proposal function pointer */
  MHp->func=(void (*)(WtMHProposal*, WtNetwork*)) R_FindSymbol(fn,sn,NULL);
  if(MHp->func==NULL){
    error("Error in MH_* initialization: could not find function %s in "
	  "namespace for package %s."
	  "Memory has not been deallocated, so restart R sometime soon.\n",fn,sn);
  }

  MHp->inputs=inputs;
  
  MHp->discord=NULL;

  /*Clean up by freeing sn and fn*/
  Free(fn);
  Free(sn);

  MHp->ntoggles=0;
  (*(MHp->func))(MHp, nwp); /* Call MH proposal function to initialize */
  MHp->toggletail = (Vertex *)Calloc(MHp->ntoggles, Vertex);
  MHp->togglehead = (Vertex *)Calloc(MHp->ntoggles, Vertex);
  MHp->toggleweight = (double *)Calloc(MHp->ntoggles, double);

  return MHp;
}
Ejemplo n.º 10
0
word_t *
compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa)
/*
 *  Selects the 'n' most popular domain images of the given 'wfa'.
 *  Consider only linear combinations of state images
 *  {i | 'from' <= i <= 'to'}. I.e. domains are in {i | from <= i < 'to'}
 *  Always ensure that state 0 is among selected states even though from
 *  may be > 0.
 *  
 *  Return value:
 *	pointer to array of the most popular state images
 *	sorted by increasing state numbers and terminated by -1
 */
{
   word_t   *domains;
   unsigned  state, label, edge;
   int       domain;
   pair_t   *hits = Calloc (to, sizeof (pair_t));

   for (domain = 0; domain < (int) to; domain++)
   {
      hits [domain].value = domain;
      hits [domain].key   = 0;
   }
   
   for (state = from; state <= to; state++)
      for (label = 0; label < MAXLABELS; label++)
	 for (edge = 0; isedge (domain = wfa->into [state][label][edge]);
	      edge++)
	    hits [domain].key++;

   qsort (hits + 1, to - 1, sizeof (pair_t), sort_desc_pair);

   n       = min (to, n);
   domains = Calloc (n + 1, sizeof (word_t));

   for (domain = 0; domain < (int) n && (!domain || hits [domain].key);
	domain++)
      domains [domain] = hits [domain].value;
   if (n != domain)
      debug_message ("Only %d domains have been used in the luminance.",
		     domain);
   n = domain;
   qsort (domains, n, sizeof (word_t), sort_asc_word);
   domains [n] = -1;
   
   Free (hits);
   
   return domains;
}
Ejemplo n.º 11
0
S32 main()
{
    S32 ret;
    U32 length;
    U8  *keySalt;
    U8  *base64KeySalt;
    U8  index;

    /* Create a memory pool */
    pool = CreateMemoryPool(MEMORY_POOL_SIZE);
    if (pool == NULL)
    {
		DP("Memory pool failed to be created.\n");
        return RFAILED;
    }

    length = ((KEY_SALT_ORIG_LEN + 2) / 3) * 4 + 1;
    base64KeySalt = (U8 *)Calloc(pool, length);
    keySalt = (U8 *)Calloc(pool, KEY_SALT_ORIG_LEN);

    /* create master key and salt */
    DP("1. Start to create master key and salt...\n\n");
    ret = CreateCryptoKeySalt(base64KeySalt);
    if (ret != ROK)
    {
        DP("Master key and salt could not be created.\n");
        return ret;
    }
    DP("Base64 master key and salt[%d]:\n\"%s\"\n\n", strlen(base64KeySalt), base64KeySalt);

    /* base64 decoding */
    DP("2. Start to base64 decode master key and salt...\n\n");
    ret = Base64Decode(base64KeySalt, length - 1, keySalt);
    if (ret != ROK)
    {
        DP("Master key and salt could not be decoded.\n");
        return ret;
    }

    DP("Master key and salt:\n");
    for (index = 0; index < KEY_SALT_ORIG_LEN; index++)
    {
        DP("0x%02x ", keySalt[index]);
    }
    DP("\n\n");

    /* Destroy a memory pool */
    DestroyMemoryPool(pool);
    return ROK;
}
Ejemplo n.º 12
0
Archivo: hyper.c Proyecto: juddy/edcde
void
AddID(Element *e, char *idval)
{
    static ID *id_last;
    if (!IDList) {
	Calloc(1, id_last, ID);
	IDList = id_last;
    }
    else {
	Calloc(1, id_last->next, ID);
	id_last = id_last->next;
    }
    id_last->elem = e;
    id_last->id   = idval;
}
Ejemplo n.º 13
0
Archivo: hbhankel.c Proyecto: asl/rssa
static void initialize_circulant(hbhankel_matrix *h,
                                 const double *F,
                                 R_len_t rank,
                                 const R_len_t *N,
                                 const R_len_t *L,
                                 const int *circular) {
  fftw_complex *ocirc;
  fftw_plan p1, p2;
  double *circ;
  R_len_t *revN, r;

  /* Allocate needed memory */
  circ = (double*) fftw_malloc(prod(rank, N) * sizeof(double));
  ocirc = (fftw_complex*) fftw_malloc(hprod(rank, N) * sizeof(fftw_complex));

  /* Estimate the best plans for given input length, note, that input data is
     stored in column-major mode, that's why we're passing dimensions in
     *reverse* order */
  revN = Calloc(rank, R_len_t);
  for (r = 0; r < rank; ++r) revN[r] = N[rank - 1 - r];
  p1 = fftw_plan_dft_r2c(rank, revN, circ, ocirc, FFTW_ESTIMATE);
  p2 = fftw_plan_dft_c2r(rank, revN, ocirc, circ, FFTW_ESTIMATE);
  Free(revN);

  /* Fill input buffer */
  memcpy(circ, F, prod(rank, N) * sizeof(double));

  /* Run the plan on input data */
  fftw_execute(p1);

  /* Cleanup and return */
  fftw_free(circ);

  h->circ_freq = ocirc;
  h->r2c_plan = p1;
  h->c2r_plan = p2;

  h->rank = rank;

  h->window = Calloc(rank, R_len_t);
  memcpy(h->window, L, rank * sizeof(R_len_t));

  h->length = Calloc(rank, R_len_t);
  memcpy(h->length, N, rank * sizeof(R_len_t));

  h->factor = Calloc(rank, R_len_t);
  for (r = 0; r < rank; ++r) h->factor[r] = circular[r] ? N[r] : N[r] - L[r] + 1;
}
Ejemplo n.º 14
0
/*---------------------------------------*/
void mulcol(csr_t *A, options_t *opts,
            precon_t *prec, int *perm) {
    /*---------------------------------------*/
    PREC_TYPE ptype;
    int n,i,maxcol,ncol,*kolrs,*il,err;
    csr_t *C;
    /*---------------------------------------*/
    n = A->n;
    ptype = opts->prectype;
    printf("begin MULTI-COLOR ...\n");
    /*------- symetrize matrix */
    Calloc(C, 1, csr_t);
    symmgraph(A, C);
    /*-------- multi-color reordering */
    if (ptype == MCSOR)
        maxcol = opts->mcsor_opt->maxcol;
    else
        maxcol = opts->mcilu0_opt->maxcol;
    /*---------------------*/
    Calloc(kolrs, n, int);
    Calloc(il, maxcol+1, int);
    /*-------- input node order */
    for (i=0; i<n; i++) perm[i] = i+1;
    /*-------- multi-coloring, greedy alg */
    multic_(&n, C->ja, C->ia, &ncol, kolrs,
            il, perm, &maxcol, &err);
    if (err != 0) {
        printf("exceed max num of colors\n");
        exit(-1);
    }
    printf("  done, %d colors\n", ncol);
    /*-----------------------*/
    if (ptype == MCSOR) {
        Calloc(prec->mcsor, 1, mcsor_prec_t);
        prec->mcsor->ncol = ncol;
        prec->mcsor->kolrs = kolrs;
        prec->mcsor->il = il;
    } else {
        Calloc(prec->mcilu0, 1, mcilu0_prec_t);
        prec->mcilu0->ncol = ncol;
        prec->mcilu0->kolrs = kolrs;
        prec->mcilu0->il = il;
    }
    /*----------------- done */
    free(C->ja);
    free(C->ia);
    free(C);
}
Ejemplo n.º 15
0
Archivo: lh.c Proyecto: mcromaz/petcat
lh *lh_init_ia(char *name, int *h, int dim) {

  lh *x;
  int i;

  x = Calloc(1, sizeof(lh));
  x->name = name;
  x->h = Calloc(dim, sizeof(float));
  x->dim = dim;
  for (i = 0; i < x->dim; i++) {
    x->h[i] = (float) h[i];
    x->cnt += h[i];
  }
  x->outlyers = 0;
  return x;
}
Ejemplo n.º 16
0
cache *initialize_cache(){
	cache *proxy_cache = Calloc(1, sizeof(cache));
	proxy_cache->start = NULL;
	proxy_cache->end = NULL;
	proxy_cache->cache_size = 0;
	return proxy_cache;
}
double *Nonlinear_equation(double *magnitude, double *phase)
  { 
    extern int ngin();
    int m,n,i,ka;
    double eps1,eps2;
    void nginf(int,int,double [],double []);
    void ngins(int,int,double [],double [][4]);
    double *x;
   
    x = Calloc(4 , sizeof(double));   
    x[0] = 5400.0;
    x[1] = 340.0;
    x[2] = 0.5;
    x[3] = 0.4;
    
    m=In_vect_n*In_vect_n; n=4; ka=m+1; eps1=0.0000000001; eps2=0.00000001;
    i=ngin(m,n,eps1,eps2,x,ka,nginf,ngins,magnitude,phase);
    printf("\n");
    printf("i=%d\n",i);
    printf("\n");
    for (i=0; i<=3; i++)
      printf("x[%d]=%13.7e\n",i,x[i]);
    printf("\n");
	return x;
  }
Ejemplo n.º 18
0
int
main(int argc, char **argv)
{
	int			listenfd, i;
	socklen_t	addrlen;
	void		sig_int(int);
	pid_t		child_make(int, int, int);

	if (argc == 3)
		listenfd = Tcp_listen(NULL, argv[1], &addrlen);
	else if (argc == 4)
		listenfd = Tcp_listen(argv[1], argv[2], &addrlen);
	else
		err_quit("usage: serv03 [ <host> ] <port#> <#children>");
	nchildren = atoi(argv[argc-1]);
	pids = Calloc(nchildren, sizeof(pid_t));
	cptr = meter(nchildren);

	my_lock_init("/tmp/lock.XXXXXX");	/* one lock file for all children */
	for (i = 0; i < nchildren; i++)
		pids[i] = child_make(i, listenfd, addrlen);	/* parent returns */

	Signal(SIGINT, sig_int);

	for ( ; ; )
		pause();	/* everything done by children */
}
Ejemplo n.º 19
0
/*========================================================================*/
int ControlInit(PyMOLGlobals * G)
{
  register CControl *I = NULL;

  if((I = (G->Control = Calloc(CControl, 1)))) {

    I->Block = OrthoNewBlock(G, NULL);
    I->Block->fClick = ControlClick;
    I->Block->fDraw = ControlDraw;
    I->Block->fDrag = ControlDrag;
    I->Block->fRelease = ControlRelease;
    I->Block->fReshape = ControlReshape;
    I->Block->active = true;
    I->Block->TextColor[0] = 1.0;
    I->Block->TextColor[1] = 0.75;
    I->Block->TextColor[2] = 0.75;
    I->ButtonColor[0] = 0.5F;
    I->ButtonColor[1] = 0.5F;
    I->ButtonColor[2] = 0.5F;
    I->ActiveColor[0] = 0.65F;
    I->ActiveColor[1] = 0.65F;
    I->ActiveColor[2] = 0.65F;
    I->Pressed = -1;
    I->Active = -1;
    OrthoAttach(G, I->Block, cOrthoTool);
    I->SaveWidth = 0;
    I->LastClickTime = UtilGetSeconds(G);
    I->NButton = 9;
    return 1;
  } else
    return 0;
}
Ejemplo n.º 20
0
void do_note(COMMAND_ARGS)
{
	User	*u;
	Note	*n;
	Strp	*sp,**np;
	char	header[MSGLEN];

	/*
	 *  no-args is handled in on_msg()
	 */
	if (!(u = find_handle(rest)))
	{
		to_user(from,TEXT_UNKNOWNUSER,rest);
		return;
	}
	to_user(from,"Enter your note for %s, end with \".\" on a line by itself",
		u->name);

	set_mallocdoer(do_note);
	n = Calloc(sizeof(Note) + StrlenX(from,to,u->name,NULL));
	n->start = now;
	n->next = notelist;
	notelist = n;

	n->to = stringcat(n->from,from) + 1;
	n->user = stringcat(n->to,to) + 1;
	stringcpy(n->user,rest);

	/*
	 *  add a note header
	 */
	sprintf(header,"\001%s %s",from,time2str(now));
	append_strp(&u->note,header);
}
Ejemplo n.º 21
0
Archivo: kheader.c Proyecto: klopp/knet
int hdr_AddTextHeader( msg_Headers headers, const char * key,
        const char * value )
{
    msg_Header header = hdr_FindHeader( headers->text, key );

    if( !header )
    {
        header = Calloc( sizeof(struct _msg_Header), 1 );
        if( !header ) return 0;
        header->name = Strdup( key );
        if( !header->name )
        {
            Free( header );
            return 0;
        }
        header->values = slcreate();
        if( !header->values )
        {
            del_Header( header );
            return 0;
        }
        if( !sladd( header->values, value ) )
        {
            del_Header( header );
            return 0;
        }
    }

    return ladd( headers->text, header ) != NULL;
}
Ejemplo n.º 22
0
static BAM_FILE _bamfile_open_r(SEXP filename, SEXP indexname, SEXP filemode)
{
    BAM_FILE bfile = (BAM_FILE) Calloc(1, _BAM_FILE);

    bfile->file = NULL;
    if (0 != Rf_length(filename)) {
        const char *cfile = translateChar(STRING_ELT(filename, 0));
        bfile->file = _bam_tryopen(cfile, CHAR(STRING_ELT(filemode, 0)), 0);
        if ((bfile->file->type & TYPE_BAM) != 1) {
            samclose(bfile->file);
            Free(bfile);
            Rf_error("'filename' is not a BAM file\n  file: %s", cfile);
        }
        bfile->pos0 = bam_tell(bfile->file->x.bam);
        bfile->irange0 = 0;
    }

    bfile->index = NULL;
    if (0 != Rf_length(indexname)) {
        const char *cindex = translateChar(STRING_ELT(indexname, 0));
        bfile->index = _bam_tryindexload(cindex);
        if (NULL == bfile->index) {
            samclose(bfile->file);
            Free(bfile);
            Rf_error("failed to open BAM index\n  index: %s\n", cindex);
        }
    }

    bfile->iter = NULL;
    bfile->pbuffer = NULL;
    return bfile;
}
Ejemplo n.º 23
0
void * Calloc0(int size)
{
	void * mem=Calloc(size);
	if(mem!=NULL)
		Memset(mem,0,size);
	return mem;
}
Ejemplo n.º 24
0
static bcspec_t *
bcspec_new(plugin_t * plt, octet_t * spec)
{
	octet_t         oct;
	bcspec_t       *bcs = 0;
	plugin_t       *p;
	int             n;

	/*
	 * two parts name ":" typespec 
	 */
	if ((n = octchr(spec, ':')) < 0) {
		oct_print( LOG_ERR,
		    "Error in boundary condition specification", spec);
		return 0;
	}

	oct.len = spec->len - n - 1;
	oct.val = spec->val + n + 1;
	spec->len = n;

	if ((p = plugin_match(plt, spec)) == 0) {
		traceLog(LOG_ERR,"Doesn't match any known plugin",spec);
		return 0;
	}

	bcs = (bcspec_t *) Calloc(1,sizeof(bcspec_t));

	bcs->plugin = p;
	bcs->name = oct2strdup(spec, 0);
	bcs->spec = octdup(&oct);

	return bcs;
}
Ejemplo n.º 25
0
Archivo: pivot.c Proyecto: cran/WGCNA
SEXP qorder(SEXP data)
{
  R_xlen_t n = Rf_xlength(data);

  // Rprintf("qorder: length of input data is %ld.\n", n);

  double * x = REAL(data);

  orderStructure * os = Calloc((size_t) n, orderStructure);

  qorder_internal(x, (size_t) n, os);

  SEXP ans;
  if (n<(size_t) 0x80000000)
  {
    // Rprintf("..returning integer order.\n");
    PROTECT (ans = allocVector(INTSXP, n));
    int * ansp = INTEGER(ans);
    for (R_xlen_t i = 0; i<n; i++) ansp[i] = (int) ( (os+i)->index+1);
  } else {
    // Rprintf("..returning floating point (double) order.\n");
    PROTECT (ans = allocVector(REALSXP, n));
    double * ansp = REAL(ans);
    for (R_xlen_t i = 0; i<n; i++) ansp[i] = (double) ((os+i)->index+1);
  }
  Free(os);
  UNPROTECT(1);
  return ans;
}
Ejemplo n.º 26
0
Associate* makeLAA(int arraySize,int patternSize){
	Associate *result=Calloc(Associate,1);
	result->keys=Calloc(int,arraySize*patternSize);
	result->patternSize=patternSize;
	result->array=Calloc(void*,arraySize);
	return result;
}
Ejemplo n.º 27
0
static void
db_print_forward_references(void) {
	size_t n;
	size_t *printed_at =
		(size_t *)Calloc(Text_Length(), sizeof (size_t));

	for (n = 1; n < Text_Length(); n++) {
		size_t fw = forward_reference[n];
		if (fw == 0) continue;
		fprintf(Debug_File, "FWR[%s]:", any_uint2string(n, 0));
		if (printed_at[fw]) {
			fprintf(Debug_File, " see %s",
				any_uint2string(printed_at[fw], 0));
		}
		else {
			while (fw) {
				fprintf(Debug_File, " %s",
					any_uint2string(fw, 0));
				printed_at[fw] = n;
				fw = forward_reference[fw];
			}
		}
		fprintf(Debug_File, "\n");
	}
	Free((void *)printed_at);
}
Ejemplo n.º 28
0
Archivo: hash.c Proyecto: kaitoh/lispi
static void rehash(st_table *table)
{
	int new_num_bins = table->num_bins+NUM_INCREMENT_REHASH;
	st_table_entry **new_bins = (st_table_entry**)Calloc(new_num_bins, sizeof(st_table_entry*));
	int i;

	for(i=0 ; i < new_num_bins ; i++) {
		new_bins[i] = NULL;
	}

	for(i=0 ; i < table->num_bins ; i++) {
		st_table_entry *next;
		st_table_entry *entry = table->bins[i];
		while(entry) {
			int pos = entry->hash % new_num_bins;
			next = entry->next;
			entry->next = new_bins[pos];
			new_bins[pos] = entry;
			entry = next;
		}
	}
	li_free(table->bins);
	table->bins = new_bins;
	table->num_bins = new_num_bins;
}
Ejemplo n.º 29
0
video_t *
alloc_video (bool_t store_wfa)
/*
 *  Video struct constructor:
 *  Initialize video structure and allocate memory for current, past
 *  and future WFA if flag 'store_wfa' is TRUE.
 *
 *  Return value:
 *	pointer to the new video structure
 */
{
   video_t *video = Calloc (1, sizeof (video_t));
   
   video->future_display = -1;
   video->display        = 0;

   video->future = video->sfuture = video->past
		 = video->frame   = video->sframe = NULL;

   if (store_wfa)
   {
      video->wfa        = alloc_wfa (NO);
      video->wfa_past   = alloc_wfa (NO);
      video->wfa_future = alloc_wfa (NO);
   }
   else
      video->wfa = video->wfa_past = video->wfa_future = NULL;

   return video;
}
Ejemplo n.º 30
0
/* Returns non-zero if everbody agrees on the leader */
int
LeaderAgreed(void)
{
	List		list;
	host_rec	*item;
	IPADDRESS	leader;
	struct sockaddr_in	*sap;

	list = hcp->hrecs;

	for (item = (host_rec *)listGetFirstItem(list), leader = item->primary;\
		item; item = (host_rec *)listGetNextItem(list, item)) {
		if (item->primary != leader)
			return(0);
	}

	/* Everybody agrees on the leader. Let's fill in his address */
//	LockGetLock(hcp_lock, 0, 0);
	sap = (struct sockaddr_in *)hcp->pri_sa =  Calloc(sizeof(struct sockaddr_in), 1);
	sap->sin_family = AF_INET;
	sap->sin_addr.s_addr = leader;
	sap->sin_port = htons(atoi(rs_port));
//	LockReleaseLock(hcp_lock);

	return(1);
}