Exemplo n.º 1
0
void SSL_Version_3_0_MAC::CalculateRecordMAC_L(const uint64 &seqence_number,
											 SSL_ProtocolVersion &version, SSL_ContentType type, 
											 SSL_varvector32 &payload, const byte *padding, uint16 p_len,
											 SSL_varvector32 &target)
{
	uint16 padlen;
	SSL_secure_varvector32 headers;
	
	switch(HashID())
	{
    case SSL_MD5 : padlen = 48;
		break;  
    case SSL_SHA : padlen = 40;
		break;  
    default : return;
	}

	headers.ForwardTo(this);
	
#ifdef TST_DUMP
	DumpTofile(secret, secret.GetLength(),"SSL 3.0 Calculating MAC : indata secret ","sslcrypt.txt"); 
#endif
	
	InitHash();
	SSL_Hash::CalculateHash(secret);
	SSL_Hash::CalculateHash(0x36,padlen);
	
	uint16 len = payload.GetLength();
	headers.WriteIntegerL(seqence_number, SSL_SIZE_UINT_64, TRUE);
	headers.WriteIntegerL((byte) type, SSL_SIZE_CONTENT_TYPE, TRUE, FALSE) ;
	headers.WriteIntegerL((uint16) len, SSL_SIZE_UINT_16, TRUE, FALSE) ;
		
#ifdef TST_DUMP
	DumpTofile(headers, headers.GetLength(),"SSL 3.0 Calculating MAC : indata headers ","sslcrypt.txt"); 
#endif
	SSL_Hash::CalculateHash(headers);
	
#ifdef TST_DUMP
	DumpTofile(payload,payload.GetLength(),"SSL 3.0 Calculating MAC : indata fragment ","sslcrypt.txt"); 
#endif
	SSL_Hash::CalculateHash(payload);
	SSL_Hash::ExtractHash(target);
	


#ifdef TST_DUMP
	DumpTofile(target,hash->Size(),"SSL 3.0 Calculating MAC : indata first hash ","sslcrypt.txt"); 
#endif
	InitHash();
	SSL_Hash::CalculateHash(secret);
	SSL_Hash::CalculateHash(0x5c,padlen);
	SSL_Hash::CalculateHash(target/*,MAC_hash->Size()*/);
	SSL_Hash::ExtractHash(target);
	
#ifdef TST_DUMP
	DumpTofile(target,hash->Size(),"SSL 3.0 Calculating MAC : output ","sslcrypt.txt"); 
#endif
}
Exemplo n.º 2
0
Arquivo: hash.c Projeto: vidarh/FPL
static void * INLINE
Init(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);
}
Exemplo n.º 3
0
int main()
{
    char s[100],*p;
    int id;
    freopen("hdu1880.txt","r",stdin);
    freopen("hdu1880ans.txt","w",stdout);
    InitHash();
    while(scanf("%s",s)&&s[0]!='@')
    {
        Find(s,INSERT);
        getchar();
        gets(s);
        Find(s,INSERT);
    }
    scanf("%d",&n);
    getchar();
    while (n--)
    {
        gets(s);
        id=Find(s,QUERY);
        if (id==-1)
        {
            puts("what?");
            continue;
        }
        p=mem[id^1].s; /*因为咒语和功能是隔1的,所以直接异或最后一位即可*/
        if(p[0]!='[') puts(p);
        else
        {
            while (*(++p)!=']') putchar(*p);
            printf("\n");
        }
    }
    return 0;
}
Exemplo n.º 4
0
/*
 * Given a set of object and library files, prepare to use fuzzy linking.
 * If symbols cannot be collected from a file, 'callback' will be called
 * with the name of the offending file.
 */
void InitFuzzy( const char *objs[], const char *libs[],
                const char *libpaths[], FuzzyInitCallback callback )
/******************************************************************/
{
    unsigned            count;
    orl_handle          o_hnd;
    int                 rc = 1;
    DllToolCallbacks    dllcallbacks;
    ORLSetFuncs( orl_cli_funcs, obj_read, obj_seek, AllocMem, FreeMem );

    /*** Create a hash table ***/
    hashtable = InitHash( HASH_TABLE_SIZE, hash_symbol_name, hash_compare );

    /*** Collect all external symbols from the specified object files ***/
    if( objs != NULL ) {
        /*** Initialize ORL ***/
        o_hnd = ORLInit( &orl_cli_funcs );
        if( o_hnd == NULL ) {
            FatalError( "Got NULL orl_handle." );
        }

        /*** Scan the file(s) ***/
        for( count=0; objs[count]!=NULL; count++ ) {
            if( !handle_obj_file( objs[count], o_hnd ) ) {
                rc = (*callback)( objs[count] );
                if( !rc )  break;
            }
        }

        /*** Tell ORL to go away ***/
        if( ORLFini( o_hnd ) != ORL_OKAY ) {
            Warning( "Error calling ORLFini." );
        }
        free_list( bufflist );
    }
    if( !rc )  return;

    /*** Collect all external symbols from the specified library files ***/
    if( libs != NULL ) {
        /*** Load the WLIB DLL ***/
        dllcallbacks.printmessage = NULL;
        dllcallbacks.printmessageCRLF = print_message_crlf;
        dllcallbacks.printwithinfo2 = print_with_info2;
        dllcallbacks.printwithinfo = print_with_info;
        dllcallbacks.cookie = NULL;
        dllhandle = InitDllTool( DLLTOOL_WLIB, &dllcallbacks );
        if( dllhandle == NULL ) {
            Warning( "Cannot load WLIB DLL -- fuzzy name matching may not work" );
        } else {
            /*** Scan the file(s) ***/
            for( count=0; libs[count]!=NULL; count++ ) {
                if( !handle_lib_file( libs[count], libpaths ) ) {
                    rc = (*callback)( libs[count] );
                    if( !rc )  break;
                }
            }
            FiniDllTool( dllhandle );
        }
    }
}
Exemplo n.º 5
0
int main()
{
    char word[20];
    int i,k,nowlen;
    freopen("poj1035.txt","r",stdin);
    freopen("poj1035ans.txt","w",stdout);

    InitHash();

    n=0;
    while (scanf("%s",word) && word[0]!='#')
    {
        strcpy(dict[n].word,word);
        dict[n].id=n;
        dict[n].len=strlen(word);
        dict[n].weight=dict[n].len*100000+n;
        n++;
        Find(word,INSERT);
    }

    QSort(0,n-1);

    nowlen=0;
    memset(startpos,-1,sizeof(startpos));
    for (i=0;i<n;i++)
    {
        if (dict[i].len==nowlen) continue;
        else
        {
            nowlen=dict[i].len;
            startpos[nowlen]=i;
        }
    }
    
    while (scanf("%s",word) && word[0]!='#')
    {
        nowlen=strlen(word);
        cnt=0;
        if (Find(word,QUERY)!=-1) printf("%s is correct\n",word);
        else
        {
            printf("%s:",word);
            CheckLen(word,nowlen);
            if (nowlen==1) CheckLen(word,2);
            else if (nowlen==15) CheckLen(word,14);
            else
            {
                CheckLen(word,nowlen-1);
                CheckLen(word,nowlen+1);
            }
            QSort2(0,cnt-1);
            for (i=0;i<cnt;i++) printf(" %s",ans[i].word);
            printf("\n");
        }
    }
    
    return 0;
}
Exemplo n.º 6
0
/*
================
MakeFaceEdges
================
*/
void MakeFaceEdges (node_t *headnode)
{
	InitHash ();
	c_tryedges = 0;
	c_cornerverts = 0;

	firstmodeledge = numedges;
	firstmodelface = numfaces;
}
Exemplo n.º 7
0
void FixTJunctions(tree_t *tree)
{
	vec_t	radius;
	vec3_t	maxs, mins;

	qprintf ("---- tjunc ----\n");

	if (notjunc)
	{
		printf ("skipped\n");
		return;
	}

//
// identify all points on common edges
//

// origin points won't allways be inside the map, so extend the hash area
	radius = RadiusFromBounds( tree->mins, tree->maxs );
	VectorSet( maxs, radius, radius, radius );
	VectorSet( mins, -radius, -radius, -radius );

	InitHash (mins, maxs);

	numwedges = numwverts = 0;
	wverts = qmalloc( sizeof(*wverts) * MAX_WVERTS );
	wedges = qmalloc( sizeof(*wverts) * MAX_WEDGES );
	superface = qmalloc (sizeof(superface_t));

	tjunc_find_r (tree->headnode);

	qprintf ("%i world edges  %i edge points\n", numwedges, numwverts);

//
// add extra vertexes on edges where needed
//
	c_tjuncs = c_tjuncfaces = c_degenerateEdges = c_degenerateFaces = c_rotated = 0;

	tjunc_fix_r (tree->headnode);

	qfree( wverts );
	qfree( wedges );
	qfree (superface);

	// Vic: report number of degenerate edges
	qprintf ("%i degenerate edges\n", c_degenerateEdges);
	qprintf ("%i degenerate faces\n", c_degenerateFaces);
	qprintf ("%i edges added by tjunctions\n", c_tjuncs);
	qprintf ("%i faces added by tjunctions\n", c_tjuncfaces);
	qprintf ("%i naturally ordered\n", c_tjuncfaces - c_rotated);
	qprintf ("%i rotated orders\n", c_rotated);
}
Exemplo n.º 8
0
CHEWING_API int chewing_Init(
		const char *dataPath,
		const char *hashPath )
{
	/* initialize Tree, Char, and Dict */
	/* FIXME: check the validation of dataPath */
	InitTree( dataPath );
	InitChar( dataPath );
	InitDict( dataPath );

	/* initialize Hash */
	/* FIXME: check the validation of hashPath */
	InitHash( hashPath );

	/* initialize SymbolTable */
	if ( ! InitSymbolTable( (char*) hashPath ) )
		InitSymbolTable( (char*) dataPath );
	if ( ! InitEasySymbolInput( (char *) hashPath ) )
		InitEasySymbolInput( (char *) dataPath );

	/* initialize HanyuPinYin table */
	if ( ! InitHanyuPinYin( hashPath ) )
		InitHanyuPinYin( dataPath );

#ifdef ENABLE_DEBUG
{
        char *dbg_path;
	int failsafe = 1;
	dbg_path = getenv( "CHEWING_DEBUG" );
	if ( dbg_path ) {
		fp_g = fopen( dbg_path, "w+" );
		if ( fp_g )
			failsafe = 0;
	}
	if ( failsafe == 1 ) {
		dbg_path = FAILSAFE_OUTPUT;
	        fp_g = fopen( dbg_path, "w+" );
		if ( ! fp_g ) {
			fprintf( stderr, 
				"Failed to record debug message in file.\n"
				"--> Output to stderr\n" );
		}
	}
	/* register debug service */
	if ( fp_g )
		addTerminateService( TerminateDebug );
}
#endif
	bTerminateCompleted = 0;
	return 0;
}
Exemplo n.º 9
0
/*
===========
tjunc
===========
*/
void
TJunc(const mapentity_t *ent, node_t *headnode)
{
    vec3_t maxs, mins;
    int i;

    Message(msgProgress, "Tjunc");

    // Guess edges = 1/2 verts
    // Verts are arbitrarily multiplied by 2 because there appears to
    // be a need for them to "grow" slightly.
    cWVerts = 0;
    tjunc_count_r(headnode);
    cWEdges = cWVerts;
    cWVerts *= 2;

    pWVerts = AllocMem(WVERT, cWVerts, true);
    pWEdges = AllocMem(WEDGE, cWEdges, true);

// identify all points on common edges

    // origin points won't allways be inside the map, so extend the hash area
    for (i = 0; i < 3; i++) {
	if (fabs(ent->maxs[i]) > fabs(ent->mins[i]))
	    maxs[i] = fabs(ent->maxs[i]);
	else
	    maxs[i] = fabs(ent->mins[i]);
    }
    VectorSubtract(vec3_origin, maxs, mins);

    InitHash(mins, maxs);

    numwedges = numwverts = 0;

    tjunc_find_r(headnode);

    Message(msgStat, "%5i world edges", numwedges);
    Message(msgStat, "%5i edge points", numwverts);

    // add extra vertexes on edges where needed
    tjuncs = tjuncfaces = 0;

    tjunc_fix_r(headnode);

    FreeMem(pWVerts, WVERT, cWVerts);
    FreeMem(pWEdges, WEDGE, cWEdges);

    Message(msgStat, "%5i edges added by tjunctions", tjuncs);
    Message(msgStat, "%5i faces added by tjunctions", tjuncfaces);
}
Exemplo n.º 10
0
/*
 * ===========
 * tjunc
 * 
 * ===========
 */
void            tjunc(node_t* headnode)
{
    vec3_t          maxs, mins;
    int             i;

    Verbose("---- tjunc ----\n");

    if (g_notjunc)
    {
        return;
    }

    //
    // identify all points on common edges
    //

    // origin points won't allways be inside the map, so extend the hash area 
    for (i = 0; i < 3; i++)
    {
        if (fabs(headnode->maxs[i]) > fabs(headnode->mins[i]))
        {
            maxs[i] = fabs(headnode->maxs[i]);
        }
        else
        {
            maxs[i] = fabs(headnode->mins[i]);
        }
    }
    VectorSubtract(vec3_origin, maxs, mins);

    InitHash(mins, maxs);

    numwedges = numwverts = 0;

    tjunc_find_r(headnode);

    Verbose("%i world edges  %i edge points\n", numwedges, numwverts);

    //
    // add extra vertexes on edges where needed
    //
    tjuncs = tjuncfaces = 0;

    tjunc_fix_r(headnode);

    Verbose("%i edges added by tjunctions\n", tjuncs);
    Verbose("%i faces added by tjunctions\n", tjuncfaces);
}
Exemplo n.º 11
0
/*
================
MakeFaceEdges
================
*/
void MakeFaceEdges (node_t *headnode)
{
	qprintf ("----- MakeFaceEdges -----\n");

	InitHash ();
	c_tryedges = 0;
	c_cornerverts = 0;

	MakeFaceEdges_r (headnode);

//	CheckEdges ();

	GrowNodeRegions (headnode);

	firstmodeledge = numedges;
	firstmodelface = numfaces;
}
Exemplo n.º 12
0
void main( void )
{
	HashTbl *HashTable;
	HashTable = InitHash(HASH_ENTRIES);
	struct timeval t1,t2;
	double timeuse;
	int i=0;
	char str[26];
	gettimeofday(&t1,NULL);

	for(i=0;i<OP_NUM;i++){
		Insert(i,HashTable);
	}
	gettimeofday(&t2,NULL);
	timeuse = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec)/1000000.0;
	printf("Use Time:%f\n",timeuse);
	Position P;
	P = Find(34,HashTable);
	printf("%d\n",Retrieve(P));
}
Exemplo n.º 13
0
// given an OBJECT IDENTIFIER, oid, to hash on, the type and it's anyId
// are installed in the OBJECT IDENTIFIER id hash tbl
void
AsnAny::InstallAnyByOid (AsnOid &oid, int anyId, AsnType *type)
{
    AnyInfo *a;
    Hash h;

    a =  new AnyInfo;
    a->anyId = anyId;
    a->oid = oid;  // copy given oid
    a->typeToClone = type;

    h = MakeHash (oid.Str(), oid.Len());

    if (AsnAny::oidHashTbl == NULL)
        AsnAny::oidHashTbl = InitHash();

    if (! Insert (AsnAny::oidHashTbl, a, h))
    {
       delete a->typeToClone;
       delete a;
    }

}  /* InstallAnyByOid */
Exemplo n.º 14
0
// Given an integer, intId, to hash on, the type and it's anyId
// are installed in the integer id hash tbl
void
AsnAny::InstallAnyByInt (AsnIntType intId, int anyId, AsnType *type)
{
    AnyInfo *a;
    Hash h;

    a = new AnyInfo;
    //  Oid will be NULL and 0 len by default constructor
    a->anyId = anyId;
    a->intId = intId;
    a->typeToClone = type;

    if (AsnAny::intHashTbl == NULL)
        AsnAny::intHashTbl = InitHash();

	 AsnInt intval = intId;
    h = MakeHash ((const char*)intval.c_str(), intval.length());
    if ( ! Insert (AsnAny::intHashTbl, a, h) )
    {
       delete a->typeToClone;
       delete a;
    }

}  /* InstallAnyByInt */
Exemplo n.º 15
0
CHEWING_API ChewingContext *chewing_new()
{
	ChewingContext *ctx;
	int ret;
	char search_path[PATH_MAX];
	char path[PATH_MAX];

	ctx = ALC( ChewingContext, 1 );
	if ( !ctx )
		goto error;

	ctx->output = ALC ( ChewingOutput, 1 );
	if ( !ctx->output )
		goto error;

	ctx->data = allocate_ChewingData();
	if ( !ctx->data )
		goto error;

	chewing_Reset( ctx );

	ret = get_search_path( search_path, sizeof( search_path ) );
	if ( ret )
		goto error;

	ret = find_path_by_files(
		search_path, DICT_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitDict( ctx->data, path );
	if ( ret )
		goto error;
	ret = InitTree( ctx->data, path );
	if ( ret )
		goto error;

	ret = InitHash( ctx->data );
	if ( !ret )
		goto error;

	ctx->cand_no = 0;

	ret = find_path_by_files(
		search_path, SYMBOL_TABLE_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitSymbolTable( ctx->data, path );
	if ( ret )
		goto error;

	ret = find_path_by_files(
		search_path, EASY_SYMBOL_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitEasySymbolInput( ctx->data, path );
	if ( ret )
		goto error;

	ret = find_path_by_files(
		search_path, PINYIN_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitPinyin( ctx->data, path );
	if ( !ret )
		goto error;

	return ctx;
error:
	chewing_delete( ctx );
	return NULL;
}
Exemplo n.º 16
0
// =====================================================================================
//  MakeFaceEdges
// =====================================================================================
void            MakeFaceEdges()
{
    InitHash();
    firstmodeledge = g_numedges;
    firstmodelface = g_numfaces;
}
Exemplo n.º 17
0
int main ()
{
  Banner ();
  InitSend ();
  fflush (stdout);
  ICI = FALSE;
  PVHashTable = NULL;
  EvalHash = NULL;
  PawnHash = NULL; /* HACK */
  PawnHashSize = (1 << 16); /* HACK */
  EvalHashSize = (1 << 15); /* HACK */
#ifdef CON_ROBBO_BUILD
  TripleHash = NULL;
  TripleHashSize = (1 << 17);
#endif
  memset ( (void*) ROOT_POSIZIONE0, 0, sizeof (typePOS));
  ROOT_POSIZIONE0->DYN_ROOT = malloc (MAXIMUM_PLY * sizeof (typeDYNAMIC));
  ROOT_POSIZIONE0->DYN = ROOT_POSIZIONE0->DYN_ROOT + 1;
  ROOT_POSIZIONE0->stop = FALSE;
  CPUS_SIZE = 1;
#ifdef YUSUF_MULTICORE
  rp_init ();
#endif
  SMP_HAS_AKTIV = FALSE;
  UCI_White_Bishops_Scale = 45;
  UCI_White_Pawn_Scale = 100;
  UCI_White_Knight_Scale = 300;
  UCI_White_Light_Scale = 310;
  UCI_White_Dark_Scale = 310;
  UCI_White_Rook_Scale = 500;
  UCI_White_Queen_Scale = 950;
  UCI_Black_Bishops_Scale = 45;
  UCI_Black_Pawn_Scale = 100;
  UCI_Black_Knight_Scale = 300;
  UCI_Black_Light_Scale = 310;
  UCI_Black_Dark_Scale = 310;
  UCI_Black_Rook_Scale = 500;
  UCI_Black_Queen_Scale = 950;
  UCI_MATERIAL_WEIGHTING = 1024;
  UCI_PAWNS_WEIGHTING = 1024;
  UCI_KING_SAFETY_WEIGHTING = 1024;
  UCI_STATIC_WEIGHTING = 1024;
  UCI_MOBILITY_WEIGHTING = 1024;

  PAWNS_HASH_ONE_EIGHTH = TRUE;
  UCI_PAWNS_HASH = 4;
  CURRENT_HASH_SIZE = 32;
  InitHash (32);
  InitPawnHash (4);
  InitPVHash (2);
  InitEvalHash (256);
#ifdef SLAB_MEMORY
  InitSlab (SLAB_SIZE);
#else
  InitSlab (0);
#endif
  InitCaptureValues (); /* SLAB_MEM */
  InitPawns (); /* SLAB_MEM? */

#ifdef USER_SPLIT
  CUT_SPLIT_DEPTH = 16;
  ALL_SPLIT_DEPTH = 14;
  PV_SPLIT_DEPTH = 14;
  SPLIT_AT_CUT = TRUE;
#endif
  SEND_CURR_MOVE = FALSE;
  USE_ALTERNATIVE_TIME = FALSE;
  TIME_IMITATE = FALSE;
  TIME_LOSE_MORE = FALSE;
  TIME_WIN_MORE = FALSE;
  BUFFER_TIME = 0;
  OUTPUT_DELAY = 0;
  UCI_PONDER = FALSE;
  VERIFY_NULL = TRUE;
  ROBBO_LOAD = ROBBO_TOTAL_LOAD = FALSE; 
  SEARCH_ROBBO_BASES = TRUE;
  MULTI_PV = 1;
  SEND_HASH = FALSE; /* aid GUI */
  DO_HASH_FULL = TRUE;
  ALLOW_INSTANT_MOVE = TRUE;
  ZOG_AKTIV = FALSE;
  strcpy (ROBBO_TRIPLE_DIR, "");
  strcpy (ROBBO_TOTAL_DIR, "");
  SEARCH_IS_DONE = TRUE;
  INFINITE_LOOP = FALSE;
#ifndef MINIMAL
  MULTI_CENTI_PAWN_PV = 65535;
  RANDOM_COUNT = 0;
  RANDOM_BITS = 1;
  ALWAYS_ANALYZE = FALSE;
  TRY_PV_IN_ANALYSIS = TRUE;
  FIXED_AGE_ANALYSIS = FALSE;
#endif

#ifdef TRACE_COMPILE
  TraceOn ();
#endif

#ifdef CON_ROBBO_BUILD
  RobboIniz ();
  InitTripleHash (1); /* ensure */
#endif
  TRY_LARGE_PAGES = FALSE;
  SUPPRESS_INPUT = FALSE;
  INPUT_BUFFER = malloc (65536);
  input_ptr = INPUT_BUFFER;
  STALL_MODE = FALSE;
  SINCE_NEW_GAME = 0;
  EASY_FACTOR = 15;
  EASY_FACTOR_PONDER = 33;
  BATTLE_FACTOR = 100;
  ORDINARY_FACTOR = 75;
  ABSOLUTE_PERCENT = 25;
  DESIRED_MILLIS =  40;
  BOOK_EXIT_MOVES = 0;
  EXTEND_IN_CHECK = FALSE;
  TRIPLE_WEAK_PROBE_DEPTH = -10;
  TRIPLE_DEFINITE_PROBE_DEPTH = 40;
  TRIPLE_DEFINITE_PROBE_HEIGHT = 5;
  LOAD_ON_WEAK_PROBE = TRUE;
  STALL_INPUT = FALSE;
  UCI_OPTION_CHESS_960 = FALSE;
#ifdef LINUX_LARGE_PAGES
  LINUX_handle_signals ();
#endif
#ifdef MODE_ANALYSIS
  ICI_HASH_MIX = FALSE;
#endif
  NewGame (ROOT_POSIZIONE0, TRUE);
  while (1)
    Input (ROOT_POSIZIONE0);
  return 0;
}
Exemplo n.º 18
0
/*
================
MakeFaceEdges
================
*/
int
MakeFaceEdges(mapentity_t *entity, node_t *headnode)
{
    int i, firstface;
    struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES];
    struct lumpdata *edges = &entity->lumps[LUMP_EDGES];
    struct lumpdata *vertices = &entity->lumps[LUMP_VERTEXES];
    struct lumpdata *faces = &entity->lumps[LUMP_FACES];

    Message(msgProgress, "MakeFaceEdges");

    cStartEdge = 0;
    for (i = 0; i < entity - map.entities; i++)
        cStartEdge += map.entities[i].lumps[LUMP_EDGES].count;

    CountData_r(entity, headnode);

    /*
     * Remember edges are +1 in BeginBSPFile.  Often less than half
     * the vertices actually are unique, although heavy use of skip
     * faces will break that assumption.  2/3 should be safe most of
     * the time without wasting too much memory...
     */
    surfedges->count = vertices->count;
    edges->count += surfedges->count;

    vertices->data = AllocMem(BSP_VERTEX, vertices->count, true);
    edges->data = AllocMem(BSP_EDGE, edges->count, true);

    // Accessory data
    pHashverts = AllocMem(HASHVERT, vertices->count, true);
    pEdgeFaces0 = AllocMem(OTHER, sizeof(face_t *) * edges->count, true);
    pEdgeFaces1 = AllocMem(OTHER, sizeof(face_t *) * edges->count, true);

    InitHash();

    firstface = map.cTotal[LUMP_FACES];
    MakeFaceEdges_r(entity, headnode, 0);

    FreeMem(pHashverts, HASHVERT, vertices->count);
    FreeMem(pEdgeFaces0, OTHER, sizeof(face_t *) * edges->count);
    FreeMem(pEdgeFaces1, OTHER, sizeof(face_t *) * edges->count);

    /* Free any excess allocated memory */
    if (vertices->index < vertices->count) {
        dvertex_t *temp = AllocMem(BSP_VERTEX, vertices->index, true);
        memcpy(temp, vertices->data, sizeof(*temp) * vertices->index);
        FreeMem(vertices->data, BSP_VERTEX, vertices->count);
        vertices->data = temp;
        vertices->count = vertices->index;
    }
    if (edges->index < edges->count) {
        void *temp = AllocMem(BSP_EDGE, edges->index, true);
        memcpy(temp, edges->data, MemSize[BSP_EDGE] * edges->index);
        FreeMem(edges->data, BSP_EDGE, edges->count);
        edges->data = temp;
        edges->count = edges->index;
    }

    if (map.cTotal[LUMP_VERTEXES] > 65535 && options.BSPVersion == BSPVERSION)
        Error("Too many vertices (%d > 65535). Recompile with the \"-bsp2\" flag to lift this restriction.", map.cTotal[LUMP_VERTEXES]);

    surfedges->data = AllocMem(BSP_SURFEDGE, surfedges->count, true);
    faces->data = AllocMem(BSP_FACE, faces->count, true);

    Message(msgProgress, "GrowRegions");

    if (options.BSPVersion == BSPVERSION)
        GrowNodeRegion_BSP29(entity, headnode);
    else
        GrowNodeRegion_BSP2(entity, headnode);

    return firstface;
}
Exemplo n.º 19
0
int read_circuit (FILE *circuit_fd)
{
    char c;
    int nerrs = 0;
    int fn, nofanin, i, j;
    int int_nog, int_nopi, int_nopo;
    int net_size;
    char symbol[MAXSTRING];
	register HASHPTR hp;
	register GATEPTR cg;
	GATEPTR pg;
	begnet=(GATEPTR)NULL;
	GATEPTR pfanin[MAXFIN+100];
	GATEPTR po_gates[MAXPO+100];
	
    int_nog = int_nopi = int_nopo = 0;
    nofanin=0;
    
    InitHash (symbol_tbl, HASHSIZE);
    
    while ((c = getsymbol (circuit_fd, symbol)) != EOF) {
			switch (c) {
				
				case '=' :
					hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0);
					//printf("in read: hp =  %s \n", symbol);
					
					if ((cg = hp->pnode) == NULL) {
						cg = (GATETYPE *)xmalloc(sizeof(GATETYPE)); 
						hp->pnode = cg;
						cg->symbol = hp;
						cg->next = begnet;
						begnet = cg;
					}
				break;
					
				case '(' :
					if ((fn = gatetype (symbol)) < 0) {
						fprintf (stderr, "Error: Gate type %s is not valid\n", symbol);
						return(-1);
					}
				break;
				
				case ',' :             
					hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0);
					if ((pg = hp->pnode) == NULL) {
						pg = (GATETYPE *)xmalloc(sizeof(GATETYPE));
						hp->pnode = pg;
						pg->symbol = hp;
						pg->index = (-1);
						pg->next = begnet;
						begnet = pg;
					}
					pfanin[nofanin++] = pg;
				break;
					
				case ')':				
					hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0);
					if ((pg = hp->pnode) == NULL) {
						pg = (GATETYPE *)xmalloc(sizeof(GATETYPE));
						hp->pnode = pg;
						pg->symbol = hp; 
						pg->index = (-1);
						pg->next = begnet;
						begnet = pg;
					}		
				
				    switch(fn) {
						
						case PI:
							int_nopi++;
							pg->index = int_nog++;
							pg->ninput = 0;
							pg->inlis=(GATEPTR *)NULL;
							pg->fn = PI;
							pg->noutput = 0;
							pg->outlis = (GATEPTR *)NULL;
						break;
						
						case PO:
							po_gates[int_nopo++] = pg;
						break;
						
						default:
							pfanin[nofanin++] = pg;

							if (cg == NULL) {
								fprintf(stderr,"Error: Syntax error in the circuit file\n");
								return(-1);
							}
						
							cg->index = int_nog++;
							cg->fn = fn;
							if ((cg->ninput = nofanin) == 0) cg->inlis = NULL;
							else { cg->inlis = (GATEPTR *)xmalloc(cg->ninput*(sizeof(GATEPTR)));
							}
							for (i = 0; i<nofanin; i++) cg->inlis[i] = pfanin[i];
							cg->noutput = 0;
							cg->outlis = (GATEPTR *)NULL;
							
							nofanin = 0;
							cg = (GATEPTR) NULL;
							break; 
					}		
			}
    }
    
    
    
    net_size = int_nog + int_nopo;
    //printf(" net = %d\n",net_size);
    
    net = (GATEPTR *)xmalloc(net_size*(sizeof(GATEPTR)));
    primaryin = (int *)xmalloc(int_nopi*(sizeof(int)));
    primaryout = (int *)xmalloc(int_nopo*(sizeof(int)));
    
    nog=nopi=nopo=0;
    
    for (cg = begnet; cg != NULL; cg = cg->next) {
		if (cg->index < 0) {
			fprintf(stderr,"Error: floating net %s\n",cg->symbol->symbol);
			fprintf(stderr, "Workaround. You have to take one of the two actions:\n");
			fprintf(stderr, "   1. Remove all the floating input and associated gates, or\n");
			fprintf(stderr, "   2. Make each floating input a primary output.\n");
			return(-1);
		}
		
		net[cg->index] = cg;
		nog++;

    }
   
   
	for (i = nog; i<net_size; i++) net[i] = (GATEPTR)NULL;

    if (nog != int_nog) {
		fprintf(stderr,"Error in read_circuit\n");
		return(-1);
    }
    

	for (i = 0; i<nog; i++) {
		cg = net[i];

		for (j = 0; j<cg->ninput; j++) cg->inlis[j]->noutput++;

		if (cg->fn == PI) primaryin[nopi++] = i; 
    }
    
    
    for (i = 0; i<int_nopo; i++) primaryout[nopo++] = po_gates[i]->index;
    
    
    for (i = 0; i<nog; i++) {
		cg = net[i];
		if (cg->noutput>0) {
		    cg->outlis = (GATEPTR *)xmalloc(cg->noutput*(sizeof(GATEPTR)));	 
    	    //maxfout = MAX(maxfout,cg->noutput);
    	    //cg->noutput= 0;
        }
    }


    for (i = 0; i<nog; i++) net[i]->noutput = 0;

    
	for (i = 0; i<nog; i++) {
		cg = net[i];

		for (j = 0; j<cg->ninput; j++) {
			cg->inlis[j]->outlis[(cg->inlis[j]->noutput)++] = cg;
			//pg = cg->inlis[j];
			//pg->outlis[pg->noutput++] = cg;
		}
	}
		
	
	for (i = 0; i<nog; i++) {
		cg = net[i];

		//<-----------------------------------------
		cg->offset = 0;
		cg->offset = find_offset(cg);
		//printf(" i have offset %d\n",cg->offset);
		if (cg->noutput > 0) continue;
		
		for (j = 0; j<int_nopo; j++)
			if (cg == po_gates[j]) break;

		if (j == int_nopo) {
			fprintf(stderr, "Error: floating output '%s' detected!\n", cg->symbol->symbol); 
			nerrs++;
		}
	}
	 
   
	if (nerrs > 0) {
		fprintf(stderr, "Workaround. You have to take one of the two actions:\n");
		fprintf(stderr, "   1. Remove all the floating output and associated gates, or\n");
		fprintf(stderr, "   2. Make each floating output a primary output.\n");
		return(-1);
	}

	if (int_nog == nog) return(nog);
	else return(-1);
}