Beispiel #1
0
void *_MemoryShrinkForSure(PyMOLGlobals * G, void *ptr, unsigned int size, int group_id,
                           int block_id MD_FILE_LINE_Decl)
{
  /* no checking done */

  if((group_id < 0) || (!SettingGetGlobal_b(G, cSetting_cache_memory)))
    return (ReallocForSure(ptr, size)); /* NOTE: fatal if new ptr is larger than old... */
  {
    register CMemoryCache *I = G->MemoryCache;
    register MemoryCacheRec *rec = &I->Cache[group_id][block_id];

    if(ptr != rec->ptr)
      printf("Error: Memory Cache Mismatch 2 %d %d\n", group_id, block_id);
    if(!rec->ptr) {             /* not currently cache-allocated... this should never happen */
      rec->size = size;
      rec->ptr = mrealloc(ptr, size);
    } else if(rec->size < size) {
      rec->ptr = MemoryReallocForSureSafe(ptr, size, rec->size);
      rec->size = size;
    } else {                    /* expanding size...should never happen... this should never happen */
      rec->size = size;
      rec->ptr = mrealloc(ptr, size);
    }
    return (rec->ptr);
  }
}
Beispiel #2
0
void	*from_file(const char *fn, unsigned long *size, t_check_fun chk)
{
	int		fd;
	char	*buff;
	int		r;

	fd = open(fn, O_RDONLY);
	if (fd < 0)
		return (0);
	*size = 0;
	buff = ft_memalloc(512);
	while (1)
	{
		r = read(fd, buff + *size, 512);
		*size += r;
		if (!chk(buff + *size, r, *size))
		{
			free(buff);
			return (0);
		}
		if (r != 512)
			break ;
		buff = mrealloc(buff, *size, *size + 512);
		ft_memset(buff + *size, 0, 512);
	}
	return (buff);
}
Beispiel #3
0
ppInt32 CosArrayInsert( PDFCosHandle CosObject, PDFCosHandle NewCosObject, ppUns32 Position )
{
    if ( !_IsCosArray( CosObject )  )
        _RAISE ( ErrCosLevel, cleInvalidObjError );
    if ( _CosDoc ( NewCosObject ) != _DOC )
        _RAISE ( ErrCosLevel, cleCannotInsertObjectFromOtherDocumentError );
    if ( !_CosIsIndirect ( NewCosObject) && _CosParent ( NewCosObject ) )
        _RAISE ( ErrCosLevel, cleCannotInsertObjectWithParrentError );      
    if ( Position >= _CosArrayCount ( CosObject ) )
        return CosArrayAppend ( CosObject, NewCosObject );
    if ( _CosArrayCount ( CosObject ) == _CosArrayCapacity ( CosObject ) ){
            _CosArrayCapacity ( CosObject ) += CalculateDelta ( _CosArrayCapacity ( CosObject ) );
            _CosArrayArray ( CosObject ) = ( PDFCosHandle * )
                mrealloc ( _LIB, _CosArrayArray ( CosObject ),
                _CosArrayCapacity ( CosObject ) * sizeof ( PDFCosHandle ) );
        };
    memmove ( &( _CosArrayItem ( CosObject, Position + 1 ) ),
        &( _CosArrayItem ( CosObject, Position )  ),
        ( _CosArrayCount ( CosObject ) - Position ) * sizeof ( PDFCosHandle ) );
    if ( _CosIsIndirect ( NewCosObject ) )
        NewCosObject = CosNewRef ( _CosDoc( NewCosObject ), _CosObjID ( NewCosObject), 
            _CosObjGeneration ( NewCosObject ) );
    _CosArrayItem ( CosObject, Position ) = NewCosObject;
    _CosArrayCount ( CosObject )++;
    if ( !_IsCosNull ( NewCosObject ) )
        _CosParent ( NewCosObject ) = CO ( CosObject );
    return Position;
}
Beispiel #4
0
char		*get_next_line(const int fd)
{
  static char	buff_rd[READ_SIZE];
  static int	i;
  int		j;
  char		*buff_ret;
  int		len;

  j = 0;
  if ((buff_ret = malloc_ret()) == NULL)
    return (NULL);
  if (i > READ_SIZE + 1)
    i = 0;
  if (buff_rd[0] == 0 && (len = mread(fd, buff_rd, READ_SIZE, &i) < 0))
    return (NULL);
  while (buff_rd[i] != '\n')
    {
      if (buff_rd[i] == 0 && (len = mread(fd, buff_rd, READ_SIZE, &i) < 0))
	return (NULL);
      if (j != 0 && ( j % READ_SIZE) == 0
	  && ((buff_ret = mrealloc(buff_ret, j)) == NULL))
	return (NULL);
      buff_ret[j++] = buff_rd[i++];
    }
  i = i + 1;
  buff_ret[j] = 0;
  return (buff_ret);
}
Beispiel #5
0
void *myalloc(tmemory *mem, int size)
{
  //  return mcalloc(size,sizeof(char));
  //}
   if (adplib_debug>1) printf("myalloc(), currentBlock = , currentPos = \n");
   if (size % ALIGNMENT) {
     size = ((size / ALIGNMENT) + 1) * ALIGNMENT;
     if (adplib_debug>1) printf("realigned: %d\n", size);
   }

   if (mem->currentPos + size >= mem->blockSize) {
      mem->currentBlock++;
      if (mem->currentBlock > mem->numberOfBlocks) {
        mem->address = mrealloc(mem->address, sizeof (char *) * mem->currentBlock);
        mem->numberOfBlocks = mem->currentBlock;
        mem->address[mem->currentBlock - 1] = mmalloc(mem->blockSize);
	//        if(adplib_debug>1) printf("address of mem->address[mem->currentBlock - 1]: %d\n", mem->address[mem->currentBlock - 1]);
      }
      mem->currentPos = 0;
      //      if (adplib_debug>1) printf("mrealloc: myalloc(%d), currentBlock = %d, currentPos = %d\n", size, mem->currentBlock, mem->currentPos);
   }
   mem->currentPos = mem->currentPos + size;
   //   if (adplib_debug>1) printf("myalloc: address: %d\n", mem->address[mem->currentBlock - 1] + (mem->currentPos - size));
   return(mem->address[mem->currentBlock - 1] + (mem->currentPos - size));
}
Beispiel #6
0
Datei: e.c Projekt: 8l/ted
void decr_line()
{
Lines--;
if (Alloc_Lines>Lines+201) {
	Alloc_Lines-=200;
	if ((edbf=(LIN *)mrealloc(edbf,sizeof(LIN)*Alloc_Lines,"err:decr_line"))
		==NULL) exit(-1);
	edstate[cur_file].edbf=edbf;
}
}
Beispiel #7
0
Datei: e.c Projekt: 8l/ted
void incr_line()
{
Lines++;
if (Alloc_Lines<=Lines+1) {
	Alloc_Lines+=200;
	if ((edbf=(LIN *)mrealloc(edbf,
		sizeof(LIN)*Alloc_Lines,"incr_line"))==NULL)	exit(-1);
	edstate[cur_file].edbf=edbf;
}
}
Beispiel #8
0
Datei: e.c Projekt: 8l/ted
void ins_lines(int row, int lines)
{
int i;
Lines+=lines;
if (Alloc_Lines<=Lines+1) {
	Alloc_Lines+=Max(lines,200);
	if ((edbf=(LIN *)mrealloc(edbf,
		 sizeof(LIN)*Alloc_Lines,"err:ins_lines"))==NULL) exit(-1);
	edstate[cur_file].edbf=edbf;
}
for(i=Lines-lines-1;i>=row;i--) edbf[i+lines]=edbf[i];
}
Beispiel #9
0
void *_MemoryCacheRealloc(PyMOLGlobals * G, void *ptr, unsigned int size, int group_id,
                          int block_id MD_FILE_LINE_Decl)
{
  /* no checking done */

  if((group_id < 0) || (!SettingGetGlobal_b(G, cSetting_cache_memory)))
    return (mrealloc(ptr, size));
  {
    register CMemoryCache *I = G->MemoryCache;
    register MemoryCacheRec *rec = &I->Cache[group_id][block_id];

    if(ptr != rec->ptr)
      printf("Error: Memory Cache Mismatch 2 %d %d\n", group_id, block_id);
    if(!rec->ptr) {
      rec->size = size;
      rec->ptr = mrealloc(ptr, size);
    } else if(rec->size < size) {
      rec->size = size;
      rec->ptr = mrealloc(ptr, size);
    }
    return (rec->ptr);
  }
}
Beispiel #10
0
void *realloc(void *p, size_t s)
{
  xbt_mheap_t mdp = __mmalloc_current_heap;
  void *ret;

  if (mdp) {
    LOCK(mdp);
    ret = mrealloc(mdp, p, s);
    UNLOCK(mdp);
  } else {
    ret = real_realloc(p,s);
  }

  return ret;
}
Beispiel #11
0
Datei: xkey.c Projekt: 8l/ted
void incr_kdefno(KEYDEF **kd, int kdefmapno, int *kdno)
{
KEYDEF *kdef=*kd;
int kdefno=*kdno;
kdefno++;
if (kdefno >= MAX_KEY_DEF) {
	MAX_KEY_DEF+=50;
	if ((kdef=mrealloc(kdef,MAX_KEY_DEF*sizeof(KEYDEF),"incr_kdefno"))==NULL)
		exit(1);
	kdefmap[kdefmapno]=kdef;
}
*kd=kdef;
*kdno=kdefno;
kdefno_m[kdefmapno]=kdefno;
}
Beispiel #12
0
int alloc_pool(){
	int i, size=mem_pool.size;
	trace(3,"alloc\n");
	//top always =0 here! =)
	mrealloc(mem_pool.free,unsigned int,mem_pool.size+ALLOC_CELLS);
	mrealloc(mem_pool.mem,cell,mem_pool.size+ALLOC_CELLS);
	for(i=0;i<ALLOC_CELLS;i++){
		//reverse
		mem_pool.free[i]=ALLOC_CELLS+size-1-i;
	}
	mem_pool.top=ALLOC_CELLS-1;
	mem_pool.size+=ALLOC_CELLS;
	pool_print();
	hash_print();
	return SUCCESS;
}
Beispiel #13
0
void extend_buffer(int article) {
  int new_size;
  
  if (article < buffer_entries)
    return;
  
  if (buffer_entries == 0)
    new_size = INITIAL_BUFFER_ENTRIES;
  else
    new_size = buffer_entries * 2;

  buffer = mrealloc(buffer, buffer_entries * NOV_BLOCK_SIZE, 
		    new_size * NOV_BLOCK_SIZE);

  buffer_entries = new_size;
  max_article = article;
}
Beispiel #14
0
Datei: misc.c Projekt: 8l/ted
void leading_space_tab()
{
int row,len,nlen,i,ll,tabno,ofs;
char *ss;
for(row=0;row<Lines;row++) {
	if (!(len=edbf[row].len)) continue;
	ss=edbf[row].cstr;
	for(ll=0;ll<len && ss[ll]==' ';ll++);
	if (ll<tab_width) continue;
	tabno=ll/tab_width;
	ofs=tabno+(ll%tab_width);
	mmemmove(ss+ofs,ss+ll,len-ll);
	for(i=0;i<tabno;ss[i++]=9);
	if ((ss=mrealloc(ss,nlen=len-ll+ofs,"leading_space_tab"))==NULL)
		return;
	edbf[row].cstr=ss;
	edbf[row].len=nlen;
}
}
Beispiel #15
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';
    }
}
Beispiel #16
0
void CosDictAppend(PDFCosHandle CosObject, ppAtom Key, PDFCosHandle KeyValue )
{
    ppUns32 i;
    if ( !_IsCosDictOrStream (CosObject) )
        _RAISE ( ErrCosLevel, cleInvalidObjError );
    if ( _CosDoc ( KeyValue ) != _DOC )
        _RAISE ( ErrCosLevel, cleCannotInsertObjectFromOtherDocumentError );
    if ( !_CosIsIndirect ( KeyValue) && _CosParent ( KeyValue ) )
        _RAISE ( ErrCosLevel, cleCannotInsertObjectWithParrentError );
    if ( _IsCosNull ( KeyValue ) ){
        CosDictRemoveKey ( CosObject, Key );
        return;
    }
    if ( _IsCosStream ( CosObject ) )
        CosObject = _CosStreamAttr (CosObject );

    /* Check on exists key */
    for ( i = 0; i < _CosDictCount ( CosObject ); i++ )
        if ( _CosDictKey ( CosObject, i) == Key ){
            CosFree( _CosDictValue ( CosObject, i) );
            if ( _CosIsIndirect ( KeyValue ) )
                KeyValue = CosNewRef ( _CosDoc( KeyValue ), _CosObjID ( KeyValue), 
                _CosObjGeneration ( KeyValue ) );
            _CosDictValue ( CosObject, i) = KeyValue;
            _CosParent ( KeyValue ) = CO ( CosObject );
            return;
        };

    if ( _CosDictCount ( CosObject ) == _CosDictCapacity (CosObject) ){
        _CosDictCapacity ( CosObject ) += CalculateDelta ( _CosDictCapacity ( CosObject) );
        _CosDictArray ( CosObject ) = ( DictElem * ) mrealloc ( _LIB, _CosDictArray ( CosObject ),
            _CosDictCapacity ( CosObject) * sizeof ( DictElem ) );
    }     
    i = _CosDictCount ( CosObject );
    _CosDictKey ( CosObject, i) = Key;
    if ( _CosIsIndirect ( KeyValue ) )
        KeyValue = CosNewRef ( _CosDoc( KeyValue ), _CosObjID ( KeyValue), 
            _CosObjGeneration ( KeyValue ) );
    _CosDictValue ( CosObject, i) = KeyValue;
    _CosParent ( KeyValue ) = CO ( CosObject );
    _CosDictCount ( CosObject )++;
}
Beispiel #17
0
void *realloc(void *p, size_t s)
{
  if (!mm_initialized) {
    if (mm_initializing)
      return mm_fake_realloc(p, s);
    mm_legacy_constructor();
  }

  if (!__malloc_use_mmalloc) {
    return mm_real_realloc(p, s);
  }

  xbt_mheap_t mdp = GET_HEAP();
  if (!mdp)
    return NULL;

  LOCK(mdp);
  void* ret = mrealloc(mdp, p, s);
  UNLOCK(mdp);
  return ret;
}
Beispiel #18
0
Datei: misc.c Projekt: 8l/ted
void trim_blank_tail()
{
int row,len,i,ll;
char *ss;
for(row=0;row<Lines;row++) {
	if (!(len=edbf[row].len)) continue;
	ss=edbf[row].cstr;
	for(ll=len;ll>0 && (ss[ll-1]==' '||ss[ll-1]==9) ;ll--);
	if (!ll) {
		free(ss);
		ss=0;
		goto lll1;
	} else
	if (ll==len) continue;
	if ((ss=mrealloc(ss,ll,"trim_blank_tail"))==NULL)
		return;
lll1:
	edbf[row].cstr=ss;
	edbf[row].len=ll;
}
if (cursor_col>edbf[cursor_row].len) cursor_col=edbf[cursor_row].len;
}
Beispiel #19
0
Datei: xkey.c Projekt: 8l/ted
LoadTedrc(char *tedname, int depth, int kdefmapno)
{
FILE *fp;
char ss[8192],ibuf[2048],*tt,*uu,*vv,*ww,*xx;
int len,i,j,lno;
int hdef[128];
extern int X_inited;
KEYDEF *kdef=kdefmap[kdefmapno];
int kdefno=kdefno_m[kdefmapno];

if ((fp=init_tedrc_fname(tedname, depth))==NULL)
	return 1;

if (kdefno && !depth) {
	for(j=0;j<kdefno;j++) free(kdef[j].cmd);
	if (!kdefmapno) free_lang();
	free(kdef);
	kdefmap[kdefmapno]=NULL;
	if (kdefmapno) {
		free(mode_str_m[kdefmapno]);
		mode_str_m[kdefmapno]=NULL;
	}
	kdef=NULL;
}
#if	0
printf("-- %d %d %s\n",depth, kdefmapno, ftedrc);
#endif
if (kdef==NULL) {
	MAX_KEY_DEF=280;
	if ((kdef=mmalloc(sizeof(KEYDEF)*MAX_KEY_DEF,"LoadTedrc"))==NULL)
		exit(1);
	kdefmap[kdefmapno]=kdef;
	kdefno_m[kdefmapno]=kdefno=0;
}


if (!depth) qsort(kmap,kname_no,sizeof(KEYMAP),qcmpxk);
tedrcfname=tedname;
lno=0;
while (!feof(fp)) {
	int next_l;

	ss[0]=0;
	next_l=0;
	for(;;) {
		lno++;
		len=mfgets(ibuf,sizeof(ibuf),fp);
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\n') ibuf[--len]=0;
		if (!len) {
			next_l=1;
			break;
		}
		while (len && (ibuf[len-1]==' '||ibuf[len-1]==9)) len--;
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\\') {
			ibuf[len-1]=0;
			strcat(ss,ibuf);
		} else {
			strcat(ss,ibuf);
			break;
		}
	}
	if (next_l) continue;

	tt=skip_spc(ss);
	uu=to_spc(tt);
	vv=skip_spc(uu);
	*uu=0;
	if (tt[0]=='#')	continue;
	if (!strcmp(tt,"d")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		kdef[i].cmd=strdup(parse_Cstr(tedname, lno,xx,&uu));
		kdef[i].type=0;
		if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		continue;
	} else
	if (!strcmp(tt,"f")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		if (parse_stmt(tedname, lno,xx,&kdef[i].cmd,&kdef[i].type)) {
			if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		}
		continue;
	}
	if (kdefmapno)
		lper(tedname,lno,"%s for LoadKeyDefInto can accept 'f' and 'd' command only", tedname);
	if (!strcmp(tt,"s")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		*ww=0;
		for(i=0;i<sizeof(locolor)/sizeof(locolor[0]);i++)
			if (!strcmp(vv,locolor[i].cname)) break;
		if (i==sizeof(locolor)/sizeof(locolor[0]))
			lper(tedname,lno,"Unknown Def color %s",vv);
		ww=to_spc(xx);
		*ww=0;
		strcpy(locolor[i].caddr,xx);
	} else
	if (!strcmp(tt,"set")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		tt=to_spc(xx);
		if (!(*ww)) lper(tedname,lno,"argument expected");
		*ww=0;
		for(i=0;i<sizeof(sets)/sizeof(sets[0]);i++)
		if (!strcmp(sets[i].sname,vv)) break;
		if (i==sizeof(sets)/sizeof(sets[0]))
			lper2(tedname,lno,"Unknown set %s",vv);
		else {
		  *tt=0;
		  *(sets[i].saddr)=atoi(xx);
		}
	} else
	if (!strcmp(tt,"lang") && !depth) {
		extern char DirectCommentChars[];
		int keywcnt=3,LangIdx,ColIdx,AllocN=32,kwidx, MaxKeywordLen=0;
		char *ff;
		KW *kw;

		if (depth)
			p_err("cannot define 'lang' in include %s", tedname);


		tt=parse_Cstr(tedname, lno,vv,&uu);
		i=strlen(tt)+2;
		if ((vv=mmalloc(i,"LoadTedrc"))==NULL) exit(1);
		if ((kw=mmalloc(AllocN*sizeof(KW),"LoadTedrc 2"))==NULL) exit(1);

		LangExt[LangN]=strcat(strcpy(vv,tt)," ");
		kw[0].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		uu=skip_spc(uu);
		DirectCommentChars[LangN]=*uu;
		kw[1].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		kw[2].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		for(;;) {
			if (!*uu) break;
			strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
			strcpy(pc_color[ColorCnt].bg_str,getstr(vv,&uu));
			uu=skip_spc(uu);
			ww=tt=parse_Cstr(tedname, lno,uu,&vv);
			uu=vv;
			xx=tt+strlen(tt);
			for(;;) {
				char *pstr;

				tt=to_spc(ww);
				vv=skip_spc(tt);
				*(tt)=0;
				if (pstr=strchr(ww,'(')) {
					kw[keywcnt].arg=strdup(pstr);
					*pstr=0;
				} else kw[keywcnt].arg=0;
				kw[keywcnt].keyword=strdup(ww);
				if (strlen(ww) > MaxKeywordLen) MaxKeywordLen=strlen(ww);
				kw[keywcnt].coloridx=ColorCnt;
#if	0
				printf("%d %d   %d %s\n",LangN,keywcnt, ColorCnt,
				kw[keywcnt].keyword);
#endif
				keywcnt++;
				if (keywcnt+3>=AllocN) {
					AllocN+=32;
					if ((kw=mrealloc(kw,AllocN*sizeof(KW),"LoadTedrc 3"))==NULL) exit(1);
				}
				ww=vv;
				if (ww==xx) break;
			}
			ColorCnt++;
		}
		qsort(kw+3,keywcnt-3,sizeof(KW), kwcmp);
		LangKw[LangN]=kw;
		LangMaxKeywordLen[LangN]=MaxKeywordLen;
		LangKwN[LangN++]=keywcnt;
		if (LangN>=MaxLang) {
			error("Too many languages defined");
			error("Remove unused language in tedrc or modify ted.h and recompile");
			exit(1);
		}
	} else
	if (!strcmp(tt,"include")) {
		if (depth > 10) {
			error("include too many level ??");
			continue;
		}
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		*ww=0;
		LoadTedrc(vv,depth+1,kdefmapno);
		tedrcfname=tedname;
	} else
	if (!strcmp(tt,"filebrowser")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		init_reg_exp(vv);
	} else
	if (!strcmp(tt,"fontlist")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		setFontList(vv);
	} else
	if (!strcmp(tt,"LoadKeyDefInto")) {
		int no;
		char mstr[16], *p;
		tt=parse_Cstr(tedname, lno,vv,&uu);
		if (!(*tt)) lper(tedname,lno,"file name expected");
		ww=skip_spc(uu);
		if (!*ww) lper(tedname,lno,"Bind number expected");
		no=*ww-'0';
		if (no<=0 || no>=4)
			lper(tedname,lno,"Bind number must be less than 4 and greater than 0");
		if ((p=strchr(tt,'.'))==NULL) {
			mode_str_m[no]="      ";
		} else {
			p++;
			if (! *p)
				mode_str_m[no]=strdup("      ");
			else
				mode_str_m[no]=strdup(p);
		}
		LoadTedrc(tt,0,no);
	}
}
fclose(fp);

