⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 starteic.c

📁 微软的基于HMM的人脸识别原代码, 非常经典的说
💻 C
📖 第 1 页 / 共 2 页
字号:
/* starteic.c
 *
 *	(C) Copyright Dec 31 1995, Edmond J. Breen.
 *		   ALL RIGHTS RESERVED.
 * This code may be copied for personal, non-profit use only.
 *
 */

/* In accordance with the practice of fair use, I hereby acknowledge
 * that:
 */
static char *PlaugerStr_=
"Portions of this work are derived from the Standard C library, (C), 1992 by P.J. Plauger, published by Prentice-Hall and are used with permission.";


/* Modified by Intel OpenCV team. The runEiC function has been changed 
   in order to catch exceptions thrown by parser and interpreter. */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <setjmp.h>
#include <stdarg.h>

#include "MachSet.h"
#include "global.h"
#include "lexer.h"
#include "typemod.h"
#include "func.h"
#include "xalloc.h"
#include "preproc.h"
#include "emitter.h"
#include "parser.h"
#include "symbol.h"
#include "error.h"
#include "reset.h"

#if __GLIBC__ >=  2
#define signal sysv_signal
void (*sysv_signal(int sig, void (*func)(int a))) (int a);
#endif


extern void EiC_interpret(environ_t * env);
extern	char *EiC_prolineString(char *str);


#define HERE printf("%s %d\n",__FILE__,__LINE__)

char *Version =
"*************************************************************************\n"
"EiC V4.3.1 - Copyright (c) 1995 to 2000,"
" by Edmond J. Breen\n"
"EiC comes `as is' and with ABSOLUTELY NO WARRANTY OF MERCHANTIBILITY AND\n"
" FITNESS OF PURPOSE\n"
"*************************************************************************\n"
;
    

environ_t *EiC_ENV;

size_t EiC_ENV_NextEntryNum()
{
    return EiC_stab_NextEntryNum(&EiC_ENV->stab);
}

void EiC_ENV_CleanUp(size_t bot)
{
    EiC_stab_CleanUp(&EiC_ENV->stab,bot);
}

/*END STRING TABLE ROUTINES*/


void EiC_reset_env_pointers(token_t * e1, int bp)
{
    EiC_ENV->lsp = bp;
}


void EiC_markENV(char mark)
{
    EiC_stab_Mark(&EiC_ENV->stab,mark);
}	

void free_env_code(void)
{
    unsigned int i;
    InsT_t *inst;

    code_t *c = &EiC_ENV->CODE;

    while(c->prev) /* find start point */
	c = (code_t*)c->prev;
	
     inst = c->inst;
     /* rem free up other info also */
    for (i = 0; i < c->nextinst; i++, inst++)
	if (inst->opcode == jmptab) {
	    eicstack_t *s;
	    s = inst->val.p.p;
	    xfree(s->val);
	    xfree(s);
	} else if (inst->opcode == assigntype) {
	    EiC_freetype(inst->val.p.p);

	} else if(inst->opcode == halt) {
		EiC_freetype(inst->val.p.p);
	}

    EiC_freecode(c);
    EiC_ENV->CODE = *c;
}

void EiC_SaveGlobalString(ptr_t *s)
{
    int len = (char*)s->ep - (char*)s->sp;
    s->sp = s->p = EiC_stab_SaveString(&EiC_ENV->stab,s->p);
    s->ep = (char*)s->p + len;
}

/* signal handling  routines 
 *
 * If a new signal hangling rountines gets added
 * make sure it gets also added in module/stdClib/src/signal.c
 *
 */

jmp_buf env;
static int jmpOn = 0;
#define Err_   1
#define Exit_  2

char * EiC_CurrentFile =NULL;
unsigned int  EiC_CurrentLine = -1;

#define errStr(x)   if(EiC_CurrentFile) EiC_error("\n" x ", file %s, line %d\n",EiC_CurrentFile,EiC_CurrentLine)
#define eic_disaster() EiC_error("exit EiC\n");exit(1)



size_t fopen_NextEntryNum(void);
void _ffexit(size_t);

void EiC_exit_call(int i)
{
#ifndef _SEIC_
    size_t fopen_entry = fopen_NextEntryNum(); 
#if defined(WIN32) || defined(_DJGPP)
    signal(SIGTERM, EiC_exit_call);
#else
    signal(SIGUSR1, EiC_exit_call);
#endif
    _ffexit(fopen_entry);
    if(jmpOn && jmpOn++ <= 1)
      longjmp(env,Exit_);
    else
	eic_disaster();
#else
    eic_disaster();
#endif
}

void  EiC_bus_err(int i)
{

#if defined(WIN32) || defined(_DJGPP)
    signal(SIGABRT,EiC_bus_err);
#else
    signal(SIGBUS, EiC_bus_err);
#endif
    errStr("EiC bus error trapped");
    if(jmpOn && jmpOn++ <= 1)
      longjmp(env,Err_);
    else
      eic_disaster();
}
void  EiC_ill_oper(int i)
{
    signal(SIGILL, EiC_ill_oper);
    errStr("EiC illegal operation attempted\n");
    if(jmpOn && jmpOn++ <= 1)
      longjmp(env,Err_);
    else
      eic_disaster();
}
void EiC_stor_access(int i)
{
    signal(SIGSEGV, EiC_stor_access);
    errStr("EiC illegal storage access");
    if(jmpOn && jmpOn++ <= 1)  {
	longjmp(env,Err_);
    } else
	eic_disaster();
}

