Example #1
0
void register_long_option(struct optstruct *opt, const char *optname)
{
	struct optnode *newnode;
	int i, found = 0;


    if(clamdscan_mode) {
	for(i = 0; clamdscan_long[i]; i++)
	    if(!strcmp(clamdscan_long[i], optname))
		found = 1;

	if(!found) {
	    mprintf("WARNING: Ignoring option --%s: please edit clamd.conf instead.\n", optname);
	    return;
	}
    }

    newnode = (struct optnode *) mmalloc(sizeof(struct optnode));
    newnode->optchar = 0;
    if(optarg != NULL) {
	newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char));
	strcpy(newnode->optarg, optarg);
    } else newnode->optarg = NULL;

    newnode->optname = (char *) mcalloc(strlen(optname) + 1, sizeof(char));
    strcpy(newnode->optname, optname);
    newnode->next = opt->optlist;
    opt->optlist = newnode;
}
Example #2
0
void *_MemoryCacheCalloc(PyMOLGlobals * G, unsigned int number, unsigned int size,
                         int group_id, int block_id MD_FILE_LINE_Decl)
{
  if((group_id < 0) || (!SettingGetGlobal_b(G, cSetting_cache_memory)))
    return (mcalloc(number, size));

  {
    register CMemoryCache *I = G->MemoryCache;
    register MemoryCacheRec *rec = &I->Cache[group_id][block_id];
    unsigned int true_size = number * size;

    /* interesting result: calloc is faster than cacheing */

    if(!rec->ptr) {
      rec->size = true_size;
      rec->ptr = mcalloc(number, size);
    } else if(rec->size < true_size) {
      mfree(rec->ptr);
      rec->size = true_size;
      rec->ptr = mcalloc(number, size);
    } else {
      mfree(rec->ptr);
      rec->size = true_size;
      rec->ptr = mcalloc(number, size);
    }
    return (rec->ptr);
  }
}
Example #3
0
void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt)
{
    pid_t pid;
    struct cfgstruct *cpt;

    if(!(cpt = cfgopt(copt, "VirusEvent")))
        return;

    /* NB: we need to fork here since this function modifies the environment.
       (Modifications to the env. are not reentrant, but we need to be.) */
    pid = fork();

    if ( pid == 0 ) {
        /* child... */
        char *buffer, *pt, *cmd;

        cmd = strdup(cpt->strarg);

        if((pt = strstr(cmd, "%v"))) {
            buffer = (char *) mcalloc(strlen(cmd) + strlen(virname) + 10, sizeof(char));
            *pt = 0;
            pt += 2;
            strcpy(buffer, cmd);
            strcat(buffer, virname);
            strcat(buffer, pt);
            free(cmd);
            cmd = strdup(buffer);
            free(buffer);
        }

        /* Allocate env vars.. to be portable env vars should not be freed */
        buffer = (char *) mcalloc(strlen(ENV_FILE) + strlen(filename) + 2, sizeof(char));
        sprintf(buffer, "%s=%s", ENV_FILE, filename);
        putenv(buffer);

        buffer = (char *) mcalloc(strlen(ENV_VIRUS) + strlen(virname) + 2, sizeof(char));
        sprintf(buffer, "%s=%s", ENV_VIRUS, virname);
        putenv(buffer);


        /* WARNING: this is uninterruptable ! */
        exit(system(cmd));

        /* The below is not reached but is here for completeness to remind
           maintainers that this buffer is still allocated.. */
        free(cmd);
    } else if (pid > 0) {
        /* parent */
        waitpid(pid, NULL, 0);
    } else {
        /* error.. */
        logg("!VirusAction: fork failed.\n");
    }
}
Example #4
0
oprtype put_cdlt(mstr *x)
{
    triple *ref;
    mstr *str;

    ref = newtriple(OC_CDLIT);
    ref->operand[0].oprclass = CDLT_REF;
    ref->operand[0].oprval.cdlt = str = (mstr *) mcalloc(sizeof(mstr));
    str->addr = mcalloc(x->len);
    str->len = x->len;
    memcpy(str->addr, x->addr, x->len);
    return put_tref(ref);
}
Example #5
0
void register_char_option(struct optstruct *opt, char ch, const char *longname)
{
	struct optnode *newnode;
	int i, found = 0;


    if(clamdscan_mode) {
	for(i = 0; clamdscan_short[i]; i++)
	    if(clamdscan_short[i] == ch)
		found = 1;

	if(!found) {
	    if(longname)
		mprintf("WARNING: Ignoring option -%c (--%s): please edit clamd.conf instead.\n", ch, longname);
	    else
		mprintf("WARNING: Ignoring option -%c: please edit clamd.conf instead.\n", ch);

	    return;
	}
    }

    newnode = (struct optnode *) mmalloc(sizeof(struct optnode));
    newnode->optchar = ch;
    if(optarg != NULL) {
	newnode->optarg = (char *) mcalloc(strlen(optarg) + 1, sizeof(char));
	strcpy(newnode->optarg, optarg);
    } else newnode->optarg = NULL;

    newnode->optname = NULL;
    newnode->next = opt->optlist;
    opt->optlist = newnode;
}
bool Flags::resize( int32_t size ) { 
	if ( size < 0           ) return false;
	if ( size == m_numFlags ) return true;
	
	char *newFlags = (char *)mcalloc( size*sizeof(char), "Flags" );
	if ( ! newFlags ) return false;

	m_numSet     = 0;
	m_highestSet = NoMax;
	m_lowestSet  = NoMin;
	if ( m_flags ) {
		// copy as many of old flags over as possible
		int32_t min = m_numFlags;
		if ( min > size ) min = size;
		gbmemcpy( newFlags, m_flags, min*sizeof(char) );
		mfree( m_flags, m_numFlags*sizeof(char), "Flags" );
		m_flags = NULL;
		// find new values for member variables
		for ( int32_t i = 0; i < min; i++ ) {
			if ( newFlags[i] ) {
				m_numSet++;
				if ( i > m_highestSet ) m_highestSet = i;
				if ( i < m_lowestSet  ) m_lowestSet  = i;
			}
		}
	}
	m_flags      = newFlags;
	m_numFlags   = size;

	return (m_flags != NULL);
}
Example #7
0
File: rnalib.c Project: u-u-h/adpc
static void init_scale_ar()
{
  int i;
  scale_ar=(double *) mcalloc(n+2, sizeof(double));
  scale_ar[0] = 1.0;
  for (i = 1; i<= n; i++) scale_ar[i] = scale_ar[i-1] / mean_scale;
}
Example #8
0
File: adplib.c Project: u-u-h/adpc
/* create a new format string entry */
static tformat_string *format_string_newentry(char type, char *string){
  tformat_string *f;
  f = (tformat_string *) mcalloc(1, sizeof(tformat_string));
  f->type   = type;
  f->string = mkstr(string);
  f->next   = NULL;
  return f;
}
Example #9
0
/* Allocate and initialize a string list. */
int
alloc_list(string_list_t * list)
{
    list->count = 0;
    list->items =
        (string_item_t *) mcalloc(list->max_count, sizeof(string_item_t), "alloc_list(items->items)");
    assert(list->items != NULL);
    return 0;
}
Example #10
0
void RTinit()        /* set up Linebuf, Midibuf & ready the input files */
{                    /*     callable once from main.c         */
extern int  Linein, Midiin;
extern char *Linename, *Midiname;

    if (Linein) {
        Linevtblk = (EVTBLK *) mcalloc((long)sizeof(EVTBLK));
	Linebuf = mcalloc((long)LBUFSIZ);
	Linebufend = Linebuf + LBUFSIZ;
	Linep = Linebuf;
	if (strcmp(Linename,"stdin") == 0) {
#ifdef THINK_C
	    console_options.top += 10;
	    console_options.left += 10;
	    console_options.title = "\pRT Line_events";
	    console_options.nrows = 10;
	    console_options.ncols = 50;
	    Linecons = fopenc();
	    cshow(Linecons);
#else
	    if (fcntl(Linefd, F_SETFL, fcntl(Linefd, F_GETFL, 0) | O_NDELAY) < 0)
	        die("-R stdin fcntl failed");
#endif
	}
	else if ((Linefd = open(Linename, O_RDONLY | O_NDELAY)) < 0)
	    dies("cannot open %s", Linename);
    }
    if (Midiin) {
        Midevtblk = (EVTBLK *) mcalloc((long)sizeof(EVTBLK));
	Midibuf = mcalloc((long)MBUFSIZ);
	Midibufend = Midibuf + MBUFSIZ;
	Midip = Midibuf;
	if (strcmp(Midiname,"stdin") == 0) {
#ifdef THINK_C
	    dieu("RT Midi_event Console not implemented");
#else
	    if (fcntl(Midifd, F_SETFL, fcntl(Midifd, F_GETFL, 0) | O_NDELAY) < 0)
	        die("-M stdin fcntl failed");
#endif
	}
	else if ((Midifd = open(Midiname, O_RDONLY | O_NDELAY)) < 0)
	    dies("cannot open %s", Midiname);
     }
}
Example #11
0
mvar *get_mvaddr(mident *c)
{
    GBLREF mvar *mvartab;
    GBLREF mvax *mvaxtab,*mvaxtab_end;
    GBLREF int mvmax;
    char *ch;
    mvar **p;
    mvax *px;
    char *tmp;
    int x;
    ch = c->c;

    p = &mvartab;
    while (*p)
        if ((x = memcmp((*p)->mvname.c,ch,sizeof(mident) / sizeof(char)))
                < 0)
            p = &((*p)->rson);
        else if (x > 0)
            p = &((*p)->lson);
        else
            return *p;
    *p = (mvar *) mcalloc((unsigned int) sizeof(mvar));
    for (tmp = (*p)->mvname.c ;
            *ch && tmp < &((*p)->mvname.c[sizeof(mident) / sizeof(char)]) ; )
        *tmp++ = *ch++;
    while(tmp < &((*p)->mvname.c[sizeof(mident) / sizeof(char)]))
        *tmp++ = 0;
    (*p)->mvidx = mvmax++;
    (*p)->lson = (*p)->rson = 0;
    (*p)->last_fetch = 0;
    px = (mvax *) mcalloc(sizeof(mvax));
    px->var = *p;
    px->last = px->next = 0;
    px->mvidx = (*p)->mvidx;
    if (mvaxtab_end)
    {
        px->last = mvaxtab_end;
        mvaxtab_end->next = px;
        mvaxtab_end = px;
    }
    else
        mvaxtab = mvaxtab_end = px;
    return *p;
}
Example #12
0
int m_xecute(void)
{
	oprtype *cr, x;
	triple *obp, *oldchain, *ref0, *ref1, tmpchain, *triptr;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	dqinit(&tmpchain,exorder);
	oldchain = setcurtchain(&tmpchain);
	switch (expr(&x, MUMPS_STR))
	{
	case EXPR_FAIL:
		setcurtchain(oldchain);
		return FALSE;
	case EXPR_INDR:
		if (TK_COLON != TREF(window_token))
		{
			make_commarg(&x,indir_xecute);
			break;
		}
		/* caution: fall through */
	case EXPR_GOOD:
		ref0 = maketriple(OC_COMMARG);
		ref0->operand[0] = x;
		ref0->operand[1] = put_ilit(indir_linetail);
		ins_triple(ref0);
	}
	setcurtchain(oldchain);
	if (TK_COLON == TREF(window_token))
	{
		advancewindow();
		cr = (oprtype *)mcalloc(SIZEOF(oprtype));
		if (!bool_expr(FALSE, cr))
			return FALSE;
		if (TREF(expr_start) != TREF(expr_start_orig))
		{
			triptr = newtriple(OC_GVRECTARG);
			triptr->operand[0] = put_tref(TREF(expr_start));
		}
		obp = oldchain->exorder.bl;
		dqadd(obp,&tmpchain,exorder);		/* violates info hiding */
		if (TREF(expr_start) != TREF(expr_start_orig))
		{
			ref0 = newtriple(OC_JMP);
			ref1 = newtriple(OC_GVRECTARG);
			ref1->operand[0] = put_tref(TREF(expr_start));
			*cr = put_tjmp(ref1);
			tnxtarg(&ref0->operand[0]);
		} else
			tnxtarg(cr);
		return TRUE;
	}
	obp = oldchain->exorder.bl;
	dqadd(obp,&tmpchain,exorder);		/* violates info hiding */
	return TRUE;
}
Example #13
0
File: adplib.c Project: u-u-h/adpc
/* same as print_subseq; used in color mode */
static void print_subseq_color(char *fs, char *s, int pos, int size){
  int i,c,tpos,ls;
  char e;
  char *lastcol, *tmp, *tmp2;
  int plastcol;

  ls      = strlen(s);
  lastcol = (char*) mcalloc(20,    sizeof(char));
  tmp     = (char*) mcalloc(20*ls, sizeof(char));
  tmp2    = (char*) mcalloc(20*ls, sizeof(char));

  plastcol = -1;  

  // go to character pos+1:
  c=0; i=0; e=0; 
  while (c<pos+1) {
    if      (s[i] == '\x1b')     { e = 1; plastcol = 0; }
    else if ((s[i] == 'm') && e) e = 0;
    else if (e)                  lastcol[plastcol++] = s[i];     
    else                         c++;    
    i++;
  }
  if (plastcol != -1) lastcol[plastcol] = 0;
  tpos = 0;
  while (c<=pos+size) {
    if (c <= ls) tmp2[tpos++] = s[i-1];
    else                tmp2[tpos++] = ' ';
    if      (s[i] == '\x1b')       e = 1;
    else if ((s[i] == 'm') && e) e = 0;
    else if (e)                  ;     
    else                         c++;    
    i++;
  }
  tmp2[tpos] = 0;
  strcat(tmp2, "\x1b[0m");
  tmp[0]=0;
  if (plastcol != -1) sprintf(tmp, "\x1b%sm", lastcol);
  strcat(tmp, tmp2);
  printf(fs, tmp);
  free(lastcol);
  free(tmp);
  free(tmp2);
}
Example #14
0
mvar *get_mvaddr(mident *var_name)
{
	mvar 	**p;
	mvax 	*px;
	mstr 	vname;
	int 	x;

	p = &mvartab;
	while (*p)
	{
		MIDENT_CMP(&(*p)->mvname, var_name, x);
		if (x < 0)
			p = &((*p)->rson);
		else if (x > 0)
			p = &((*p)->lson);
		else
			return *p;
	}
	/* variable doesn't exist - create a new mvar in mvartab */
	vname.len = var_name->len;
	vname.addr = var_name->addr;
	s2pool_align(&vname);
	*p = (mvar *)mcalloc(SIZEOF(mvar));
	(*p)->mvname.len = vname.len;
	(*p)->mvname.addr = vname.addr;
	(*p)->mvidx = mvmax++;
	(*p)->lson = (*p)->rson = NULL;
	(*p)->last_fetch = NULL;
	px = (mvax *)mcalloc(SIZEOF(mvax));
	px->var = *p;
	px->last = px->next = 0;
	px->mvidx = (*p)->mvidx;
	if (mvaxtab_end)
	{
		px->last = mvaxtab_end;
		mvaxtab_end->next = px;
		mvaxtab_end = px;
	}
	else
		mvaxtab = mvaxtab_end = px;
	return *p;
}
Example #15
0
File: put_tsiz.c Project: 5HT/mumps
oprtype put_tsiz(void)
{
	triple 		*ref;
	tripsize	*tsize;

	ref = newtriple(OC_TRIPSIZE);
	ref->operand[0].oprclass = TSIZ_REF;
	ref->operand[0].oprval.tsize = tsize = (tripsize *)mcalloc(sizeof(tripsize));
	tsize->ct = NULL;
	tsize->size = 0;
	return put_tref(ref);
}
Example #16
0
triple *maketriple(opctype op)
{
	triple *x;

	x = (triple *)mcalloc(SIZEOF(triple));
	x->opcode = op;
	x->src.line = source_line;
	x->src.column = source_column;
	dqinit(&(x->backptr), que);
	dqinit(&(x->jmplist), que);
	return x;
}
Example #17
0
File: adplib.c Project: u-u-h/adpc
/* print the given subsequence of a sequence */
static void print_subseq(char *fs, char *s, int offset, int pos, int size){
  int i, tpos;
  char *tmp;

  tmp     = (char*) mcalloc(2*strlen(s), sizeof(char));
  tpos = 0;
  for (i=pos+1; i <= pos + size; i++) 
    if (i <= strlen(s)) tmp[tpos++] = s[offset+i-1];
    else                tmp[tpos++] = ' ';
  tmp[tpos] = 0;
  printf(fs, tmp);
  free(tmp);
}
Example #18
0
void getmaxCellScore (ProcessData * pData, TracebackData * tbData) {
    int i;
    MOATypeElmVal recvMaxCellScore;
    MOATypeShape * recvMaxCellIndex = NULL;
    char msg[MID_MESSAGE_SIZE];
    MOATypeDimn k;

    MPI_Status status;
    MPI_Request request;
    recvMaxCellIndex =  mcalloc ((MOATypeInd) tbData->seqNum, (MOATypeInd) sizeof *recvMaxCellIndex);
    if (recvMaxCellIndex == NULL) {
        printf ("Failed to allocate memory for the multidimensional Index. Exiting.\n");
        return;
    }
    for (i=1;i<ClusterSize;i++) {
        MPI_Recv (&recvMaxCellScore, 1, MPI_LONG_LONG, i, 0, MOAMSA_COMM_WORLD, &status);
        MPI_Recv (recvMaxCellIndex, pData->seqNum, MPI_LONG_LONG, i, 1, MOAMSA_COMM_WORLD, &status);
        sprintf (msg, "Master received recvMaxCellScore = %lld, recvMaxCellIndex = {%lld ", recvMaxCellScore, recvMaxCellIndex[0]);
        mprintf (3, msg, 1);
        for (k=1;k<pData->seqNum;k++) {
            sprintf (msg, ", %lld", recvMaxCellIndex[k]);
            mprintf (3, msg, 1);
        }
        sprintf  (msg, "} from %d\n", i);
        mprintf (3, msg, 1);
        if (i == 1) {
            tbData->maxCellScore = recvMaxCellScore;
            for (k=0;k<pData->seqNum;k++)
                tbData->maxCellIndex[k] = recvMaxCellIndex[k];
            tbData->currProc = i;
        }
        else if (recvMaxCellScore > tbData->maxCellScore) {
            tbData->maxCellScore = recvMaxCellScore;
            for (k=0;k<pData->seqNum;k++)
                tbData->maxCellIndex[k] = recvMaxCellIndex[k];
            tbData->currProc = i;
        }
    }
    sprintf (msg, "Master received max proc %d score  = %lld, Index = {%lld", tbData->currProc, tbData->maxCellScore, tbData->maxCellIndex[0]);
    for (k=1;k<pData->seqNum;k++)
        sprintf (msg, "%s, %lld", msg, tbData->maxCellIndex[k]);
    sprintf (msg, "%s}\n", msg);
    mprintf (3, msg, 1);
    if (recvMaxCellIndex != NULL)
        free (recvMaxCellIndex);
    recvMaxCellIndex = NULL;
}
Example #19
0
File: Util.c Project: baoboa/pymol
void *UtilArrayCalloc(unsigned int *dim,ov_size ndim,ov_size atom_size)
{
  ov_size size;
  ov_size sum,product;
  ov_size chunk;
  ov_size a,b,c;
  void *result,**p;
  char *q;
  
  sum = 0;
  for(a=0;a<(ndim-1);a++) {
    product = dim[0];
    for(b=1;b<=a;b++)
      product = product * dim[b];
    sum = sum + product * sizeof(void*);
  }
  size = atom_size;
  for(a=0;a<ndim;a++)
	 size = size * dim[a];
  size = size + sum;
  result = (void*)mcalloc(size*2,1); /* what is this *2 for ??? */

  if(result) {
    chunk = 1;
    p = result;
    for(c=0;c<(ndim-1);c++) {
      if(c<(ndim-2)) {
        chunk = dim[c+1] * sizeof(void*);
      } else {
        chunk = dim[c+1] * atom_size;
      }
      
      product = dim[0];
      for(b=1;b<=c;b++)
        product = product * dim[b];
      q = ((char*)p) + product * sizeof(void*); 
      for(a=0;a<product;a++) {
        *p = q;
        p++;
        q+=chunk;
      }
    }
  }
  return(result);
}
Example #20
0
int m_goto(void)
{
	oprtype	*cr;
	triple	*obp, *oldchain, *ref0, *ref1, tmpchain, *triptr;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	dqinit(&tmpchain, exorder);
	oldchain = setcurtchain(&tmpchain);
	if (!entryref(OC_JMP, OC_EXTJMP, (mint)indir_goto, TRUE, FALSE, FALSE))
	{
		setcurtchain(oldchain);
		return FALSE;
	}
	setcurtchain(oldchain);
	if (TK_COLON == TREF(window_token))
	{
		advancewindow();
		cr = (oprtype *)mcalloc(SIZEOF(oprtype));
		if (!bool_expr(FALSE, cr))
			return FALSE;
		if ((TREF(expr_start) != TREF(expr_start_orig)) && (OC_NOOP != (TREF(expr_start))->opcode))
		{
			triptr = newtriple(OC_GVRECTARG);
			triptr->operand[0] = put_tref(TREF(expr_start));
		}
		obp = oldchain->exorder.bl;
		dqadd(obp, &tmpchain, exorder);   /*this is a violation of info hiding*/
		if ((TREF(expr_start) != TREF(expr_start_orig)) && (OC_NOOP != (TREF(expr_start))->opcode))
		{
			ref0 = newtriple(OC_JMP);
			ref1 = newtriple(OC_GVRECTARG);
			ref1->operand[0] = put_tref(TREF(expr_start));
			*cr = put_tjmp(ref1);
			tnxtarg(&ref0->operand[0]);
		} else
			tnxtarg(cr);
		return TRUE;
	}
	obp = oldchain->exorder.bl;
	dqadd(obp, &tmpchain, exorder);   /*this is a violation of info hiding*/
	return TRUE;
}
Example #21
0
File: m_goto.c Project: 5HT/mumps
int m_goto(void)
{
	triple tmpchain, *oldchain, *obp, *ref0, *ref1, *triptr;
	oprtype *cr;

	dqinit(&tmpchain, exorder);
	oldchain = setcurtchain(&tmpchain);
	if (!entryref(OC_JMP, OC_EXTJMP, (mint) indir_goto, TRUE, FALSE))
	{
		setcurtchain(oldchain);
		return FALSE;
	}
	setcurtchain(oldchain);
	if (window_token == TK_COLON)
	{
		advancewindow();
		cr = (oprtype *) mcalloc(sizeof(oprtype));
		if (!bool_expr((bool) FALSE, cr))
			return FALSE;
		if (expr_start != expr_start_orig)
		{
			triptr = newtriple(OC_GVRECTARG);
			triptr->operand[0] = put_tref(expr_start);
		}
		obp = oldchain->exorder.bl;
		dqadd(obp, &tmpchain, exorder);   /*this is a violation of info hiding*/
		if (expr_start != expr_start_orig)
		{
			ref0 = newtriple(OC_JMP);
			ref1 = newtriple(OC_GVRECTARG);
			ref1->operand[0] = put_tref(expr_start);
			*cr = put_tjmp(ref1);
			tnxtarg(&ref0->operand[0]);
		}
		else
			tnxtarg(cr);
		return TRUE;
	}
	obp = oldchain->exorder.bl;
	dqadd(obp, &tmpchain, exorder);   /*this is a violation of info hiding*/
	return TRUE;
}
Example #22
0
static void XMLCALL
setElement(void *data, const char *el, int len)
{
    int i, j;

    if(len <= 0 || parser_node == NULL)
        return;

    /* ignore prefixed '\n \r \t space' */
    for(i = 0; i < len; i++) {
        if(el[i] != '\r' && el[i] != '\n' && el[i] != '\t' && el[i] != ' ')
            break;
    }
    if(i == len)
        return;
    if(el[len - 1] == '\n')
        len--;

    if(parser_node->value == NULL) {
        parser_node->value = (char *) mcalloc(len - i + 1, 1);
        if(parser_node->value == NULL) {
            xml_error = XML_ERR_MEMORY;
            printf("%s: %d\n", __FILE__, __LINE__);
            return;
        }
        memcpy(parser_node->value, el + i, len - i);
        parser_node->value[len - i] = '\0';
    }
    else {
        /* expands parser's value */
        j = strlen(parser_node->value);
        parser_node->value =
            (char *) mrealloc((void *) parser_node->value, j + (len - i) + 1);
        if(parser_node->value == NULL) {
            xml_error = XML_ERR_MEMORY;
            printf("%s: %d\n", __FILE__, __LINE__);
            return;
        }
        memcpy(parser_node->value + j, el + i, len - i);
        parser_node->value[j + len - i] = '\0';
    }
}
Example #23
0
File: rnalib.c Project: u-u-h/adpc
static void init_il_ent_ar()
{
  int i;
  il_ent_ar=(int *) mcalloc(max(31,n+1), sizeof(int));

  /* report errors by unrealistic values: */
  il_ent_ar[ 0] = UNDEF;
  il_ent_ar[ 1] = UNDEF;

  il_ent_ar[2] = 150  ;
  il_ent_ar[3] = 160 ;
  il_ent_ar[4] = 170 ;
  il_ent_ar[5] = 180 ;
  il_ent_ar[6] = 200 ;
  il_ent_ar[7] = 220 ;
  il_ent_ar[8] = 230 ;
  il_ent_ar[9] = 240 ;
  il_ent_ar[10] = 250 ;
  il_ent_ar[11] = 260 ;
  il_ent_ar[12] = 270 ;
  il_ent_ar[13] = 278 ;
  il_ent_ar[14] = 286 ;
  il_ent_ar[15] = 294 ;
  il_ent_ar[16] = 301 ;
  il_ent_ar[17] = 307 ;
  il_ent_ar[18] = 313 ;
  il_ent_ar[19] = 319 ;
  il_ent_ar[20] = 325 ;
  il_ent_ar[21] = 330 ;
  il_ent_ar[22] = 335 ;
  il_ent_ar[23] = 340 ;
  il_ent_ar[24] = 345 ;
  il_ent_ar[25] = 349 ;
  il_ent_ar[26] = 353 ;
  il_ent_ar[27] = 357 ;
  il_ent_ar[28] = 361 ;
  il_ent_ar[29] = 365 ;
  il_ent_ar[30] = 369 ;

  for (i=31;i<=n;i++) il_ent_ar[i] = il_ent_ar[30] + jacobson_stockmayer(i);
}
Example #24
0
File: rnalib.c Project: u-u-h/adpc
static void init_bl_ent_ar()
{
  int i;
  bl_ent_ar=(int *) mcalloc(max(31,n+1), sizeof(int));

  /* report errors by unrealistic values: */
  bl_ent_ar[0] = UNDEF;

  bl_ent_ar[1] = 380 ;
  bl_ent_ar[2] = 280 ;
  bl_ent_ar[3] = 320 ;
  bl_ent_ar[4] = 360 ;
  bl_ent_ar[5] = 400 ;
  bl_ent_ar[6] = 440 ;
  bl_ent_ar[7] = 459 ;
  bl_ent_ar[8] = 470 ;
  bl_ent_ar[9] = 480 ;
  bl_ent_ar[10] = 490 ;
  bl_ent_ar[11] = 500 ;
  bl_ent_ar[12] = 510 ;
  bl_ent_ar[13] = 519 ;
  bl_ent_ar[14] = 527 ;
  bl_ent_ar[15] = 534 ;
  bl_ent_ar[16] = 541 ;
  bl_ent_ar[17] = 548 ;
  bl_ent_ar[18] = 554 ;
  bl_ent_ar[19] = 560 ;
  bl_ent_ar[20] = 565 ;
  bl_ent_ar[21] = 571 ;
  bl_ent_ar[22] = 576 ;
  bl_ent_ar[23] = 580 ;
  bl_ent_ar[24] = 585 ;
  bl_ent_ar[25] = 589 ;
  bl_ent_ar[26] = 594 ;
  bl_ent_ar[27] = 598 ;
  bl_ent_ar[28] = 602 ;
  bl_ent_ar[29] = 605 ;
  bl_ent_ar[30] = 609 ;

  for (i=31;i<=n;i++) bl_ent_ar[i] = bl_ent_ar[30] + jacobson_stockmayer(i);
}
Example #25
0
File: rnalib.c Project: u-u-h/adpc
static void init_hl_ent_ar()
{
  int i;
  hl_ent_ar=(int *) mcalloc(max(31,n+1), sizeof(int));

  /* report errors by unrealistic values: */
  hl_ent_ar[0] = UNDEF;
  hl_ent_ar[1] = UNDEF;
  hl_ent_ar[2] = UNDEF;

  hl_ent_ar[3] = 570 ;
  hl_ent_ar[4] = 560 ;
  hl_ent_ar[5] = 560 ;
  hl_ent_ar[6] = 540 ;
  hl_ent_ar[7] = 590 ;
  hl_ent_ar[8] = 560 ;
  hl_ent_ar[9] = 640 ;
  hl_ent_ar[10] = 650 ;
  hl_ent_ar[11] = 660 ;
  hl_ent_ar[12] = 670 ;
  hl_ent_ar[13] = 678 ;
  hl_ent_ar[14] = 686 ;
  hl_ent_ar[15] = 694 ;
  hl_ent_ar[16] = 701 ;
  hl_ent_ar[17] = 707 ;
  hl_ent_ar[18] = 713 ;
  hl_ent_ar[19] = 719 ;
  hl_ent_ar[20] = 725 ;
  hl_ent_ar[21] = 730 ;
  hl_ent_ar[22] = 735 ;
  hl_ent_ar[23] = 740 ;
  hl_ent_ar[24] = 744 ;
  hl_ent_ar[25] = 749 ;
  hl_ent_ar[26] = 753 ;
  hl_ent_ar[27] = 757 ;
  hl_ent_ar[28] = 761 ;
  hl_ent_ar[29] = 765 ;
  hl_ent_ar[30] = 769 ;

  for (i=31;i<=n;i++) hl_ent_ar[i] = hl_ent_ar[30] + jacobson_stockmayer(i);
}
Example #26
0
File: put_lit.c Project: 5HT/mumps
oprtype put_lit(mval *x)
{
	mliteral *a;
	triple *ref;

	ref = newtriple(OC_LIT);
	ref->operand[0].oprclass = MLIT_REF;
	dqloop(&literal_chain,que,a)
		if (is_equ(x,&(a->v)))
		{
			a->rt_addr--;
			ref->operand[0].oprval.mlit = a;
			return put_tref(ref);
		}
	ref->operand[0].oprval.mlit = a = (mliteral *) mcalloc(sizeof(mliteral));
	dqins(&literal_chain,que,a);
	a->rt_addr = -1;
	a->v = *x;
	mlitmax++;
	return put_tref(ref);
}
// . return NULL with g_errno set on error
// . importLoop() calls this to get a msg7 to inject a doc from the foreign
//   titledb file into our local collection
Multicast *ImportState::getAvailMulticast() { // Msg7 ( ) {

	//static XmlDoc **s_ptrs = NULL;

	// this is legit because parent checks for it
	CollectionRec *cr = g_collectiondb.getRec ( m_collnum );

	// each msg7 has an xmldoc doc in it
	if ( ! m_ptrs ) {
		long max = (long)MAXINJECTSOUT;
		m_ptrs=(Multicast *)mcalloc(sizeof(Multicast)* max,"sxdp");
		if ( ! m_ptrs ) return NULL;
		m_numPtrs = max;//(long)MAXINJECTSOUT;
		for ( long i = 0 ; i < m_numPtrs ;i++ ) 
			m_ptrs[i].constructor();
	}

	// respect the user limit for this coll
	long long out = m_numOut - m_numIn;
	if ( out >= cr->m_numImportInjects ) {
		g_errno = 0;
		return NULL;
	}

	// find one not in use and return it
	for ( long i = 0 ; i < m_numPtrs ; i++ ) {
		// point to it
		Multicast *mcast = &m_ptrs[i];
		if ( mcast->m_inUse ) continue;
		//m7->m_inUse = true;
		mcast->m_importState = this;
		return mcast;
	}
	// none avail
	g_errno = 0;
	return NULL;
}
Example #28
0
char *abpath(const char *filename)
{
	struct stat foo;
	char *fullpath, cwd[200];

    if(stat(filename, &foo) == -1) {
	mprintf("@Can't access file %s\n", filename);
	perror(filename);
	return NULL;
    } else {
	fullpath = mcalloc(200 + strlen(filename) + 10, sizeof(char));
#ifdef C_CYGWIN
	sprintf(fullpath, "%s", filename);
#else
	if(!getcwd(cwd, 200)) {
	    mprintf("@Can't get absolute pathname of current working directory.\n");
	    return NULL;
	}
	sprintf(fullpath, "%s/%s", cwd, filename);
#endif
    }

    return fullpath;
}
Example #29
0
/* $ZWRITE(): Single parameter - string expression */
int f_zwrite(oprtype *a, opctype op)
{
	mval		tmp_mval;
	oprtype		*newop;
	triple		*r;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	r = maketriple(op);
	if (EXPR_FAIL == expr(&(r->operand[0]), MUMPS_STR))
		return FALSE;
	if (TK_COMMA != TREF(window_token))
		r->operand[1] = put_ilit(0);
	else
	{
		advancewindow();
		if (EXPR_FAIL == expr(&(r->operand[1]), MUMPS_INT))
			return FALSE;
	}
	/* This code tries to execute $ZWRITE at compile time if all parameters are literals */
	if ((OC_LIT == r->operand[0].oprval.tref->opcode) && (ILIT_REF == r->operand[1].oprval.tref->operand->oprclass)
		&& (!gtm_utf8_mode || valid_utf_string(&r->operand[0].oprval.tref->operand[0].oprval.mlit->v.str)))
	{	/* We don't know how much space we will use; but we know it's based on the size of the current string */
		op_fnzwrite(r->operand[1].oprval.tref->operand[0].oprval.ilit,
			&r->operand[0].oprval.tref->operand[0].oprval.mlit->v, &tmp_mval);
		newop = (oprtype *)mcalloc(SIZEOF(oprtype));
		*newop = put_lit(&tmp_mval);				/* Copies mval so stack var tmp_mval not an issue */
		assert(TRIP_REF == newop->oprclass);
		newop->oprval.tref->src = r->src;
		*a = put_tref(newop->oprval.tref);
		return TRUE;
	}
	ins_triple(r);
	*a = put_tref(r);
	return TRUE;
}
// print out the mem table
// but combine allocs with the same label
// sort by mem allocated
bool Mem::printMemBreakdownTable ( SafeBuf* sb, 
				   char *lightblue, 
				   char *darkblue) {
	const char *ss = "";

	sb->safePrintf (
		       "<table>"

		       "<table %s>"
		       "<tr>"
		       "<td colspan=3 bgcolor=#%s>"
		       "<center><b>Mem Breakdown%s</b></td></tr>\n"

		       "<tr bgcolor=#%s>"
		       "<td><b>allocator</b></td>"
		       "<td><b>num allocs</b></td>"
		       "<td><b>allocated</b></td>"
		       "</tr>" ,
		       TABLE_STYLE, darkblue , ss , darkblue );

	int32_t n = m_numAllocated * 2;
	MemEntry *e = (MemEntry *)mcalloc ( sizeof(MemEntry) * n , "Mem" );
	if ( ! e ) {
		log(LOG_WARN, "admin: Could not alloc %" PRId32" bytes for mem table.",
		    (int32_t)sizeof(MemEntry)*n);
		return false;
	}

	// hash em up, combine allocs of like label together for this hash
	for ( int32_t i = 0 ; i < (int32_t)m_memtablesize ; i++ ) {
		// skip empty buckets
		if ( ! s_mptrs[i] ) continue;
		// get label ptr, use as a hash
		char *label = &s_labels[i*16];
		int32_t  h     = hash32n ( label );
		if ( h == 0 ) h = 1;
		// accumulate the size
		int32_t b = (uint32_t)h % n;
		// . chain till we find it or hit empty
		// . use the label as an indicator if bucket is full or empty
		while ( e[b].m_hash && e[b].m_hash != h )
			if ( ++b >= n ) b = 0;
		// add it in
		e[b].m_hash       = h;
		e[b].m_label      = label;
		e[b].m_allocated += s_sizes[i];
		e[b].m_numAllocs++;
	}

	// get the top 20 users of mem
	MemEntry *winners [ PRINT_TOP ];

	int32_t i = 0;
	int32_t count = 0;
	for ( ; i < n && count < PRINT_TOP ; i++ )
		// if non-empty, add to winners array
		if ( e[i].m_hash ) winners [ count++ ] = &e[i];

	// compute new min
	int32_t min  = 0x7fffffff;
	int32_t mini = -1000;
	for ( int32_t j = 0 ; j < count ; j++ ) {
		if ( winners[j]->m_allocated > min ) continue;
		min  = winners[j]->m_allocated;
		mini = j;
	}

	// now the rest must compete
	for ( ; i < n ; i++ ) {
		// if empty skip
		if ( ! e[i].m_hash ) continue;
		//if ( e[i].m_allocated > 120 && e[i].m_allocated < 2760 )
		//	log("hey %" PRId32, e[i].m_allocated);
		// skip if not a winner
		if ( e[i].m_allocated <= min ) continue;
		// replace the lowest winner
		winners[mini] = &e[i];
		// compute new min
		min = 0x7fffffff;
		for ( int32_t j = 0 ; j < count ; j++ ) {
			if ( winners[j]->m_allocated > min ) continue;
			min  = winners[j]->m_allocated;
			mini = j;
		}
	}

	// now sort them
	bool flag = true;
	while ( flag ) {
		flag = false;
		for ( int32_t i = 1 ; i < count ; i++ ) {
			// no need to swap?
			if ( winners[i-1]->m_allocated >= 
			     winners[i]->m_allocated ) continue;
			// swap
			flag = true;
			MemEntry *tmp = winners[i-1];
			winners[i-1]  = winners[i];
			winners[i  ]  = tmp;
		}
	}
			
	// now print into buffer
	for ( int32_t i = 0 ; i < count ; i++ ) 
		sb->safePrintf (
			       "<tr bgcolor=%s>"
			       "<td>%s</td>"
			       "<td>%" PRId32"</td>"
			       "<td>%" PRId32"</td>"
			       "</tr>\n",
			       LIGHT_BLUE,
			       winners[i]->m_label,
			       winners[i]->m_numAllocs,
			       winners[i]->m_allocated);

	sb->safePrintf ( "</table>\n");

	// don't forget to release this mem
	mfree ( e , (int32_t)sizeof(MemEntry) * n , "Mem" );

	return true;
}