Exemplo n.º 1
0
void HashratSignFile(char *Path, HashratCtx *Ctx)
{
STREAM *S;
char *Tempstr=NULL, *HashStr=NULL;
double pos;
THash *Hash;

S=STREAMOpenFile(Path, SF_RDWR);
if (! S) return;


Hash=HashInit(Ctx->HashType);
HashratFinishHash(&HashStr, Ctx, Hash);
pos=STREAMSeek(S,0,SEEK_END);

Tempstr=MCopyStr(Tempstr,"hashrat-placeholder---: ",GetDateStr("%Y/%m/%d %H:%M:%S",NULL)," ",Ctx->HashType,":", HashStr,"\n",NULL);
STREAMWriteLine(Tempstr,S);
STREAMFlush(S);

STREAMSeek(S,0,SEEK_SET);
Hash=HashInit(Ctx->HashType);
HashratHashFile(Ctx, Hash, FT_FILE, Path, (off_t) pos);
HashratFinishHash(&HashStr, Ctx, Hash);


Tempstr=MCopyStr(Tempstr,"hashrat-integrity-mark: ",GetDateStr("%Y/%m/%d %H:%M:%S",NULL)," ",Ctx->HashType,":", HashStr,"\n",NULL);
STREAMSeek(S,pos,SEEK_SET);
STREAMWriteLine(Tempstr,S);
STREAMFlush(S);


DestroyString(Tempstr);
DestroyString(HashStr);
}
Exemplo n.º 2
0
void
Y_set_vars(int nArgs)
{
  Symbol *stack = sp - nArgs + 1;
  IOStream *file, *child;
  char **vars, **rvars;
  long i, nvars, nrvars;
  Dimension *dims;
  if (nArgs<2 || nArgs>3 || !stack[0].ops || !stack[1].ops)
    YError("set_vars takes exactly two or three arguments");

  file = YGetFile(stack++);
  child = file->history? file->history->child : 0;
  vars = YGet_Q(stack++, 1, &dims);
  nvars = (vars&&dims)? (dims->next? -1 : dims->number) : 0;
  if (nArgs==3) {
    rvars = YGet_Q(stack++, 1, &dims);
    nrvars = (vars&&dims)? (dims->next? -1 : dims->number) : 0;
  } else {
    rvars = 0;
    nrvars = 0;
  }
  if (nvars<0 || nrvars<0) YError("set_vars var lists must be 1D");
  if ((nvars && nvars!=file->dataTable.nItems) ||
      (nrvars && nrvars!=(child? child->dataTable.nItems : 0)))
    YError("set_vars var lists must match number of vars in file");

  if (nvars) {
    HashTable tmp;
    y_hashtmp *h = y_new_tmpobj(sizeof(y_hashtmp), y_zap_hashtmp);
    HashInit(&h->table, nvars);
    PushDataBlock(h);
    for (i=0 ; i<nvars ; i++)
      if (HashAdd(&h->table, vars[i], 0)) break;
    if (i<nvars) YError("duplicate names in set_vars static var list");
    if (p_signalling) p_abort();
    tmp = h->table;
    h->table = file->dataTable;
    file->dataTable = tmp;
    Drop(1);
  }

  if (nrvars) {
    HashTable tmp;
    y_hashtmp *h = y_new_tmpobj(sizeof(y_hashtmp), y_zap_hashtmp);
    HashInit(&h->table, nvars);
    PushDataBlock(h);
    for (i=0 ; i<nrvars ; i++)
      if (HashAdd(&h->table, rvars[i], 0)) break;
    if (i<nrvars) YError("duplicate names in set_vars record var list");
    if (p_signalling) p_abort();
    tmp = h->table;
    h->table = child->dataTable;
    child->dataTable = tmp;
    Drop(1);
  }
}
Exemplo n.º 3
0
void
EFInit()
{
    EFLayerNumNames = 1;
    EFDevNumTypes = 0;
    EFCompat = TRUE;

    HashInit(&efFreeHashTable, 32, HT_WORDKEYS);
    HashInit(&efDefHashTable, INITDEFSIZE, 0);
    HashInit(&efDevParamTable, 8, HT_STRINGKEYS);
    efSymInit();
}
Exemplo n.º 4
0
void HMACInit(HASH *Hash)
{
Hash->Ctx=(void *) HashInit(Hash->Type+5);

Hash->Update=HMACPrepare;
Hash->Finish=HMACFinish;
}
Exemplo n.º 5
0
Arquivo: scope.c Projeto: frerich/core
void NewScope(const char *name)
/*
 * Thread safe
 */
{
    Scope *ptr;

    CfDebug("Adding scope data %s\n", name);

    if (!ThreadLock(cft_vscope))
    {
        CfOut(cf_error, "", "!! Could not lock VSCOPE");
        return;
    }

    for (ptr = VSCOPE; ptr != NULL; ptr = ptr->next)
    {
        if (strcmp(ptr->scope, name) == 0)
        {
            ThreadUnlock(cft_vscope);
            CfDebug("SCOPE Object %s already exists\n", name);
            return;
        }
    }

    ptr = xcalloc(1, sizeof(Scope));

    ptr->next = VSCOPE;
    ptr->scope = xstrdup(name);
    ptr->hashtable = HashInit();
    VSCOPE = ptr;
    ThreadUnlock(cft_vscope);
}
Exemplo n.º 6
0
int HashFile(char **Return, const char *Type, const char *Path, int Encoding)
{
HASH *Hash;
STREAM *S;
char *Tempstr=NULL;
int result;

S=STREAMOpen(Path,"r");
if (! S) return(FALSE);

Hash=HashInit(Type);
if (! Hash) 
{
	STREAMClose(S);
	return(FALSE);
}


Tempstr=SetStrLen(Tempstr,4096);
result=STREAMReadBytes(S,Tempstr,4096);
while (result !=EOF)
{
	Hash->Update(Hash, Tempstr, result);
	result=STREAMReadBytes(S,Tempstr,4096);
}

DestroyString(Tempstr);
STREAMClose(S);

result=HashFinish(Hash, Encoding, Return);

return(result);
}
Exemplo n.º 7
0
Arquivo: scope.c Projeto: jeffali/core
Scope *ScopeNew(const char *name)
{
    Scope *ptr;

    if (!ThreadLock(cft_vscope))
    {
        Log(LOG_LEVEL_ERR, "Could not lock VSCOPE");
        return NULL;
    }

    for (ptr = VSCOPE; ptr != NULL; ptr = ptr->next)
    {
        if (strcmp(ptr->scope, name) == 0)
        {
            ThreadUnlock(cft_vscope);
            return NULL;
        }
    }

    ptr = xcalloc(1, sizeof(Scope));

    ptr->next = VSCOPE;
    ptr->scope = xstrdup(name);
    ptr->hashtable = HashInit();
    VSCOPE = ptr;
    ThreadUnlock(cft_vscope);

    return ptr;
}
Exemplo n.º 8
0
void ScopeClear(const char *ns, const char *name)
{
    assert(name);
    assert(!ScopeIsReserved(name));

    if (!ns)
    {
        ns = "default";
    }

    if (!ThreadLock(cft_vscope))
    {
        Log(LOG_LEVEL_ERR, "Could not lock VSCOPE");
        return;
    }

    Scope *scope = ScopeGet(ns, name);
    if (!scope)
    {
        Log(LOG_LEVEL_DEBUG, "No scope '%s' to clear", name);
        ThreadUnlock(cft_vscope);
        return;
    }

    HashFree(scope->hashtable);
    scope->hashtable = HashInit();
    Log(LOG_LEVEL_DEBUG, "Scope '%s' cleared", name);

    ThreadUnlock(cft_vscope);
}
Exemplo n.º 9
0
int HashratCheckSignedFile(char *Path, HashratCtx *Ctx)
{
STREAM *S;
char *Tempstr=NULL, *HashStr=NULL;
THash *Hash, *tmpHash;
int LineCount=0;

S=STREAMOpenFile(Path, SF_RDWR);
if (! S) return(FALSE);

Hash=HashInit(Ctx->HashType);
Tempstr=STREAMReadLine(Tempstr, S);
while (Tempstr)
{
	LineCount++;

	//hashrat-integrity-mark: 2014/10/29 21:05:19 md5:nTnlHmvVowFowmxXtm0uNw==
	if (strncmp(Tempstr, "hashrat-integrity-mark: ",24)==0)
	{
		tmpHash=Hash->Clone(Hash);
		HashFinish(tmpHash,ENCODE_BASE64,&HashStr);

		HashratOutputSigningCheck(Ctx, HashStr, Tempstr, LineCount);
	}
  Hash->Update(Hash ,Tempstr, StrLen(Tempstr));

	
	Tempstr=STREAMReadLine(Tempstr, S);
}

DestroyString(Tempstr);
DestroyString(HashStr);

return(TRUE);
}
Exemplo n.º 10
0
Arquivo: lefTech.c Projeto: radc/qflow
void
LefTechInit()
{
    HashSearch hs;
    HashEntry *he;
    lefLayer *lefl;

    if (LefInfo.ht_table != (HashEntry **) NULL)
    {
        HashStartSearch(&hs);
        while (he = HashNext(&LefInfo, &hs))
        {
            lefl = (lefLayer *)HashGetValue(he);
            if (!lefl) continue;
            lefl->refCnt--;
            if (lefl->refCnt <= 0)
            {
                /* Via detailed information, if it exists,	*/
                /* needs to have its allocated memory free'd.	*/

                if (lefl->lefClass == CLASS_VIA)
                    if (lefl->info.via.lr != NULL)
                        freeMagic(lefl->info.via.lr);

                freeMagic(lefl);
            }
        }
        HashKill(&LefInfo);
    }
    HashInit(&LefInfo, 32, HT_STRINGKEYS);
}
Exemplo n.º 11
0
Scope *ScopeNew(const char *name)
{
    Scope *ptr;

    CfDebug("Adding scope data %s\n", name);

    if (!ThreadLock(cft_vscope))
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "!! Could not lock VSCOPE");
        return NULL;
    }

    for (ptr = VSCOPE; ptr != NULL; ptr = ptr->next)
    {
        if (strcmp(ptr->scope, name) == 0)
        {
            ThreadUnlock(cft_vscope);
            CfDebug("SCOPE Object %s already exists\n", name);
            return NULL;
        }
    }

    ptr = xcalloc(1, sizeof(Scope));

    ptr->next = VSCOPE;
    ptr->scope = xstrdup(name);
    ptr->hashtable = HashInit();
    VSCOPE = ptr;
    ThreadUnlock(cft_vscope);

    return ptr;
}
Exemplo n.º 12
0
int HashBytes(char **Return, char *Type, char *text, int len, int Encoding)
{
THash *Hash;

Hash=HashInit(Type);
Hash->Update(Hash, text, len);
return(Hash->Finish(Hash, Encoding, Return));
}
Exemplo n.º 13
0
static StackFrame *StackFrameNewPromise(const Promise *owner)
{
    StackFrame *frame = StackFrameNew(STACK_FRAME_TYPE_PROMISE, true);

    frame->data.promise.owner = owner;
    frame->data.promise.variables = HashInit();

    return frame;
}
Exemplo n.º 14
0
extern void InitGlobalVarList( void )
/***********************************/
/* must be called before any other reference to GlobalVarList is made */
{
    GlobalVarArray.num = 0;
    GlobalVarArray.alloc = 20;
    GlobalVarArray.increment = 20;
    InitArray( (void **)&GlobalVarList, sizeof( a_variable ), &GlobalVarArray );
    GlobalVarHash = HashInit( HASH_SIZE, &stricmp );
}
Exemplo n.º 15
0
Hash * HashCreateAlloc(char copyKey, void *(*xMalloc)(size_t), void (*xFree)(void *)) {
    Hash * pHash = (Hash*)xMalloc(sizeof(Hash));
    if (pHash != NULL) {
        HashInit(pHash, copyKey, xMalloc, xFree);
        return pHash;
    }
    else {
        return 0;
    }
}
Exemplo n.º 16
0
int HashBytes(char **Return, const char *Type, const char *text, int len, int Encoding)
{
HASH *Hash;
int result;

Hash=HashInit(Type);
if (! Hash) return(0);
Hash->Update(Hash, text, len);
result=HashFinish(Hash, Encoding, Return);

return(result);
}
Exemplo n.º 17
0
extern void FreeGlobalVarList( bool including_real_globals )
/**********************************************************/
{
    int i, j;

    if( GlobalVarList == NULL )
        return;

    if( including_real_globals ) {
        for( i = 0; i < GlobalVarArray.num; i++ ) {
            GUIMemFree( GlobalVarList[i].name );
            GUIMemFree( GlobalVarList[i].strval );
            GUIMemFree( GlobalVarList[i].autoset );
        }
        GlobalVarArray.num = 0;
        GUIMemFree( GlobalVarList );
        if( GlobalVarHash ) {
            HashFini( GlobalVarHash );
            GlobalVarHash = NULL;
        }
    } else {
        for( i = 0; i < GlobalVarArray.num; ) {
            if( GlobalVarList[i].name[0] != '$' ) {
                GUIMemFree( GlobalVarList[i].name );
                GUIMemFree( GlobalVarList[i].strval );
                GUIMemFree( GlobalVarList[i].autoset );

                for( j = i; j < GlobalVarArray.num - 1; j++ ) {
                    memcpy( &GlobalVarList[j], &GlobalVarList[j + 1],
                        sizeof( a_variable ) );
                    GlobalVarList[j].id = j;
                    // This destroys the concept that a handle to a variable
                    // will always point to the same variable.  Between
                    // script launches, variable ids will change.
                }
                GlobalVarArray.num -= 1;
                BumpDownArray( &GlobalVarArray );
            } else {
                i++;
            }
        }
        // We have to rebuild the hash table
        if( GlobalVarHash ) {
            HashFini( GlobalVarHash );
            GlobalVarHash = HashInit( HASH_SIZE, &stricmp );
            for( i = 0; i < GlobalVarArray.num; i++ ) {
                HashInsert( GlobalVarHash, GlobalVarList[i].name, i );
            }
        }
    }
}
Exemplo n.º 18
0
void
DBTechInitType()
{
    DefaultType *dtp;
    char *cp;

    /* Clear out any old information */
    if (dbTypeNameLists.sn_next != NULL)
    {
	NameList *tbl;

	for (tbl = dbTypeNameLists.sn_next; tbl != &dbTypeNameLists;
		tbl = tbl->sn_next)
	{
	    freeMagic(tbl->sn_name);
	    freeMagic(tbl);
	}
    }

    /* Tables of short names */
    dbTypeNameLists.sn_next = &dbTypeNameLists;
    dbTypeNameLists.sn_prev = &dbTypeNameLists;

    /*
     * Add the type names to the list of known names, and set
     * the default plane for each type.
     */
    for (dtp = dbTechDefaultTypes; dtp->dt_names; dtp++)
    {
	cp = dbTechNameAdd(dtp->dt_names, (ClientData) dtp->dt_type,
			&dbTypeNameLists);
	if (cp == NULL)
	{
	    TxError("DBTechInit: can't add type names %s\n", dtp->dt_names);
	    niceabort();
	}
	DBTypeLongNameTbl[dtp->dt_type] = cp;
	DBPlane(dtp->dt_type) = dtp->dt_plane;
        TTMaskSetOnlyType(&DBLayerTypeMaskTbl[dtp->dt_type], dtp->dt_type);
    }

    /* Zero the active layers (this mask is inverted later) */
    TTMaskZero(&DBActiveLayerBits);

    /* Hash table of layer aliases, free'ing the allocated type masks */
    HashFreeKill(&DBTypeAliasTable);
    HashInit(&DBTypeAliasTable, 8, HT_STRINGKEYS);

    DBNumTypes = TT_TECHDEPBASE;
}
Exemplo n.º 19
0
int main(int argc, char **argv) {
	int i;
	long long diff;
	int *res = NULL;
	int times = 10;
	int clean_avc = 0;
	struct timespec start, end;

	if (argc > 1)
		times = atoi(argv[1]);
	if (argc > 2)
		clean_avc = atoi(argv[2]);

	Hash hmap;
	HashInit(&hmap, HASH_STRING, 0);

	char *scon = "unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023";
	char *tcon = "unconfined_u:object_r:sesqlite_public:s0";
	char *clas = "db_column";
	char *perm = "select";
	char *key = "unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 unconfined_u:object_r:sesqlite_public:s0 db_column select";

	res = malloc(sizeof(int));
	*res = selinux_check_access(scon, tcon, clas, perm, NULL);
	HashInsert(&hmap, strdup(key), strlen(key), res);

	for (i = 0; i < times; ++i) {

		if ( clean_avc != 0 ){
			cleanavc();
			HashClear(&hmap);
		}

		GETTIME(start)

		res = HashFind(&hmap, key, strlen(key));
		if (res == NULL) {
			res = malloc(sizeof(int));
			*res = selinux_check_access(scon, tcon, clas, perm, NULL);
			HashInsert(&hmap, strdup(key), strlen(key), res);
		}

		GETTIME(end)
		diff = TIMESPEC_DIFF(start, end);
		printf("%lld\n", diff);
	}

	return 0;
}
Exemplo n.º 20
0
/* Build a hash table containing all terms in zText. */
static int build_terms(Hash *terms, sqlite3_tokenizer *pTokenizer,
                       const char *zText, sqlite_int64 iDocid){
  sqlite3_tokenizer_cursor *pCursor;
  const char *pToken;
  int nTokenBytes;
  int iStartOffset, iEndOffset, iPosition;

  int rc = pTokenizer->pModule->xOpen(pTokenizer, zText, -1, &pCursor);
  if( rc!=SQLITE_OK ) return rc;

  pCursor->pTokenizer = pTokenizer;
  HashInit(terms, HASH_STRING, 1);
  while( SQLITE_OK==pTokenizer->pModule->xNext(pCursor,
                                               &pToken, &nTokenBytes,
                                               &iStartOffset, &iEndOffset,
                                               &iPosition) ){
    DocList *p;

    /* Positions can't be negative; we use -1 as a terminator internally. */
    if( iPosition<0 ) {
      rc = SQLITE_ERROR;
      goto err;
    }

    p = HashFind(terms, pToken, nTokenBytes);
    if( p==NULL ){
      p = docListNew(DL_POSITIONS_OFFSETS);
      docListAddDocid(p, iDocid);
      HashInsert(terms, pToken, nTokenBytes, p);
    }
    docListAddPosOffset(p, iPosition, iStartOffset, iEndOffset);
  }

err:
  /* TODO(shess) Check return?  Should this be able to cause errors at
  ** this point?  Actually, same question about sqlite3_finalize(),
  ** though one could argue that failure there means that the data is
  ** not durable.  *ponder*
  */
  pTokenizer->pModule->xClose(pCursor);
  return rc;
}
Exemplo n.º 21
0
Arquivo: scope.c Projeto: jeffali/core
void ScopeClear(const char *name)
{
    if (!ThreadLock(cft_vscope))
    {
        Log(LOG_LEVEL_ERR, "Could not lock VSCOPE");
        return;
    }

    Scope *scope = ScopeGet(name);
    if (!scope)
    {
        Log(LOG_LEVEL_DEBUG, "No such scope to clear");
        ThreadUnlock(cft_vscope);
        return;
    }

    HashFree(scope->hashtable);
    scope->hashtable = HashInit();

    ThreadUnlock(cft_vscope);
}
Exemplo n.º 22
0
Arquivo: main.c Projeto: thgreiner/amy
int main(int argc, char *argv[])
{
#if HAVE_SETBUF
    setbuf(stdin, NULL);
#endif
       
    OpenLogFile("Amy.log");

    InitMoves();

    InitAll();
    HashInit();

    /*
     * Process rc file first, then command line options. This way command
     * line options can override rc file settings.
     */

    ProcessRCFile();
    ProcessOptions(argc, argv);

    ShowVersion();

    AllocateHT();
    InitEGTB(EGTBPath);
    RecogInit();

    DoBookLearning();

    Print(0, "\n");

    strcpy(AutoSaveFileName, GetTmpFileName());

    /* Ensure true random behavior. */
    InitRandom(GetTime());

    StateMachine();

    return 0;
}
Exemplo n.º 23
0
Scope *ScopeNew(const char *ns, const char *scope)
{
    assert(scope);

    if (!ns)
    {
        ns = "default";
    }

    if (!ThreadLock(cft_vscope))
    {
        Log(LOG_LEVEL_ERR, "Could not lock VSCOPE");
        return NULL;
    }

    for (Scope *ptr = VSCOPE; ptr != NULL; ptr = ptr->next)
    {
        if (strcmp(ptr->ns, ns) == 0 && strcmp(ptr->scope, scope) == 0)
        {
            ThreadUnlock(cft_vscope);
            return NULL;
        }
    }

    Scope *ptr = xcalloc(1, sizeof(Scope));

    ptr->hashtable = HashInit();
    ptr->ns = xstrdup(ns);
    ptr->scope = xstrdup(scope);
    assert(ptr->scope);
    ptr->next = VSCOPE;
    VSCOPE = ptr;

    assert(VSCOPE->scope);

    ThreadUnlock(cft_vscope);

    return ptr;
}
Exemplo n.º 24
0
void ScopeClearSpecial(SpecialScope scope)
{
    if (!ThreadLock(cft_vscope))
    {
        Log(LOG_LEVEL_ERR, "Could not lock VSCOPE");
        return;
    }

    Scope *ptr = ScopeGet(NULL, SpecialScopeToString(scope));
    if (!ptr)
    {
        Log(LOG_LEVEL_DEBUG, "No special scope '%s' to clear", SpecialScopeToString(scope));
        ThreadUnlock(cft_vscope);
        return;
    }

    HashFree(ptr->hashtable);
    ptr->hashtable = HashInit();
    Log(LOG_LEVEL_DEBUG, "Special scope '%s' cleared", SpecialScopeToString(scope));

    ThreadUnlock(cft_vscope);
}
Exemplo n.º 25
0
void ScopeClear(const char *name)
{
    CfDebug("Clearing scope %s\n", name);

    if (!ThreadLock(cft_vscope))
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "!! Could not lock VSCOPE");
        return;
    }

    Scope *scope = ScopeGet(name);
    if (!scope)
    {
        CfDebug("No such scope to clear\n");
        ThreadUnlock(cft_vscope);
        return;
    }

    HashFree(scope->hashtable);
    scope->hashtable = HashInit();

    ThreadUnlock(cft_vscope);
}
Exemplo n.º 26
0
static int build_terms(Hash *terms, sqlite3_tokenizer *pTokenizer,
                       const char *zText, sqlite_int64 iDocid){
  sqlite3_tokenizer_cursor *pCursor;
  const char *pToken;
  int nTokenBytes;
  int iStartOffset, iEndOffset, iPosition;

  int rc = pTokenizer->pModule->xOpen(pTokenizer, zText, -1, &pCursor);
  if( rc!=SQLITE_OK ) return rc;

  pCursor->pTokenizer = pTokenizer;
  HashInit(terms, HASH_STRING, 1);
  while( SQLITE_OK==pTokenizer->pModule->xNext(pCursor,
                                               &pToken, &nTokenBytes,
                                               &iStartOffset, &iEndOffset,
                                               &iPosition) ){
    DocList *p;

    
    if( iPosition<0 ) {
      rc = SQLITE_ERROR;  
      goto err;
    }

    p = HashFind(terms, pToken, nTokenBytes);
    if( p==NULL ){
      p = docListNew(DL_POSITIONS_OFFSETS);
      docListAddDocid(p, iDocid);
      HashInsert(terms, pToken, nTokenBytes, p);
    }
    docListAddPosOffset(p, iPosition, iStartOffset, iEndOffset);
  }

err:
  pTokenizer->pModule->xClose(pCursor);
  return rc;
}
Exemplo n.º 27
0
/* Simple version of #define and #undef processor. */
int main() {
  char word[kMaxWord];
  char *name;
  char defn[kMaxWord];
  LinkNode *p;
  int len = 0, i = 0;
  enum ParserState state = kStart;

  HashTable hash_table[kHashSize];
  HashInit(hash_table, kHashSize);

  memset(word, 0, kMaxWord);
  memset(defn, 0, kMaxWord);

  while (GetWord(word, kMaxWord) != EOF) {
    switch (state) {
      case kStart:
        if (strcmp(word, "#define") == 0) {
          state = kDefine;
        } else if (strcmp(word, "#undef") == 0) {
          state = kUnDef;
        } else if (!isalpha(word[0])) {
          printf("%s", word);
        } else if ((p = HashSearch(hash_table, word)) == NULL) {
          printf("%s", word);
        } else {
          ungets(p->defn);
        }
        break;
      case kDefine:
        if (isalpha(word[0])) {
          name = strdup(word);
          state = kName;
        } else {
          printf("Error: non-alpha name");
          exit(1);
        }
        break;
      case kName:
        if (word[0] == '\n') {
          printf("Error: incomplate define");
          exit(1);
        } else {
          strcpy(defn, word);
          len += strlen(word);
          state = kDefn;
        }
        break;
      case kDefn:
        if (word[0] != '\n' && len < kMaxWord) {
          strcat(defn, word);
          len += strlen(word);
        } else {
          HashInsert(hash_table, name, defn);
          state = kStart;
        }
        break;
      case kUnDef:
        if (isalpha(word[0])) {
          HashDelete(hash_table, name);
          state = kStart;
        } else {
          printf("Error: non-alpha name");
          exit(1);
        }
        break;
    }
  }
  return 0;
}
Exemplo n.º 28
0
void ap_open_diag_raw(int diagFile)
{
    diag_file = diagFile;
    diag_levels = (THash*)malloc(sizeof(THash));
    HashInit(diag_levels);
}
Exemplo n.º 29
0
void
DBTypeInit()
{
    HashInit(&DBTypeAliasTable, 8, HT_STRINGKEYS);
}
Exemplo n.º 30
0
void Kyokumen::Init(int suji, int dan, int promote, int teNum, KomaInf ban[MAX_DAN][MAX_SUJI], int hand[EHI+1])
{
	HashInit();
	m_KyokumenHashVal = 0;
	m_HandHashVal = 0;
	m_HashVal = 0;
	
	memset(m_BanPadding1, WALL, sizeof(m_BanPadding1));
	memset(m_Ban, WALL, sizeof(m_Ban));
	memset(m_BanPadding2, WALL, sizeof(m_BanPadding2));
	m_TeNum = teNum;
	m_LastTe = Te(0, 0, EMPTY, EMPTY);
	m_KingS = 0;
	m_KingE = 0;
	m_Suji = suji;
	m_Dan = dan;
	m_Promote = promote;
	m_Value = 0;
	
	int idxD;
	int idxS;
	for (idxD=0; idxD < m_Dan; idxD++) {
		for (idxS=0; idxS < m_Suji; idxS++) {
			KomaPos pos = COLROW2KOMAPOS(idxS+1, m_Suji, idxD+1, m_Dan);
			m_Ban[pos] = ban[idxD][idxS];
			m_KyokumenHashVal ^= m_HashSeed[m_Ban[pos]][pos];
			if (m_Ban[pos] == SOU) {
				m_KingS = pos;
			}
			else if (m_Ban[pos] == EOU) {
				m_KingE = pos;
			}
			m_Value += KomaValue[m_Ban[pos]];
		}
	}
	
	KomaInf inf;
	int num;
	for (inf=EMPTY; inf < EHI+1; inf++) {
		m_Hand[inf] = hand[inf];
		m_Value += HandValue[inf] * m_Hand[inf];
		for (num=1; num <= m_Hand[inf]; num++) {
			m_HandHashVal ^= m_HandHashSeed[inf][num];
		}
	}
	
	InitControl();
	
	m_HashVal = m_KyokumenHashVal ^ m_HandHashVal;
	int i;
	for (i=0; i <= MAX_TE_HISTORY; i++) {
		m_HashHistory[i] = 0;
		m_OuteHistory[i] = 0;
	}
	m_HashHistory[m_TeNum] = m_HashVal;
	if (GetTeban() == SELF) {
		// 現在の手番が先手ということは、現在の局面に成った指し手は後手ということになる.
		// 後手が王手をしている状態かどうかを履歴に取っておく.
		m_OuteHistory[m_TeNum] = m_ControlE[m_KingS];
	}
	else {
		m_OuteHistory[m_TeNum] = m_ControlS[m_KingE];
	}
}