void EiC_float_err(int i)
{
    signal(SIGFPE, EiC_float_err);
    errStr("EiC maths  exception");
    if(jmpOn && jmpOn++ <= 1)
      longjmp(env,Err_);
    else
      eic_disaster();
}

void EiC_term_int(int i)
{
    signal(SIGINT, EiC_term_int);
    errStr("EiC interrupted");
    if(jmpOn && jmpOn++ <= 1)
      longjmp(env,Err_);
    else
      eic_disaster();
}

FILE *EiChist = NULL;
extern int EiC_verboseON, EiC_SHOWLINE, EiC_traceON, EiC_TIMER,
    EiC_interActive, EiC_showIncludes;
int silent = 0, HistoryFile = 1;
int StartUpH = 1;
int reStart = 0, prompt = 0;
int EiC_Interact = 1;
int ScriptMode = 0;
static int FREE_G_STRING = 1;


void usage(void)
{
    puts("\n\t\tEiC\n"
	 " An Extensible Interactive C interpreter\n"
	 " To start eic, type eic.\n"
	 " To exit eic, type :exit.\n"
	 "\n Usage:\n"
	 "\teic  [-Ipath] [-Dname[=var]] -[hHvVcCrR]  [[file] [fileargs]]\n"
	 " Options:\n"
	 "   C preprocessor directives:\n"
	 "\t-Ipath      search for include files in path\n"
	 "\t-Dname      define a symbolic name to the value 1\n"
	 "\t-Dname=var  define a symbolic name to the value var\n"
	 "\t            Note, there is no spaces allowed\n"
	 "   EiC directives:\n"
	 "\t-h -H       causes this usage to be displayed\n"
	 "\t-v -V       print EiC's Log information\n"
	 "\t-p          showline\n"
	 "\t-P          show path of include files\n"
	 "\t-t -T       turns trace on\n"
	 "\t-c -C       turns timer on\n"
	 "\t-e          echo HTML mode\n" 
	 "\t-r          restart EiC. Causes EiC to be re initiated\n"
         "\t               from the contents of EiChist.lst file\n"
	 "\t-R          same as `r', but prompts the user to accept\n"
	 "\t               or reject each input line first\n" 
	 "\t-s -S       run silently\n"
	 "\t-f          run in script mode\n"
	 "\t-n          no history file\n"
	 "\t-N          don't use any startup.h files\n"
	 "\t-A          Non-interactive-mode\n"
	 "\tfile        EiC will execute `file' and then stop; for example:\n"
	 "\t              % eic foo.c \n"
	 "\tfileargs    command line arguments, which get passed onto file\n"
	 );
    exit(1);
}

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;
}



void EiC_save_history(FILE *fp, int from);

extern int EiC_verboseON;

int EiC_Include_file(char *, int);
void EiC_marksyms(char);
    
char *inbuf;
extern char *EiC_nextproline();
extern int EiC_listcodeON, EiC_interpON,EiC_memdumpON;
extern unsigned long EiC_tot_memory;
extern size_t EiC_tot_alloc;

void do_displays()
{
    if(EiC_verboseON)
	printf("\ninstr = %d sARsize = %d  lsp = %d aARsize  = %d\n"
	       "EiC_tot_alloc = %lu EiC_tot_memory = %lu\n",
	       EiC_ENV->CODE.nextinst,
	       EiC_ENV->ARsize,
	       EiC_ENV->lsp,
	       EiC_ENV->LARsize,
	       (unsigned long)EiC_tot_alloc,
	       EiC_tot_memory);
    EiC_listcode(&EiC_ENV->CODE);
}

void runEiC()
{
    void EiC_remTempories(void);
    void EiC_peephole(code_t *c);
    int EiC_getHistLineNo(), hfrom = 0;

    /* Hawk start change */
	EiC_ParseError = 0;
    /* Hawk change */

    /* Hawk start change */
    __try {
    /* Hawk change */
    switch(setjmp(env)) {
	case 0:
	    jmpOn = 1;

	    EiCp_initiateReset();

#ifndef NO_HISTORY
	    hfrom = EiC_getHistLineNo();
#endif
	    inbuf = EiC_nextproline();

	    EiC_initlex(inbuf);
	    EiC_initparser();
	    EiC_parse(EiC_ENV);
	    EiC_peephole(&getenvcode(EiC_ENV));
	
	    if(EiC_listcodeON)
		do_displays();
	    if (EiC_ENV->CODE.nextinst && EiC_interpON && !EiC_ParseError)
		EiC_interpret(EiC_ENV);
	    break;
	
	default:
	    EiC_messageDisplay("EiC reports an unRecognised jmp condition in starteic.c"); 
	case Err_:
	    EiC_ParseError = 1;
	    break;
	case Exit_:
	    EiC_messageDisplay("Exit called: force clean up!\n");
	    EiC_ParseError = 1;
	    break;

	    
    }
    /* Hawk start change */
    } __finally {
    /* Hawk change */

    if (EiC_errs) 
	EiC_clear_err_msgs();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -