?? eicmod.c
字號:
type->alias = 1;
type = nextType(type);
}
}
static long getmitem(val_t *v, int t)
{
switch(t) {
case INT: return v->ival;
case UINT: return v->uival;
case LONG: return v->lval;
case ULONG: return v->ulval;
}
return -1;
}
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;
}
static int showhashtab(void)
{
int tab;
token_t e1;
EiC_work_tab = tab = stand_tab; /* standard name space */
EiC_inittoken(&e1);
switch(EiC_lexan()) {
TYPESPEC:
TYPEQUAL:
retractlexan();
EiC_type_name(&e1);
break;
case ID:
if(strcmp(EiC_LEXEM,"tags") == 0)
tab = tag_tab;
else if(strcmp(EiC_LEXEM,"builtin") == 0)
e1.Type = EiC_addtype(t_builtin,0);
else
retractlexan();
break;
default:
retractlexan();
}
if(e1.Type) {
showtab(tab, 0,&e1,NULL,NULL);
EiC_freetype(e1.Type);
} else {
showtab(tab,0,NULL,NULL,IsObject);
showtab(tab,0,NULL,NULL,EiC_IsFunc);
}
return 1;
}
static int extra_option(char * option)
{
EiC_work_tab = stand_tab; /* standard name space */
if (EiC_lexan() == ID) {
if(strcmp(EiC_LEXEM,option) == 0)
return 1;
else
retractlexan();
} else
retractlexan();
return 0;
}
int EiC_exit_EiC()
{
extern FILE *EiChist;
fflush(NULL);
if(EiC_verboseON)
fputs("EiC Bye\n", stdout);
if(EiChist)
fclose(EiChist);
exit(1);
return 1;
}
static int toggle_verbose()
{
EiC_verboseON = !EiC_verboseON;
return EiC_verboseON;
}
static int toggle_interface()
{
interfaceON = !interfaceON;
return interfaceON;
}
static int toggle_memdump()
{
EiC_memdumpON = !EiC_memdumpON;
return EiC_memdumpON;
}
static int toggle_memtrace()
{
EiC_memtraceON = !EiC_memtraceON;
return EiC_memtraceON;
}
static int toggle_showline()
{
EiC_SHOWLINE = !EiC_SHOWLINE;
return EiC_SHOWLINE;
}
static int toggle_timer()
{
EiC_TIMER = !EiC_TIMER;
return EiC_TIMER;
}
static int toggle_interp()
{
EiC_interpON = !EiC_interpON;
return EiC_interpON;
}
static int toggle_includes()
{
EiC_showIncludes= !EiC_showIncludes;
return EiC_showIncludes;
}
static int toggle_trace()
{
if(extra_option("funcs"))
EiC_traceFunc = !EiC_traceFunc;
else
EiC_traceFunc = 0;
if(EiC_traceFunc)
EiC_traceON = 1;
else
EiC_traceON = !EiC_traceON;
return EiC_traceON;
}
static int toggle_listcode()
{
if(extra_option("linenums"))
EiC_lineNums = !EiC_lineNums;
else
EiC_lineNums = 0;
if(EiC_lineNums)
EiC_listcodeON = 1;
else
EiC_listcodeON = !EiC_listcodeON;
return EiC_listcodeON;
}
static int showhistory()
{
#ifndef NO_HISTORY
void EiC_show_history(FILE *fp);
EiC_show_history(stdout);
#endif
return 1;
}
static int showHelp()
{
puts("-----------------------------------------------------------------------------\n"
"EiC-COMMAND SUMMARY DESCRIPTION\n"
"-----------------------------------------------------------------------------\n"
":-I path Append path to the include-file search list.\n"
":-L List search paths.\n"
":-R path Remove path from the include-file search list.\n"
":clear fname Removes the contents of file fname from EiC.\n"
":exit Terminates an EiC session.\n"
":files Display the names of all included files.\n"
":files fname Summarize the contents of the included file `fname'.\n"
":gen fname Generates EiC interface of the included file `fname'.\n"
":gen fname [<\"outfile\">] Places the interface in outfile\n"
":gen fname 4 Generates EiC interface with 4 levels of multiplexing.\n"
":help Display summary of EiC commands.\n"
":history List the history of all input commands.\n"
":includes Display path of include files when loaded.\n"
":interpreter Execute input commands. By default it is on.\n"
":listcode List stack code.\n"
":listcode linenums List stack code with associated line numbers.\n"
":memdump Show potential memory leaks.\n"
":reset Reset EiC back to its start state.\n"
":reset here Set the `reset' state to EiC's current state.\n"
":rm dddd Remove memory item dddd, which is a constant integer value.\n"
":rm f Removes f's definition from the symbol tables.\n"
":show f Shows type or macro definition of `f'.\n"
":showline Show input line after macro expansion.\n"
":status Display the status of the toggle switches.\n"
":timer Time in seconds of execution.\n"
":trace Trace function calls and line numbers during code execution.\n"
":trace funcs Trace function calls only during code execution.\n"
":variables Display declared variables and interpreter-ed function names.\n"
":variables tags Display the tag identifiers.\n"
":variables type-name Display variables of type `type-name'.\n"
":verbose Suppresses EiC's copyright and warning messages on start up.\n"
"------------------------------------------------------------------------------\n"
);
return 0;
}
static int EiCstatus()
{
struct toggle {
char * name;
int *val; }
toggles[] = {
{"includes",&EiC_showIncludes},
{"interpreter", &EiC_interpON},
{"listcode",&EiC_listcodeON},
{"memdump", &EiC_memdumpON},
{"showline",&EiC_SHOWLINE},
{"timer",&EiC_TIMER},
{"trace",&EiC_traceON},
{"verbose",&EiC_verboseON},
};
int n = sizeof(toggles)/sizeof(struct toggle);
while(n--)
printf("\t%-15s %d\n",toggles[n].name, *toggles[n].val);
return 0;
}
static symentry_t *add_eicfunc(char *name, int (*func) ())
{
symentry_t *sym;
sym = EiC_insertLUT(eic_tab, name, t_eic);
sym->level = 1;
sym->val.func = func;
return sym;
}
symentry_t *EiC_add_builtinfunc(char *name, val_t(*vfunc) ())
{
symentry_t *sym;
sym = EiC_insertLUT(stand_tab, name, ID);
EiC_freetype(sym->type);
sym->level = 1;
sym->val.vfunc = vfunc;
sym->type = EiC_addtype(t_builtin,NULL);
return sym;
}
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");
}
/* */
/* Jean-Bruno Richard personal Modification inside eicmod.c */
/* */
/* Semi-automatic module code generation */
/* functions. Thanks to the function prototype, it's possible to */
/* generate it's interfacing function to EiC. */
/* Few manual modification of the generated code are sometimes needed, */
/* but it helps a lot.... */
/* How to use it : */
/* Launch EiC, #include the desired header file */
/* (Example #include "gl.h") */
/* and use the new EiC command :gen with the name of the header file */
/* (In the example :gen gl.h) EiC will output the interface to stdout */
/* Hope it helps..... : */
/* jean-bruno.richard@mg2.com */
#ifndef NO_AUTOGEN
static int callBack=0;
static int * callNo =NULL;
static int *callpos = NULL;
static int Ncalls = 0;
static char *callName="EiC_Cfunc_";
static char *middleName="MiddleOne_";
static int MULTIPLEX = 1;
static void EiC__generateType(type_expr *t, char *id,FILE *fp, int level)
{
struct_t *S;
char tmp[100];
char out[100];
strcpy(out,id);
do {
switch(EiC_gettype(t)) {
case t_pointer: /* pointer */
sprintf(tmp,"*%s",out);
strcpy(out,tmp);
break;
case t_char: sprintf(tmp,"%s %s", "char", out); strcpy(out,tmp); break;
case t_uchar: sprintf(tmp,"%s %s", "unsigned char",out);strcpy(out,tmp); break;
case t_short: sprintf(tmp,"%s %s", "short",out);strcpy(out,tmp);break;
case t_ushort: sprintf(tmp,"%s %s", "unsigned short",out);strcpy(out,tmp);break;
case t_int: sprintf(tmp,"%s %s", "int",out);strcpy(out,tmp);break;
case t_uint: sprintf(tmp,"%s %s", "unsigned",out);strcpy(out,tmp);break;
case t_long: sprintf(tmp,"%s %s", "long",out);strcpy(out,tmp);break;
case t_ulong: sprintf(tmp,"%s %s", "unsigned long",out);strcpy(out,tmp);break;
case t_float: sprintf(tmp,"%s %s", "float",out);strcpy(out,tmp);break;
case t_double: sprintf(tmp,"%s %s", "double",out);strcpy(out,tmp);break;
case t_void: sprintf(tmp,"%s %s", "void",out);strcpy(out,tmp);break;
case t_struct:
case t_union:
if(EiC_gettype(t) == t_union)
fputs("union {",fp);
else
fputs("struct {",fp);
S = EiC_getInf(t);
if(!S) {
fputs("Incomplete", fp);
break;
}
level++;
if (level <= 2) {
int i;
for (i = 0; i < S->n; i++) {
EiC__generateType(S->type[i], S->id[i], fp,level);
fputs(";",fp);
}
}
sprintf(tmp,"} %s ",out);
strcpy(out,tmp);
level--;
break;
case t_array: /* array */
if(out[0] == '*') {
sprintf(tmp,"(%s)%s",out,"[]");
strcpy(out,tmp);
} else {
sprintf(tmp,"[%d]",(int)EiC_getInf(t));
strcat(out, tmp);
}
break;
}
} while ( (t=nextType(t)));
fprintf(fp,"%s",out);
}
static int DoCallBackNames(func_t *F, FILE *fp)
{
int x = 0;
if (F) {
int i;
callpos = realloc(callpos,sizeof(int)*getFNp(F));
for (i = 0; i < getFNp(F); i++) {
type_expr *t = getFPty(F,i);
if(EiC_gettype(t) == t_pointer &&
EiC_IsFunc(EiC_gettype(nextType(t)))) {
callNo = realloc(callNo, sizeof(*callNo) * (x+1));
callpos[x] = i;
callNo[x] = callBack++;
fprintf(fp,"static void * %s%d = NULL;\n",callName,callNo[x]);
x++;
}
}
}
return (Ncalls = x);
}
static void genCallBackFunc(type_expr *ty,
int p,
FILE *fp)
{
char buff[10];
func_t *F, *F2;
int i,v, var=0;
type_expr *t;
F = EiC_getInf(ty);
t = getFPty(F,callpos[p]);
t = nextType(t);
F2 = EiC_getInf(t);
fprintf(fp,"static ");
EiC_showdectype(nextType(t),0,fp);
fprintf(fp," %s%d(",middleName,callNo[p]);
/* check 4 varadic function calls */
for(i=0;i<getFNp(F2);i++)
if(EiC_gettype(getFPty(F2,i)) == t_var) {
var = 1;
break;
}
if(!var) {
for(i=0;i<getFNp(F2)-1;i++) {
if((v=EiC_gettype(getFPty(F2,i))) == t_void)
continue;
sprintf(buff,"x%d, ",i);
EiC__generateType(getFPty(F2,i),buff,fp,1);
}
if((v=EiC_gettype(getFPty(F2,i))) != t_void) {
sprintf(buff,"x%d ",i);
EiC__generateType(getFPty(F2,i),buff,fp,1);
}
fprintf(fp,")\n{\n");
for (i = 0; i < getFNp(F2); i++) {
if(EiC_gettype(getFPty(F2,i)) == t_void)
continue;
fprintf(fp," setArg(%d, %s%d, ",i,callName,callNo[p]);
EiC__generateType(getFPty(F2,i),"",fp,1);
fprintf(fp,",x%d);\n",i);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -