Esempio n. 1
0
void EiC_comm_switch(void)
{
    int EiC_insertpath(char *);
    int EiC_removepath(char *);
    void EiC_listpath(void);
    char EiC_nextchar(void);
    
    char *buf;
    if (EiC_lexan() == ID) {
	if(EiC_gettype(token->Val.sym->type) == ID) {
	    EiC_remsym(token->Val.sym);
	}

	buf = getNextInput();
	    
	switch(EiC_LEXEM[0]) {
	  case 'I':
	    if(!*buf || !EiC_insertpath(buf))
	     EiC_warningerror("Failed to add path"); 
	    break;
	  case 'R':
	    if(!*buf || !EiC_removepath(buf))
	     EiC_warningerror("Failed to remove path"); 
	    break;
	  case 'L':
	    EiC_listpath();break;
	  default:	    
	    EiC_error("Unknown command switch");
	}	    	    
	    
    } else 
	EiC_error("Expected command switch");

}
Esempio n. 2
0
static int show(void)
{
    int t;
    int h = EiC_work_tab;
    AR_t arg;

    EiC_work_tab = stand_tab;

    if ((t = EiC_lexan()) == ID || t == TYPENAME) {
	if(!EiC_showMacro(token->Val.sym->id)) { /* test macros first */
	    t = EiC_gettype(token->Val.sym->type);
	    if (t == ID) {
		EiC_remsym(token->Val.sym);
		/*
		 * check for struct/union tag name.
		 */
		if ((token->Val.sym = EiC_lookup(tag_tab, EiC_LEXEM)) == NULL) {
		    EiC_error("Unknown identifier %s",EiC_LEXEM);
		    return 0;
		}
		fputs("Tag::",stdout);
	    }

	    displaySclass(token->Val.sym);
	    fputs(token->Val.sym->id, stdout);
	    fputs(" -> ", stdout);
	    EiC_showdectype(token->Val.sym->type, 1,stdout);
	    fputc('\n',stdout);
	    
/* -----------------------------------------------------*/
	   
	    t = EiC_gettype(token->Val.sym->type);
	    if (! (token->Val.sym->sclass == c_typedef ||
		   (t==t_builtin) || (t==t_func) || (t==t_funcdec))) 
	    {
              fputs("value= ", stdout);
              
              arg.v=EiC_ENV->AR[token->Val.sym->val.ival].v;
              arg.type = token->Val.sym->type;
    
              EiC_showvalue(&arg);
              
             } 
             

/* -------------------------------------------------*/
	    if (t == t_func && EiC_listcodeON) {
		if (EiC_ENV->AR[token->Val.sym->val.ival].v.p.p)
		    EiC_listcode(EiC_ENV->AR[token->Val.sym->val.ival].v.p.p);	       
	    }
	} else
	    EiC_remsym(token->Val.sym);
    } else
	EiC_error("Expected identifier");
    EiC_work_tab = h;
    return 1;
}
Esempio n. 3
0
static int charliteral(int c)
{
	if(!bCanInsertSymbol)
	{
		//maks: solve the error when colorize "oi/oi"
		WASLITERAL = 0;
		return c;
	}

    if (c == '\\') {
	switch ((c = EiC_nextchar())) {
	case 'n': c = '\n'; break;     /* newline */
	case 't': c = '\t'; break;     /* tabspace */
	case 'v': c = '\v'; break;     /* vertical tab */
	case 'b': c = '\b'; break;     /* backspace */
	case 'r': c = '\r'; break;     /* carriage return */
	case 'f': c = '\f'; break;     /* formfeed */
	case 'a': c = '\a'; break;     /* bell */
	case '\\': c = '\\'; break;    /* backslash */
	case '\'': c = '\''; break;    /* single quote */
	case '"': c = '\"'; break;     /* double quote */
        case '?': c = '\?'; break;     /* question mark */
	case 'x':		       /* string of hex characters */
	case 'X':{
	    int i, val = 0;
	    while ((i = gethex((c = EiC_nextchar()))) > -1) {
		val = val * 16 + i;
	    }
	    retract(c);
	    if (val > 255)
		EiC_error("Illegal character hex value");
	    c = val;
	}
	break;
	default:
	    if (getoct(c) > -1) {		/* octal characters */
		int i, val = 0;
		while ((i = getoct(c)) > -1) {
		    val = val * 8 + i;
		    c = EiC_nextchar();
		}
		retract(c);
		if (val > 255)
		    EiC_error("Illegal character octal value");
		c = val;
	    } else
		EiC_error("Illegal character escape sequence `\\%c'", c);
	    break;
	}
	WASLITERAL = 1;
    } else
	WASLITERAL = 0;
    return ((signed char )c);
}
Esempio n. 4
0
static int rm(void)
{
    unsigned long mitem;
    
    int t, h = EiC_work_tab;
    EiC_work_tab = stand_tab;
    do {
	switch(EiC_lexan()) {
	  case ID:
	  case TYPENAME:
	    t = EiC_gettype(token->Val.sym->type);
	    if (t == ID) {
		EiC_remsym(token->Val.sym);
		/*
		 * check for a tag name.
		 */
		if((token->Val.sym = EiC_lookup(tag_tab,EiC_LEXEM)) == NULL) {
		    EiC_error("Unknown identifier %s",EiC_LEXEM);
		}else {
		    checktype(token->Val.sym->type);
		    EiC_remsym(token->Val.sym);
		}
	    } else if (t == t_builtin) {
		EiC_error("Cannot remove builtin functions");
	    } else {
		checktype(token->Val.sym->type);
		EiC_remsym(token->Val.sym);
	    }
	    break;
	  case INT: 
	  case UINT:
	  case LONG:
	  case ULONG:	    
	    mitem = getmitem(&token->Val,token->Tok);
	    if(EiC_getMemMark(mitem) == MEM_LEAK)
		EiC_freeMemItem(mitem);
	    else
		EiC_error("Memory item %ld is not a leak\n", mitem);
	    break;
	  default:
	    EiC_error("UnExpected input to rm");
	    break;
	    
	}
    } while (EiC_lexan() == ',');
    retractlexan();
    EiC_work_tab = h;
    return 1;
}
Esempio n. 5
0
void EiC_getSwitchCommands(int *Argc, char ***Argv)
{

#ifndef NO_ARGV

    int argc = *Argc;
    char **argv = *Argv;
 
    static int gotSwitches = 0;

    if(gotSwitches)
	return;

    gotSwitches = 1;
    
    if(argc-- > 0)
	while(argv[1]) {
	    if(argv[1][0] == '-') {
		if(!do_sw_commands(&argv[1][1])) {
		    EiC_error("Unknown switch command [%s]\n",
			    argv[1]);
		    usage();
		} 
	    } else 
		break;
	    argv++;
	    argc--;
	}

    if(argc-- >0) {
	if(!EiC_run(argc+1,argv+1))
	    EiC_error("Failed to run %s\n",argv[1]);
	exit(0);
    }

    *Argc = argc;
    *Argv = argv;

#endif

}   
Esempio n. 6
0
int do_sw_commands(char *cp)
{
    while(*cp) {
	switch(*cp++) {
	case 'D': dodefine(cp);  return 1;
	case 'I': EiC_insertpath(cp); return 1;
	case '\?':
	case 'h':
	case 'H': usage();
	case 'c':
	case 'C': EiC_TIMER = 1; break;
	#ifndef NO_HTML
	case 'e':
	    // connect stderr to stdout 
	    dup2(1,2); 
	    // setup stdout to behave like stderr 
	    if(setvbuf(stdout,NULL,_IONBF,0) != 0)
		EiC_error("failed to setup stdout\n");
	    // inform the browser 
	    puts("Content-type: text/plain\n\n");
	    break;
	#endif
	case 'v':
	case 'V': puts(Version); exit(1);

	case 'R': prompt = 1;
	case 'r': reStart = 1;  break;

	case 's': 
	case 'S': silent = 1; break; 

	case 'f': ScriptMode = 1; break;
	case 'p': EiC_SHOWLINE = 1; break;
	case 'P': EiC_showIncludes = 1; break;
	case 't':
	case 'T': EiC_traceON = 1; break;
	case 'n': HistoryFile = 0; break;
	case 'N': StartUpH = 0; break;
	case 'A': EiC_Interact = 0; break;
	default:
	    while(isspace(*cp)) cp++;
	    if(*cp == '-')  /* assume script mode */
		while(isspace(*++cp));
	    else if(*cp)  /* catch for lines ending with whitespace */
		return 0;
	}
    }
    return 1;
}
Esempio n. 7
0
static void EiC_stringliteral(void)
{
    unsigned size, lastsize = 0, c;
    char *p=NULL;

    lex_str_start_pos = lex_lastpos = lex_curpos; //maks
    do {

	for (size = 0; ((c = charliteral(EiC_nextchar())) != '\0' || WASLITERAL) &&
	     !(c == '"' && !WASLITERAL)  && size < BSIZE; size++) 
	    EiC_LEXEM[size] = c;
    

	if (lastsize)
	    p = (char *) xrealloc(p, lastsize + size + 1);
	else
	    p = (char *) xcalloc(size + 1, sizeof(char));

	memcpy(&p[lastsize], EiC_LEXEM, size);
	lastsize += size;

	if(((c != '"') || (c == '"' && WASLITERAL)) && size == BSIZE) {
	    p[lastsize++] = c;
	    continue;
	}
	
	if (c != '"')
	    EiC_error("String literal error");

	do {
	    c = EiC_nextchar();
	    if (c == '\n')
		lex_lastpos++, lex_lineno++;
	} while (WHITE(c) || c == '\n');

	lex_lastpos = lex_curpos;
	if (!c)
	    do
		c = EiC_nextchar();
	    while (WHITE(c));
    } while (c == '"' || size == BSIZE);
    retract(c);
    p[lastsize] = '\0';
    token->Val.p.sp = token->Val.p.p = p;
    token->Val.p.ep = p + lastsize + 1;
}
Esempio n. 8
0
static int ResetEiC()
{
    char *buf;
    void EiCp_ResetStart(void);
    void EiCp_setResetStart(void);

    buf = getNextInput();
    if(buf[0]) {
	if(strcmp(buf,"here") == 0)
	   EiCp_setResetStart();
	else
	    EiC_error("Unrecgonised command `%s' for reset",buf);
    } else
	EiCp_ResetStart();

    return 0;
}
Esempio n. 9
0
static int clearCommand(void)
{
    /*
     * syntax :clear file1[,file]*
     */

    int EiC_lutClearFileEntries(char *FileName);
    void EiC_ClearFileMacros(char *fname);
    void EiC_rmIncludeFileName(char *fname);
    
    char EiC_nextchar(void);

    int EiC_IsIncluded(char *fname);
    char *buf;

    buf = getNextInput();

    if(buf[0]) {
	char *p;
	do {
	    p = strchr(buf,',');
	    if(p) 
		*p = 0;

	    if(!EiC_IsIncluded(buf))
		EiC_warningerror("Failed to find %s",buf); 
	    else {
		int r = EiC_lutClearFileEntries(buf);
		EiC_ClearFileMacros(buf);
		if(r)
		    EiC_rmIncludeFileName(buf);
	    }
	    if(p) 
		buf = p + 1;
	}while(p);
		

    } else 
	EiC_error("Expected file name");
    


    return 1;
}
Esempio n. 10
0
void * EiC_ymalloc(char *file, int lineno, size_t nbytes)
{
    void * pheap;

	if(GetGameMode())
	{
		unsigned long total = EiC_tot_memory + nbytes;
		if(total > gedMaxGameMem) //maks
		{
			//Don't alloc more then gedMaxGameMem
			EiC_error("Attempt to access %lu bytes.\n    If is correct, set the variable gedMaxGameMem=%lu or more\n    in an action before the allocation", nbytes, total);
			nbytes = 4;
		}
	}	
	realAllocatedMem = nbytes;

    pheap = (malloc)(nbytes);
	if(pheap) memset(pheap,0, realAllocatedMem/*nelems * elems*/); //maks

    assertp(pheap==NULL,STDMSG);
    install(file,lineno,pheap,nbytes);

    return pheap;
}	
Esempio n. 11
0
Label_t * EiCp_addLabel(Label_t *lab, 
			char *name, 
			int loc, int chck)
{
    Label_t *nlab;

    if(chck) { /* check 4 duplicated labels */
	nlab = lab;
	while(nlab) {	
	    if(strcmp(name, nlab->name) == 0) 
		EiC_error("Duplicate label %s",name);
	    nlab = nlab->nxt;
	}
    }
    
    nlab = xmalloc(sizeof(*nlab));
    nlab->name = xmalloc(strlen(name)+1);
    strcpy(nlab->name,name);
    nlab->loc = loc;
    
    nlab->nxt = lab;

    return nlab;
}
Esempio n. 12
0
extern int EiC_lexan(void)
{
    int t=0, loop; char c=0, EiC_nextchar();

#ifdef ILOOKAHEAD

    token = &EiC_TokenArray[EiC_TokenP];

    if(EiC_TokenR > 0) {
	EiC_TokenR--;
	EiC_TokenI++;
	EiC_TokenP=(EiC_TokenP+1)%MAX_TOKENS;
	return token->Tok;
    }


#else

    if (STOKEN != NOTOKEN) {
	STOKEN = NOTOKEN;
	return token->Tok;
    }

#endif
    
    loop  = 1;
    state = 0;
    while (loop) {
	switch (state) {
	  case 0: lex_lastpos = lex_curpos; c = EiC_nextchar();
	    state = (WHITE(c) ? 0 :
		    (c == '\n' ? lex_lineno++, 0 :
		    (c == '<' ? t = LT, 1 :
		    (c == '>' ? t = GT, 2 :
		    (c == '+' ? t = '+', 3 :
		    (c == '-' ? t = '-', 4 :
		    (c == '|' ? t = BOR, 5 :
		    (c == '&' ? t = AND, 6 :
		    (c == '\''? 7 :
		    (c == '"' ? 8 :
		    (c == '.' ? 9 :  
		    (c == '/' ? t = '/', c = EiC_nextchar(), 50 :
		    (c == '%' ? t = '%', c = EiC_nextchar(), 50 :
		    (c == '*' ? t = '*', c = EiC_nextchar(), 50 :
		    (c == '=' ? t = ASS, c = EiC_nextchar(), 50 :
		    (c == '!' ? t = NOT, c = EiC_nextchar(), 50 :
		    (c == '^' ? t = XOR, c = EiC_nextchar(), 50 :
			//(c == '~' ? t = NOTB, c = EiC_nextchar(), 50 : //maks: ~
		     fail(RELOP, c))))))))))))))))));
	    break;
	  case 1: /* get <,  <= and << */
	    if ((c = EiC_nextchar()) == '<') t = LSHT;
	    else state = 50;
	    break;
	  case 2: /* get >, >= and >> */
	    if ((c = EiC_nextchar()) == '>') t = RSHT;
	    else state = 50;
	    break;
	  case 3: c = EiC_nextchar();                         /* get +, += or ++ */
	    if (c == '+') t = INC, state = 60;
	    else state = 50;
	    break;
	  case 4: c = EiC_nextchar();                            /* get -, -= -- */
	    state = 60;
	    if (c == '-') t = DEC;
	    else if (c == '>') t = RARROW;
	    else state = 50;
	    break;
	  case 5: c = EiC_nextchar();                         /* get |, |= or || */
	    if (c == '|') t = LOR, state = 60;
	    else state = 50;
	    break;
	  case 6: c = EiC_nextchar();                         /* get &, &= or && */
	    if (c == '&') t = LAND, state = 60;
	    else state = 50;
	    break;
	  case 7:token->Val.ival = charliteral(EiC_nextchar()); /* char_constants */
	    t = TOKEN_CHAR;
	    if (EiC_nextchar() != '\'')
		EiC_error("Missing single quote '");
	    state = 60;
	    break;
	  case 8: EiC_stringliteral();                        /* string literals */
	    token->Tok = STR;
	    /*return STR;*/ loop = 0; break;
	  case 9: c = EiC_nextchar();
	    t = '.';
	    if(DIGIT(c)) 
		state = 22;
	    else
		state = 60;
	    retract(c);
	    break;
	  case 10: c = EiC_nextchar();              /* identifiers and  keywords */
	    state = (LETTER(c) ? 11 :
		    (c == '_' ? 11 : fail(ID, c)));
	    break;
	  case 11: c = EiC_nextchar();
	    state = (LETTER(c) ? 11 :
		    (DIGIT(c) ? 11 :
		    (c == '_' ? 11 : 12)));
	    break;
	  case 12: retract(c); success(ID); /*return (token->Tok);*/ loop = 0; break;

	  case 20: c = EiC_nextchar();                     /* integers and reals */
	    state = (c == '0' ? 30 :
		    (DIGIT(c) ? 21 : fail(TOKEN_INT, c)));
	    break;
	  case 21: c = EiC_nextchar();
	    state = (DIGIT(c) ? 21 :
		    (c == '.' ? 22 :
		    (c == 'e' ? 23 :
		    (c == 'E' ? 23 : 25))));
	    break;
	  case 22: c = EiC_nextchar();
	    state = (DIGIT(c) ? 22 :
		    (c == 'e' ? 23 :
		    (c == 'E' ? 23 : 26)));
	    break;
	  case 23: c = EiC_nextchar();
	    state = (c == '+' ? 24 :
		    (c == '-' ? 24 :
		    (DIGIT(c) ? 24 : fail(TOKEN_FLOAT, c) /* ??? */ )));
	    break;
	  case 24: c = EiC_nextchar();
	    state = (DIGIT(c) ? 24 : 26);
	    break;
	  case 25: checkExt(c); success(TOKEN_INT); /*return (token->Tok);*/ loop = 0; break;
	  case 26: checkExt(c); success(TOKEN_FLOAT); /*return (token->Tok);*/ loop = 0; break;
	  case 27: checkExt(c); success(HEX);   /*return (token->Tok);*/ loop = 0; break;
	  case 28: checkExt(c); success(OCTAL); /*return (token->Tok);*/ loop = 0; break;
	  case 30:			  /* check for octal and hex numbers */
	    if ((c = EiC_nextchar()) == 'x' || c == 'X') {
		while (gethex((c = EiC_nextchar())) > -1);
		state = 27;
		break;
	    }
	    if (c != '.' && c != 'e' && c != 'E') {
		while (getoct(c) > -1)
		    c = EiC_nextchar();
		state = 28;
		break;
	    }
	    retract(c); state = 21; break;
	  case 50:                                      /* mix with equal's  */
	    if (c == '=')
		switch (t) {
		  case '+': t = ADDEQ;  break;		/* += */
		  case '-': t = SUBEQ;  break;		/* -= */
		  case '/': t = DIVEQ;  break;		/* /= */
		  case '*': t = MULEQ;  break;		/* *= */
		  case '%': t = MODEQ;  break;		/* %= */
		  case ASS: t = EQ;     break;		/* == */
		  case GT:  t = GE;     break;		/* >= */
		  case LT:  t = LE;     break;		/* <= */
		  case NOT: t = NE;     break;		/* != */
		  case RSHT:t = RSHTEQ; break;		/* >>= */
		  case LSHT:t = LSHTEQ; break;		/* <<= */
		  case AND: t = ANDEQ;  break;		/* &= */
		  case BOR: t = BOREQ;  break;		/* |= */
		  case XOR: t = XOREQ;  break;		/* ^= */
		  //case NOTB: t = NOTBEQ;  break;		/* maks ~= */
		  default: retract(c);
	    }
		else if(c == '/' && t == '/') //maks
		{
			//C++ comment
			//Only for colorize
			//Comments are removed by preprocessor before parser

			do 
			{
				c = EiC_nextchar();
				
			} while(c && c != '\n');

			retract(c);

			success(MISC); 
			token->Tok = TOKEN_COMMENT;
			loop = 0;
			break;
		}
		else retract(c);
	    state = 60;
	    break;
	  case 60: success(MISC); token->Tok = t; /*return (token->Tok);*/ loop = 0; break;
	  case 100: token->Tok = EiC_nextchar(); /*return (token->Tok);*/ loop = 0; break;
	}
    }

#ifdef ILOOKAHEAD

    if(EiC_TokenI<MAX_TOKENS)
	EiC_TokenI++;

    EiC_TokenP = (EiC_TokenP +1)%MAX_TOKENS;

#endif

    return token->Tok;


}
Esempio n. 13
0
static void success(int ival)
{
    int i, size;
	
    size = (int) (lex_curpos - lex_lastpos);
    memcpy(EiC_LEXEM, &lex_buff[lex_lastpos], size);
    EiC_LEXEM[size] = '\0';
    if (Lseen) size--;
    if (Useen) size--;
    if (Fseen) size--;

    Hseen = 0;
    switch (ival) {
	case ID:
	    if ((token->Tok = EiC_iskeyword(cwords, EiC_LEXEM,
 					sizeof(cwords) / sizeof(keyword_t))) == 0) 
		{
			if(size > 64) //maks: avoid crash when enter a very long identifier
			{
				EiC_error("Identifier is too large");
				return;
			}

			token->Tok = ID;
			/* search for id in various name spaces */
			if ((token->Val.sym = EiC_lookup(EiC_work_tab, EiC_LEXEM)) == NULL)
				if(bCanInsertSymbol) token->Val.sym = EiC_insertLUT(EiC_work_tab, EiC_LEXEM, ID); //maks
				
				if (token->Val.sym)
					if (token->Val.sym->sclass == c_typedef)
						token->Tok = TYPENAME;
		}
	    break;
	case OCTAL:
	    if (Fseen)
		EiC_error("Declaration syntax error");
	    for (lexival = 0, i = 0; i < size; i++)
		lexival = lexival * 8 + getoct(EiC_LEXEM[i]);
	    Hseen = 1;
	    setintval();
	    break;
	case HEX:
	    for (lexival = 0, i = 2; i < size; i++)
		lexival = lexival * 16 + gethex(EiC_LEXEM[i]);
	    Hseen = 1;
	    setintval();
	    break;
	case TOKEN_INT:
	    for (lexival = 0, i = 0; i < size; i++)
		lexival = lexival * 10 + EiC_LEXEM[i] - '0';
	    setintval();
	    break;
	case TOKEN_FLOAT:
	    if (Useen)
		EiC_error("Declaration syntax error");
	    lexfval = atof(EiC_LEXEM);
	    setfloatval();
	    break;
	case RELOP:
	case MISC:
	    break;
    }
}
Esempio n. 14
0
static void setintval(void) //maks
{
    if (Fseen) 
	{
		lexfval = lexival;
		setfloatval();
		return;
    }
	
    if (Useen) 
	{
		if (Lseen || lexival > UINT_MAX) 
		{
			if(lexival < ULONG_MAX)
			{
				token->Tok = TOKEN_ULONG;
				token->Val.ulval = lexival;
			}
			else
			{
				EiC_error("Value is too large (max=%lu)", ULONG_MAX);
			}
		} 
		else 
		{
			if(lexival < UINT_MAX)
			{
				token->Tok = TOKEN_UINT;
				token->Val.uival = (unsigned) lexival;
			}
			else
			{
				EiC_error("Value is too large (max=%lu)", UINT_MAX);
			}		
		}
    } 
	else if (Lseen || lexival > UINT_MAX) 
	{
		if (lexival > ULONG_MAX) 
		{
			//token->Tok = TOKEN_ULONG;
			//token->Val.ulval = lexival;

			EiC_error("Value is too large (max=%lu)", ULONG_MAX);
		} 
		else if (lexival >= ULONG_MAX) 
		{
			token->Tok = TOKEN_ULONG;
			token->Val.ulval = lexival;
		} 
		else 
		{
			token->Val.lval = lexival;
			token->Tok = TOKEN_LONG;
		}
    } 
	else 
	{
		if (lexival <= INT_MAX) 
		{
			token->Val.ival = (int) lexival;
			token->Tok = TOKEN_INT;
		} 
		else if(Hseen && lexival <= UINT_MAX) 
		{
			token->Tok = TOKEN_UINT;
			token->Val.uival = (unsigned) lexival;
		} 
		else if(lexival <= LONG_MAX) 
		{	    
			token->Val.lval = (long) lexival;
			token->Tok = TOKEN_LONG;
		} 
		else 
		{
			token->Tok = TOKEN_ULONG;
			token->Val.ulval = lexival;
		}
    }
}
Esempio n. 15
0
void * EiC_yrealloc(char *file, int lineno, void *oldp, size_t nbytes)
{
    void *newp;
    int found = 0, d, bOld = 0, bno = 0; //maks

	if(nbytes <= 0 && oldp)
	{
		//maks: realloc definition
		EiC_yfree(file, lineno, oldp);
		return 0;
	}
    
    if(oldp != NULL) 
	{
		found =  xlookup(oldp);
		assertp(found < 0,STDMSG);
		bOld = 1; //maks
		bno = BNO(oldp);
    }

	if(GetGameMode())
	{
		unsigned long total = EiC_tot_memory + nbytes;
		if(total > gedMaxGameMem) //maks
		{
			//Don't alloc more then gedMaxGameMem
			EiC_error("Attempt to access %lu bytes.\n    If is correct, set the variable gedMaxGameMem=%lu or more\n    in an action before the allocation", nbytes, total);
			nbytes = 4;
		}
	}
	realAllocatedMem = nbytes;
    
    newp = realloc(oldp,nbytes);
    
    assertp(nbytes && newp == NULL,("line %d in file %s\n",lineno,file));
    
    if(bOld) //maks
	{
		d = nbytes - MTAB[bno].dbuf[found].nbytes;
		EiC_tot_memory -= MTAB[bno].dbuf[found].nbytes; //maks

		if(bno != BNO(newp)) 
		{
			
			int i;
			
			MTAB[bno].dbuf[found].p = NULL;
			MTAB[bno].dbuf[found].mark = freemark;
			i = install(file,lineno,newp,nbytes);
			/* retain creation time stamp */
			MTAB[BNO(newp)].dbuf[i].alloc_num
				= MTAB[bno].dbuf[found].alloc_num;
			
		} 
		else 
		{
			MTAB[bno].dbuf[found].p = newp;
			MTAB[bno].dbuf[found].nbytes = nbytes;
			MTAB[bno].dbuf[found].crt_file = file;
			MTAB[bno].dbuf[found].crt_lineno = lineno;

			EiC_tot_memory += nbytes; //maks
		}

		
    } 
	else
	{
		install(file,lineno,newp,nbytes);
	}
    

    return newp;
}
Esempio n. 16
0
void EiC_startEiC(int argc, char **argv)
{
    extern int EiC_load_history(char *fname,int prompt);

#if defined(WIN32) || defined(_DJGPP)
    signal(SIGABRT, EiC_bus_err);
#else
    signal(SIGBUS, EiC_bus_err);
#endif
    signal(SIGILL, EiC_ill_oper);
    signal(SIGSEGV, EiC_stor_access);
    signal(SIGFPE, EiC_float_err);
    signal(SIGINT, EiC_term_int);
#if defined(WIN32) || defined(_DJGPP)
    signal(SIGTERM, EiC_exit_call);
#else
    signal(SIGUSR1, EiC_exit_call);
#endif


    EiC_getSwitchCommands(&argc,&argv);

#ifndef NO_ARGV

    if(argc-- >0) {
        if(!EiC_run(argc+1,argv+1))
            EiC_error("Error: Failed to run %s\n",argv[1]);
        exit(0);
    }
#endif

    if(!silent) {
        fputs(Version,stdout);
    }

#ifndef NO_HISTORY
    if(StartUpH)
        EiC_setinfile("starteic.h");

    if(HistoryFile) {
        char * name = "EiChist.lst";
        if(reStart) {
            puts("Re Initiating EiC -- please wait.");
            if(EiC_load_history(name,prompt)) {
                runEiC();  /* ensure that startup files have
			  been loaded and compiled */
                EiChist = fopen(name,"w");
                EiC_save_history(EiChist,0);
                fclose(EiChist);
                EiChist=NULL;
                EiC_Include_file(name,1);
                runEiC();
                EiChist = fopen(name,"a");
            } else {
                EiC_error("Error: unable to load history file\n");
                HistoryFile = 0;
                EiChist = NULL;
            }
            puts("Done.");
        } else {
            EiChist = fopen(name,"w");
            if(!EiChist) {
                EiC_messageDisplay("Failed to create EiChist.lst\n"
                                   "Start No history file mode switch\n");
                HistoryFile = 0;
            }
        }
        if(HistoryFile)
            setvbuf(EiChist,NULL,_IOLBF,0);
    }
#endif

#ifdef PPCLIB
    setvbuf(stdout,NULL,_IONBF,0);
    setvbuf(stderr,NULL,_IONBF,0);
#endif
    /* Hawk start change */
    /*  while(1)         */
    /* runEiC();         */
    /* Hawk change       */
}