if (!depth) {
kdefno=kdefno_m[kdefmapno];
qsort(kdef,kdefno,sizeof(kdef[0]),qcmp);
bzero(hdef,sizeof(hdef));
bzero(kdefhash[kdefmapno],128*sizeof(int));
for(i=0;i<kdefno;i++) {
	j=KEYHASH(kdef[i].kcode[0]);
	if (hdef[j]) continue;
	hdef[j]=1;
	kdefhash[kdefmapno][j]=i;
}
kdefhash[kdefmapno][127]=kdefno;
for(i=126;i>=0;i--)
if (!hdef[i]) kdefhash[kdefmapno][i]=kdefhash[kdefmapno][i+1];
ReLoadTed=1;
if (X_inited) alloc_pc_colors();
}
return 0;
}
Beispiel #20
0
Datei: xkey.c Projekt: 8l/ted
ExecCommand(char *cmd, int count)
{
	int i,usta,j;
	char *ttt,*uuu;
	char *pcmd;

	pcmd=cmd;
	last_str=0;
	for(i=0;i<count;i++) {
		u_char funo=*(cmd++);
		if (func[funo].modfunc && readonly) {
			message(4,"Read only mode");
			break;
		}
		switch (func[funo].argtype) {
		case 0:
			if (rec_mac && funo!=1) {
				*(mac_ptr++)=funo;
				mac_cnt++;
				ck_mac_size();
			}
			usta=func[funo].action();
			X_loop();
			break;
		case 1:
			if (rec_mac) {
				*(mac_ptr++)=funo;
				*(mac_ptr++)=*cmd;
				mac_cnt++;
				ck_mac_size();
			}
			usta=func[funo].action(*(cmd++));
			break;
		case 2:
			if (rec_mac) {
				*(mac_ptr++)=funo;
				strcpy(mac_ptr, cmd);
				mac_ptr+=strlen(cmd)+1;
				ck_mac_size();
			}
			usta=func[funo].action(cmd);
			if (ReLoadTed) {
				ReLoadTed=0;
				return 0;
			}
			cmd+=strlen(cmd)+1;
			break;
		case 3:
			usta=func[funo].action(cmd,ttt=cmd+strlen(cmd)+1);
			if (rec_mac) {
				*(mac_ptr++)=funo;
				strcpy(mac_ptr, cmd);
				mac_ptr+=strlen(cmd)+1;
				strcpy(mac_ptr,ttt);
				mac_ptr+=strlen(ttt)+1;
				ck_mac_size();
			}
			cmd+=strlen(cmd)+1+strlen(ttt)+1;
			break;
		case 5:
		  /* for binding that needs vi keystrokes saving (dd, dw ...) */
			/* look for PlaySaveFunc */
			for (j=0;j<ckdefno;j++) {
				char *p=ckdef[j].cmd;
				if (*p==4) {
					static char *qq;
					int cmlen=cmdlen(pcmd,count);

					if ((qq=mrealloc(qq,cmlen,"feek_key"))==NULL)
						return 0;
					memcpy(qq,pcmd,cmlen);
					ckdef[j].type=count;
					*qq=4;
					ckdef[j].cmd=qq;
					saveBufType=1;
					break;
				}
			}
			usta=1;
			break;
		case 6:
			if (saveBufType) usta=1;
			else {
				putStrSave();
				return 0;
			}
			break;
		case 7:
			ttt=cmd+strlen(cmd)+1;
			uuu=ttt+strlen(ttt)+1;
      usta=func[funo].action(cmd,ttt,uuu);
			if (rec_mac) {
				*(mac_ptr++)=funo;
				strcpy(mac_ptr, cmd);
				mac_ptr+=strlen(cmd)+1;
				strcpy(mac_ptr,ttt);
				mac_ptr+=strlen(ttt)+1;
				strcpy(mac_ptr,uuu);
				mac_ptr+=strlen(uuu)+1;
				ck_mac_size();
			}
			cmd+=strlen(cmd)+1+strlen(ttt)+1+strlen(uuu)+1;
			break;
		case 8:
		{
		  int aa,bb;
		  memcpy(&aa,cmd,sizeof(int));
		  memcpy(&bb,cmd+4,sizeof(int));
      usta=func[funo].action(aa,bb);
      cmd+=sizeof(int)*2;
    }
		  break;
		}
    if (xgets_enter==-1) {
		  xgets_enter=0;
		  break;
		}
		if (usta) continue;
		disp_fname();
		disp_cur_pos();
		disp_ins_mod();
		show_cursor_w();
	}
return 1;
}
Beispiel #21
0
static void XMLCALL
startElement(void *data, const char *name, const char **atts)
{
    int i, j;
    struct xmlattribute *xmlattr;

    /* starting parsing */
    if(xml_error)
        return;
    parser_node = (struct xmlnode *) mcalloc(sizeof(struct xmlnode), 1);
    if(parser_node == NULL) {
        printf("%s: %d\n", __FILE__, __LINE__);
        xml_error = XML_ERR_MEMORY;
        return;
    }
    parser_node->parent = parser_parent[xml_depth];
    /* update parser_parent child structure */
    if(parser_parent[xml_depth]->nchild) {
        /* add new child */
        parser_parent[xml_depth]->child =
            (struct xmlnode **) mrealloc((void *)
                                         parser_parent[xml_depth]->child,
                                         (parser_parent[xml_depth]->nchild +
                                          1) * sizeof(struct xmlnode *));
        if(parser_parent[xml_depth]->child == NULL) {
            printf("%s: %d\n", __FILE__, __LINE__);
            xml_error = XML_ERR_MEMORY;
            return;
        }
        parser_parent[xml_depth]->child[parser_parent[xml_depth]->nchild] =
            parser_node;
        parser_parent[xml_depth]->nchild++;
    }
    else {
        /* first child */
        parser_parent[xml_depth]->child =
            (struct xmlnode **) mcalloc(sizeof(struct xmlnode *), 1);
        if(parser_parent[xml_depth]->child == NULL) {
            xml_error = XML_ERR_MEMORY;
            printf("%s: %d\n", __FILE__, __LINE__);
            return;
        }
        parser_parent[xml_depth]->child[0] = parser_node;
        parser_parent[xml_depth]->nchild = 1;
    }

    xml_depth++;
    if(xml_depth == parent_depth) {
        if(parent_depth == max_parent_depth) {
            xml_error = XML_ERR_MEMORY;
            printf("%s: %d\n", __FILE__, __LINE__);
            return;
        }
        parent_depth++;
    }
    parser_parent[xml_depth] = parser_node;
    parser_node->name = strdup(name);

    /* get xml node's attributes */
    for(i = 0, j = 0; atts[i]; i += 2)
        j++;
    if(j) {
        parser_node->attr =
            (struct xmlattribute **) mcalloc(sizeof(struct xmlattribute *),
                                             j);
        if(parser_node->attr == NULL) {
            xml_error = XML_ERR_MEMORY;
            printf("%s: %d\n", __FILE__, __LINE__);
            return;
        }
        parser_node->nattr = j;
        for(i = 0; i < j; i++) {
            xmlattr =
                (struct xmlattribute *) mcalloc(sizeof(struct xmlattribute),
                                                1);
            if(xmlattr == NULL) {
                xml_error = XML_ERR_MEMORY;
                printf("%s: %d\n", __FILE__, __LINE__);
                return;
            }
            xmlattr->name = strdup(atts[2 * i]);
            xmlattr->value = strdup(atts[2 * i + 1]);
            parser_node->attr[i] = xmlattr;
        }
    }
}
Beispiel #22
0
ppInt32 ULModFindOrAppendAtom(PDFLibHandle Lib, char *str)
{
	PPDFLib l   =  ( PPDFLib ) Lib;
	ppInt32 i, cmp;
	char *n;
	PppAtomNode  /* T = &( l-> AtomRoot), */
		S,P, Q;
	S = P = l->AtomRoot.Right;
	if ( !S ){
		S =  ( PppAtomNode ) mmalloc ( Lib, sizeof ( ppAtomNode ) );
		i = ( ppInt32 ) strlen ( str );
		n = ( char * ) mmalloc ( Lib, i + 1 );
		memcpy ( n, str, i + 1 );
		S->Balance = 0;
		S->ID = 0;
		S->Left = NULL;
		S->Right = NULL;
		S->String = n;
		S->EscStr = ULGetEscName ( Lib, n );
		S->Length = ULGetNameSize ( n );
		if ( ( l->AtomCount ) == l->AtomCapacity ){
			l->AtomCapacity += CalculateDelta(l->AtomCapacity);
			l->AtomArray = ( PppAtomNode *) mrealloc ( Lib, l->AtomArray, sizeof ( PppAtomNode ) * l->AtomCapacity );
		};
		l->AtomArray[l->AtomCount++] = S;
		l->AtomRoot.Right = S;
		return 0;
	}
A2 : 
	cmp = strcmp ( str, P->String );
	if ( !cmp )
		return P->ID;
	if ( cmp < 0 ){
		Q = P->Left;
		if ( !Q ){
			Q = ( PppAtomNode ) mmalloc ( Lib, sizeof ( ppAtomNode ) );
			P->Left = Q;
			goto A5;
		}
	} else{
		Q = P->Right;
		if ( !Q ){
			Q = ( PppAtomNode )mmalloc ( Lib, sizeof ( ppAtomNode ) );
			P->Right = Q;
			goto A5;
		}
	}
	/*    if ( Q->Balance ){
	T = P;
	S = Q;
	}*/
	P = Q;
	goto A2;
A5 : 
	i = ( ppInt32 ) strlen ( str );
	n = ( char * ) mmalloc ( Lib, i + 1 );
	memcpy ( n, str, i + 1 );
	Q->Balance = 0;
	Q->ID = l->AtomCount;
	Q->Left = NULL;
	Q->Right = NULL;
	Q->String = n;
	Q->EscStr = ULGetEscName ( Lib, n );
	Q->Length = ULGetNameSize ( n );
	if ( ( l->AtomCount ) == l->AtomCapacity ){
		l->AtomCapacity += CalculateDelta ( l->AtomCapacity ) ;
		l->AtomArray = ( PppAtomNode * )mrealloc ( Lib, l->AtomArray, sizeof ( PppAtomNode ) * l->AtomCapacity );
	};
	l->AtomArray[l->AtomCount] = Q;
	return l->AtomCount++;
}
// . pre-allocate memory
// . returns false and sets g_errno on error
bool TopTree::setNumNodes ( int32_t docsWanted , bool doSiteClustering ) {

	// save this
	m_docsWanted       = docsWanted;
	m_doSiteClustering = doSiteClustering;

	// reset this
	m_kickedOutDocIds = false;
	//m_lastKickedOutDocId = -1LL;
	
	// how many nodes to we need to accomodate "docsWanted" docids?
	// we boost it up here for domain/host counting for site clustering.
	m_ridiculousMax = (int64_t)docsWanted * 2;
	if ( m_ridiculousMax < 50 ) m_ridiculousMax = 50;
	int64_t numNodes = m_ridiculousMax * 256;
	// i would say limit it to 100,000 nodes regarless
	if ( numNodes > MAXDOCIDSTOCOMPUTE ) numNodes = MAXDOCIDSTOCOMPUTE;
	// craziness overflow?
	if ( numNodes < 0 ) numNodes = MAXDOCIDSTOCOMPUTE;
	// amp it up last minute, after we set numNodes, if we need to
	if ( ! m_doSiteClustering ) m_ridiculousMax = 0x7fffffff;

	// if not doing siteclustering... don't use 5gb of ram!
	// add 1 for printing "next 10" link
	if ( ! m_doSiteClustering ) numNodes = m_docsWanted + 1;

	// how many docids do we have, not FULLY counting docids from
	// "dominating" domains? aka the "variety count"
	m_vcount = 0.0;

	// limit vcount to "cap" docids per domain
	m_cap  = m_docsWanted / 50;
	if ( m_cap < 2 ) m_cap = 2;
	if ( ! m_doSiteClustering ) m_cap = 0x7fffffff;

	// to keep things more continuous as a function of "m_docsWanted" we 
	// count docids right at the "cap" as a fractional count. see below.
	m_partial = (float)(m_docsWanted % 50) / 50.0;

	// reset dom count array
	memset ( m_domCount , 0 , 4 * 256 );

	// reset domain min nodes
	for ( int32_t i = 0 ; i < 256 ; i++ )
		m_domMinNode[i] = -1;

	// return if nothing needs to be done
	if ( m_nodes && numNodes == m_numNodes ) return true;
	// save this
	//m_useSampleVectors = useSampleVectors;
	// . grow using realloc if we should
	// . alloc for one extra to use as the "empty node"
	//int32_t vecSize = 0;
	//if ( useSampleVectors ) vecSize = SAMPLE_VECTOR_SIZE ;
	char *nn ;

	int64_t oldsize = (m_numNodes+1) * ( sizeof(TopNode) );
	int64_t newsize = (  numNodes+1) * ( sizeof(TopNode) );
	// if they ask for to many, this can go negative
	if ( newsize < 0 ) {
		g_errno = ENOMEM;
		return false;
	}

	bool updated = false;
	if (! m_nodes) {
		nn=(char *)mmalloc (newsize,"TopTree");
		m_numUsedNodes = 0;
	}
	else  {
		nn=(char *)mrealloc(m_nodes,oldsize,newsize,"TopTree");
		updated = true;
	}
	if ( ! nn ) return log("query: Can not allocate %"INT64" bytes for "
			       "holding resulting docids.",  newsize);
	// save this for freeing
	m_allocSize = newsize;
	// success
	char *p = nn;
	m_nodes    = (TopNode *)p;
	m_numNodes = numNodes;
	p += (numNodes+1) * sizeof(TopNode);
	// vectors
	//if ( m_useSampleVectors ) m_sampleVectors = (int32_t *)p;
	// bail now if just realloced
	if ( updated ) return true;
	// make empty the last
	m_emptyNode = 0;
	// set it
	m_headNode = -1;
	// score info
	m_lowNode  = -1;
	m_highNode = -1;

	// setup the linked list of empty nodes
	for ( int32_t i = 0 ; i < m_numNodes ; i++ ) {
		m_nodes[i].m_parent = -2;
		m_nodes[i].m_right  = i+1;
	}
	// last node is the end of the linked list of available nodes
	m_nodes[m_numNodes-1].m_right = -1;

	// alloc space for m_t2, only if doing site clustering
	if ( ! m_doSiteClustering ) return true;

	// . we must limit domHash to m_ridiculousMax nodes
	// . "dataInPtrs" mean we have a 4 byte data that we store in the
	//   "dataPtr". this is somewhat of a hack, but we need a place to
	//   store the node number of this node in this top tree. see below.
	if ( ! m_t2.set ( 4          , // fixedDataSize
			  m_numNodes , // maxNumNodes
			  true       , // doBalancing
			  -1         , // memMax (-1-->no max)
			  false      , // ownData?
			  "tree-toptree"  ,
			  true       , // dataInPtrs?
			  NULL       , // dbname (generic)
			  12         , // keySize
			  false      ))// useProtection?
		return false;

	return true;
}
// use "mem" bytes of memory for the cache
bool DiskPageCache::growCache ( long mem ) {
	// debug msg
	//log("GROWING PAGE CACHE from %li to %li bytes", m_upperMemOff, mem );
	// don't exceed the max
	if ( mem > m_maxMemOff ) mem = m_maxMemOff; 
	// bail if we wouldn't be growing
	if ( mem <= m_upperMemOff ) return true;
	// how many pages? round up.
	long npages = mem/(m_pageSize+HEADERSIZE) + 1;

	// . we need one "available" slot for each page in the cache
	// . this is a list of memory offsets that are available
	long oldSize = m_maxAvailMemOffs * sizeof(long) ;
	long newSize = npages            * sizeof(long) ;
	long *a = (long *) mrealloc(m_availMemOff,oldSize,newSize,m_memTag);
	if ( ! a ) return log("db: Failed to regrow page cache from %li to "
			      "%li bytes. Not enough memory.",oldSize,newSize);
	m_availMemOff     = a;
	m_maxAvailMemOffs = npages;
	m_memAlloced += (newSize - oldSize);
	// debug msg
	//log("%s growCache: up %li",m_dbname,(newSize - oldSize));

	// how much more mem do we need to alloc?
	long need = mem - m_upperMemOff ;
	// how big is our last page set?
	long size = 0;
	char *ptr = NULL;
	long    i = 0;
	if ( m_numPageSets > 0 ) {
		// since we allocate everything at init this shouldn't happen
		char *xx=NULL; *xx=0;
		i    = m_numPageSets - 1;
		ptr  = m_pageSet     [ i ];
		size = m_pageSetSize [ i ];
	}
	// realloc him
	long extra = m_maxPageSetSize - size ;
	if ( extra > need ) extra = need;
	if ( m_useRAMDisk ){
		// since RAMdisk it creates a file, no reason to alloc
		m_memAlloced = need;
		m_upperMemOff = need;
		return true;
	}
	// and shared mem already has the mem at this point
	if ( m_useSHM ) {
		m_memAlloced = need;
		m_upperMemOff = need;
		return true;
	}

	char *s = (char *)mrealloc ( ptr , size , size + extra, 
				     m_memTag);
	if ( ! s ) return log("db: Failed to allocate %li bytes more "
			      "for pagecache.",extra);
	m_pageSet     [ i ] = s;
	m_pageSetSize [ i ] = size + extra;
	// if we are not adding to an existing, we are a new page set
	if ( ! ptr ) m_numPageSets++;
	// discount it
	need -= extra;
	// add to alloc count
	m_memAlloced  += extra;
	m_upperMemOff += extra;
	// debug msg
	//log("%s growCache2: up %li",m_dbname,extra);
	// if we do not need more, we are done
	if ( need == 0 ) return true;
	// otherwise, alloc new page sets until we hit it
	for ( i++ ; i < MAX_PAGE_SETS && need > 0 ; i++ ) {
		long size = need;
		if ( size > m_maxPageSetSize ) size = m_maxPageSetSize;
		need -= size;
		m_pageSet[i] = (char *) mmalloc ( size , m_memTag );
		if ( ! m_pageSet[i] ) break;
		m_pageSetSize[i]  = size;
		m_memAlloced     += size;
		m_upperMemOff    += size;
		m_numPageSets++;
		// debug msg
		//log("%s growCache3: up %li",m_dbname,size);
	}
	// update upper bound
	if ( need == 0 ) return true;
	return log(LOG_LOGIC,"db: pagecache: Bad engineer. Weird problem.");
}