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

📄 hash.c

📁 类PASCAL语言的编译器,LINUX环境的,我没试过是否正确.
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * int InitHash() * * Initialize the hash table. Simple and quick! * *****/struct ShitData {  uchar *name;  long ID;  uchar ret;  uchar *format;};struct MoreShitData {  uchar *name;  long ID;  long flags;};static ReturnCode INLINE InitHash(struct Data *scr){  ReturnCode ret;  static struct ShitData internal_functions[]={    {"abs",		FNC_ABS,	'I', "I"},    {"atoi",		FNC_ATOI,	'I', "S"},    {"closelib",	FNC_CLOSELIB,	'I', "S"},  /* amiga only */    {"debug",		FNC_DEBUG,	'I', "i"},    {"eval",		FNC_EVAL,	'I', "S"},    {"exists",          FNC_EXISTS,     'I', "Si"},    {"interpret",	FNC_INTERPRET,	'I', "S"},    {"itoa",		FNC_ITOA,	'S', "I"},    {"itoc",		FNC_ITOC,	'S', "I"},    {"joinstr",		FNC_JOINSTR,	'S', "s>"},    {"ltostr",		FNC_LTOSTR,	'S', "Ii"},    {"openlib",		FNC_OPENLIB,	'I', "SI"}, /* amiga only */    {"rename",		FNC_RENAME,     'I', "SS"},    {"sprintf",		FNC_SPRINTF,	'S', "Sa>"},    {"sscanf",          FNC_SSCANF,     'I', "SSa>"},    {"strcmp",		FNC_STRCMP,	'I', "SS"},    {"stricmp",		FNC_STRICMP,	'I', "SS"},    {"strlen",		FNC_STRLEN,	'I', "S"},    {"strncmp",		FNC_STRNCMP,	'I', "SSI"},    {"strnicmp",	FNC_STRNICMP,	'I', "SSI"},    {"strstr",		FNC_STRSTR,	'I', "SSi"},    {"stristr",		FNC_STRISTR,	'I', "SSi"},    {"strtol",		FNC_STRTOL,	'I', "Si"},    {"substr",		FNC_SUBSTR,	'S', "SII"},  };  /* FPL keywords. "else" is not included (treated special). Is is     defines as KEYWORD_ELSE */  static struct MoreShitData keywords[]={    {"auto",	CMD_AUTO,	FPL_KEYWORD_DECLARE},    {"break",	CMD_BREAK,	0},    {"case",	CMD_CASE,	0},    {"char",	CMD_INT,	FPL_KEYWORD_DECLARE|FPL_CHAR_VARIABLE},    {"const",	CMD_CONST,	FPL_KEYWORD_DECLARE},    {"continue", CMD_CONTINUE,	0},    {"default",	CMD_DEFAULT,	0},    {"do",	CMD_DO,		0},    {"double",	CMD_DOUBLE,	FPL_IGNORE},    {"else",	CMD_ELSE,	0},    {"enum",	CMD_ENUM,	FPL_IGNORE},    {"exit",	CMD_EXIT,	0},    {"export",	CMD_EXPORT,	FPL_KEYWORD_DECLARE},    {"float",   CMD_FLOAT,	FPL_IGNORE},    {"for",	CMD_FOR,	0},    {"if",	CMD_IF,		0},    {"int",	CMD_INT,	FPL_KEYWORD_DECLARE},    {"long",	CMD_INT,	FPL_KEYWORD_DECLARE},    {"register",CMD_REGISTER,	FPL_KEYWORD_DECLARE},    {"resize",	CMD_RESIZE,	0},    {"return",	CMD_RETURN,	0},    {"short",	CMD_INT,	FPL_KEYWORD_DECLARE|FPL_SHORT_VARIABLE},    {"signed",	CMD_SIGNED,	FPL_KEYWORD_DECLARE|FPL_IGNORE},    {"static",  CMD_STATIC,	FPL_KEYWORD_DECLARE},    {"string",	CMD_STRING,	FPL_KEYWORD_DECLARE},    {"struct",  CMD_STRUCT,	FPL_IGNORE},    {"switch",	CMD_SWITCH,	0},    {"typedef",	CMD_TYPEDEF,	FPL_KEYWORD_DECLARE},    {"union",	CMD_UNION,	FPL_IGNORE},    {"unsigned",CMD_UNSIGNED,	FPL_KEYWORD_DECLARE|FPL_IGNORE},    {"void",	CMD_VOID,	FPL_KEYWORD_DECLARE},    {"volatile",CMD_VOLATILE,	FPL_KEYWORD_DECLARE|FPL_IGNORE},    {"while",	CMD_WHILE,	0},  };  long i;  struct Identifier *ident;  GETMEMA(scr->hash, sizeof(struct Identifier *)* FPL_HASH_SIZE);  memset((void *)scr->hash, 0, sizeof(struct Identifier *)*FPL_HASH_SIZE);  /*   * The hash table initialization gives us a brilliant chance to bring up   * the execution speed even more by inserting the few internal functions   * into this same table. The functions will then act *EXACTLY* the same   * and we can shorten the code and much easier write internal functions   * that return strings...   */  for(i=0; i<sizeof(internal_functions)/sizeof(struct ShitData);i++) {    GETMEMA(ident, sizeof(struct Identifier));    ident->name=internal_functions[i].name;    ident->data.external.ID=internal_functions[i].ID;    ident->data.external.ret=internal_functions[i].ret;    ident->data.external.format=internal_functions[i].format;    ident->flags=FPL_INTERNAL_FUNCTION|FPL_EXPORT_SYMBOL;    ident->level=0;    ident->func=NULL; /* all functions */    ident->file= "<FPL>"; /* internal */    ident->number = 0;    ret=AddIdentifier(scr, ident);    if(ret)      break;  }  for(i=0; i<sizeof(keywords)/sizeof(struct MoreShitData);i++) {    GETMEMA(ident, sizeof(struct Identifier));    ident->name=keywords[i].name;    ident->data.external.ID=keywords[i].ID;  /* dirty enum work! */    ident->flags=FPL_EXPORT_SYMBOL|FPL_KEYWORD|keywords[i].flags;    ident->level=0;    ident->func=NULL;  /* all functions */    ident->file= "<FPL>";  /* internal */    ident->number = 0;    ret=AddIdentifier(scr, ident);    if(ret)      break;  }  return(ret);}/********************************************************************** * * int Gethash(); * * Return the hash number for the name received as argument. * *****/unsigned long Gethash(uchar *name){  unsigned long hash=0;  while(*name)    hash=(hash<<1)+*name+++(hash&(1<<31)?-2000000000:0);  return(hash);}/********************************************************************** * * void Free(); * * This function frees the resources used by this FPL session. * ***********/void REGARGS fplFree(struct Data *scr){  struct Data onstack;  onstack=*scr; /* copy the entire struct */  scr=&onstack; /* use the `stack-struct' */  FREEALL();}/********************************************************************** * * int DelIdentifier() * * Delete an identifier from the hash table. Specify 'name' or 'ident'. * ******/ReturnCode REGARGSDelIdentifier(struct Data *scr,              uchar *name, /* only needed if 'ident' is NULL! */	      struct Identifier *ident){  ReturnCode ret=FPL_OK;  if(!ident) {    /* Get the structure pointer */    CALL(GetIdentifier(scr, name, &ident));  }    /* Link the previous member in the list to the next member */  if(ident->prev)    /* If there is a previous member */    ident->prev->next=ident->next;  else    /* if this was the first in the list */    scr->hash[ident->hash%FPL_HASH_SIZE]=ident->next;  if(ident->next)    ident->next->prev=ident->prev;  if(ident->flags&FPL_INSIDE_FUNCTION &&     ident->data.inside.format) {    FREE(ident->data.inside.format);  }  if((ident->flags&FPL_EXTERNAL_FUNCTION)||     (ident->flags&(FPL_INTERNAL_FUNCTION|FPL_KEYWORD)))    /* internal or external function/keyword */    ;  else  {    FREE(ident->name);  }  FREE(ident);  return(ret);}/********************************************************************** * * fplInit(); * * Initialize a lot of FPL internal structures and references. Returns * NULL if anything went wrong! * *******/void * REGARGSfplInit(long *cmdline){  struct Data point;  struct Data *scr;  void *init;  scr=&point;  init=Init(&point, cmdline);  if(init) {    if(PutOpen(scr, NULL))      init=NULL;  }    if(!init)    FREEALLA();    return(init);}static void * INLINEInit(struct Data *scr,	/* stack oriented */     long *cmdline) /* command line info */{  ReturnCode ret;  uchar *buffer;  struct Data *ptr;  memset(scr, 0, sizeof(struct Data)); /* NULLs everything! */    /*   * Set some flags according to command line parameters:   */  if(cmdline[LINE_COMMENTNEST] ) {    scr->flags |= FPLDATA_NESTED_COMMENTS;  }  buffer=(uchar *)MALLOCA(BUF_SIZE);  if(!buffer)    /* fail! */    return(NULL);  scr->buf=buffer;  scr->cmdline = cmdline;  if(ret=InitHash(scr))    return(NULL);  ptr=(struct Data *)MALLOCA(sizeof(struct Data));  if(ptr)    *ptr=*scr; /* copy the entire structure! */  IdentNumber=0; /* identifier number to increase at every declaration */  return((void *)ptr);}long REGARGSBitToggle(long original, /* Original 32 bits */	  long bit,      /* alternate bit pattern */	  long OnOff)    /* Or/And boolean, TRUE==OR, FALSE==AND */{  if(OnOff)    return ( original | bit );  else    return ( original & ~bit );}

⌨️ 快捷键说明

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