Пример #1
0
double_hash_t* init_double_hash(int hs_two_pow)
{
	double_hash_t* hash = NULL;
	int hash_size;

	if(hs_two_pow>MAX_HSIZE_TWO_POW || hs_two_pow<0)
		hash_size = MAX_HASH_SIZE;
	else
		hash_size = 1<<hs_two_pow;	


	/* space for the double_hash is allocated in share memory */
	hash = (double_hash_t*)shm_malloc(sizeof(double_hash_t));
	if(hash == NULL)
		return NULL;

	if( (hash->dhash = init_hash(hash_size)) == NULL )
	{
		shm_free(hash);
		return NULL;
	}
	
	if( (hash->chash = init_hash(hash_size)) == NULL )
	{
		free_hash(hash->dhash, hash_size, ERASE_CELL);
		shm_free(hash);
		return NULL;
	}

	hash->hash_size = hash_size;

	return hash;
}
Пример #2
0
struct vxlan_instance * 
create_vxlan_instance (u_int8_t * vni)
{
	char cbuf[16];
	u_int32_t vni32;
	struct vxlan_instance * vins;

	/* create socket and fdb */
	vins = (struct vxlan_instance *) malloc (sizeof (struct vxlan_instance));
	memset (vins, 0, sizeof (struct vxlan_instance));
	memcpy (vins->vni, vni, VXLAN_VNISIZE);

	snprintf (cbuf, 16, "0x%02x%02x%02x", 
		  vins->vni[0],vins->vni[1], vins->vni[2]);
	vni32 = strtol (cbuf, NULL, 0);
	snprintf (vins->vxlan_tap_name, IFNAMSIZ, "%s%X", 
		  VXLAN_TUNNAME, vni32);

	vins->fdb = init_fdb ();
	vins->tap_sock = tap_alloc (vins->vxlan_tap_name);
	

	/* create out bound MAC/ARP/ND/RA access list */
	init_hash (&vins->acl_mac, ETH_ALEN);
	init_hash (&vins->acl_ip4, sizeof (struct in_addr));
	init_hash (&vins->acl_ip6, sizeof (struct in6_addr));

	return vins;
}
Пример #3
0
int main ()
{
    int n, num0[6];
    while(~scanf("%d", &n))
    {
        cur = 0;
        init_hash();
        int temp, twins = 0;
        for(int i = 0; i < n;  i ++)
        {
            for(int j = 0; j < 6; j ++)
            {
                scanf("%d", &temp);
                num0[j] = temp;
            }
            if(twins)
                continue;
            twins = search_hash(num0);
        }
        if(twins)
            printf("Twin snowflakes found.\n");
        else
            printf("No two snowflakes are alike.\n");
    }
    return 0;
}
Пример #4
0
static void
add_keyword (const char *name, hash_table *keywords)
{
  if (name == NULL)
    default_keywords = false;
  else
    {
      const char *end;
      int argnum1;
      int argnum2;
      const char *colon;

      if (keywords->table == NULL)
	init_hash (keywords, 100);

      split_keywordspec (name, &end, &argnum1, &argnum2);

      /* The characters between name and end should form a valid C identifier.
	 A colon means an invalid parse in split_keywordspec().  */
      colon = strchr (name, ':');
      if (colon == NULL || colon >= end)
	{
	  if (argnum1 == 0)
	    argnum1 = 1;
	  insert_entry (keywords, name, end - name,
			(void *) (long) (argnum1 + (argnum2 << 10)));
	}
    }
}
Пример #5
0
void tpie_init(int subsystems) {
	if (subsystems & MEMORY_MANAGER)	
	 	init_memory_manager();

	if (subsystems & DEFAULT_LOGGING)
		init_default_log();

	if (subsystems & PRIMEDB)
		init_prime();

	if (subsystems & CAPTURE_FRACTIONS) {
		init_fraction_db(true);
		init_execution_time_db();
	} else if (subsystems & PROGRESS) {
		init_fraction_db(false);
		init_execution_time_db();
	}

	if (subsystems & JOB_MANAGER)
		init_job();

	if (subsystems & STREAMS) {
		init_stream_buffer_pool();
		init_compressor();
	}

	if (subsystems & HASH)
		init_hash();
}
Пример #6
0
int main() {

	struct test *dummy;
	size_t size = 13;
	HASHTABLE init = init_hash(dummy, size, (void *)casting);


	strcpy(point_one.name, "entry\0");
	strcpy(point_sec.name, "hello\0");
	strcpy(point_thi.name, "12345\0");

	point_one.x = 5;
	point_one.y = 20;
	
	point_sec.x = 17;
	point_sec.y = 30;

	point_thi.x = 11;
	point_thi.y = 2350;

	insertHash(init, point_one.name, &point_one);				
	insertHash(init, point_sec.name, &point_sec);				
	insertHash(init, point_thi.name, &point_thi);				

	dummy = getHash(init, point_sec.name);
	printf("Output Name: %s, x: %d, y: %d\n", dummy->name, dummy->x, dummy->y);


	return 1;
}
Пример #7
0
int main(/* int argc, char **argv */)
{
    ngx_pool_t *pool = NULL;
    ngx_array_t *array = NULL;
    ngx_hash_t *hash;


    printf("--------------------------------\n");
    printf("create a new pool:\n");
    printf("--------------------------------\n");


    pool = ngx_create_pool(1024, &ngx_log);

    dump_pool(pool);

    printf("--------------------------------\n");
    printf("create and add urls to it:\n");
    printf("--------------------------------\n");
    array = add_urls_to_array(pool);  //in fact, here should validate array
    dump_hash_array(array);

    printf("--------------------------------\n");
    printf("the pool:\n");
    printf("--------------------------------\n");
    dump_pool(pool);

    hash = init_hash(pool, array);
    if (hash == NULL)
    {
        printf("Failed to initialize hash!\n");
        return -1;
    }

    printf("--------------------------------\n");
    printf("the hash:\n");
    printf("--------------------------------\n");
    dump_hash(hash, array);
    printf("\n");

    printf("--------------------------------\n");
    printf("the pool:\n");
    printf("--------------------------------\n");
    dump_pool(pool);

    //find test
    printf("--------------------------------\n");
    printf("find test:\n");
    printf("--------------------------------\n");
    find_test(hash, urls, Max_Num);
    printf("\n");

    find_test(hash, urls2, Max_Num2);

    //release
    ngx_array_destroy(array);
    ngx_destroy_pool(pool);

    return 0;
}
Пример #8
0
static void dissector_init_lay3(int (*fnt)(void *ptr))
{
	init_hash(&eth_lay3);
	INSERT_HASH_PROTOS(icmp_ops, eth_lay3);
	INSERT_HASH_PROTOS(udp_ops, eth_lay3);
	INSERT_HASH_PROTOS(tcp_ops, eth_lay3);
	for_each_hash(&eth_lay3, fnt);
}
Пример #9
0
void begin(void)
{
    init_hash();
    init_data();
    init_board();
    setbuf(stdout, NULL);
    setbuf(stdin, NULL);
}
Пример #10
0
int main(int argc, const char* argv[])
{
    struct simple_hash ht;
    init_hash(&ht,128);
    for (;;)
    {
        char buf[256];
        if (fgets(buf, 256, stdin) == NULL)
            break;
        char *command = strtok(buf, whitespace);
        unsigned int key;
        unsigned int value;
        if (strcmp(command, "insert") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            sscanf(strtok(NULL, whitespace), "%u", &value);
            hash_insert(&ht,key,value);
        }
        else if (strcmp(command, "lookup") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            size_t value;
            int result;
            result=hash_lookup(&ht,key, &value);
            if (result==0)
                printf("%u\n", (unsigned int) value);
            else
                printf("None\n");
        }
        else if (strcmp(command, "increment") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            hash_cell_insert(&ht,key)->value++;
        }
        else if (strcmp(command, "delete") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            hash_delete(&ht,key);
        }
        else if (strcmp(command, "clear") == 0)
        {
            clear_hash(&ht);
        }
        else if (strcmp(command, "compact") == 0)
        {
            compact_hash(&ht);
        }
        fflush(stdout);
    }

    // Dump entire table
    printf("{\n");
    if(ht.m_zeroUsed) printf("    %u: %u,\n", ht.m_zeroCell.key, ht.m_zeroCell.value);
    for(size_t i=0;i<ht.m_arraySize;i++) if(ht.m_cells[i].key) printf("    %u: %u,\n", ht.m_cells[i].key, ht.m_cells[i].value);
    printf("}\n");
    end_hash(&ht);
    return 0;
}
Пример #11
0
static void type_add(char *name, char *value) {
  int h;
  stabtype *s;
  char      sc =0;
  char     *v;
  char     *vr;
  char     *split;

  if (!stab_type_init) {
    init_hash();
    stab_type_init = 1;
  }

  /* Split the "value" up into a type name and a value */
  
  split = strchr(value,'=');
  if (value[0] != '(') split = 0;
  if (split) {
    sc = *split;
    v = value;
    *split = 0;
    vr = split+1;
  } else {
    v = value;
    sc = 0;
    vr = 0;
  }

  h = thash(name);
  s = lnames[h];
  while (s) {
    if (strcmp(s->name,name) == 0) {
      if (strcmp(s->value,v)) {
	s->value = wad_string_lookup(v);
      }
      goto add_more;
    }
    s = s->next;
  }
  s = deadnames[h];
  if (!s) {
    s = (stabtype *) wad_malloc(sizeof(stabtype));
  } else {
    deadnames[h] = s->next; 
  }
  s->name = wad_string_lookup(name);
  s->value = wad_string_lookup(v);
  s->next = lnames[h];
  s->visit = 0;
  lnames[h] = s;

  /* Now take a look at the value.   If it is contains other types, we might be able to define more stuff */
 add_more:
  if (vr) {
    /* There is a mapping to another type */
    type_add(v,vr);
  }
}
Пример #12
0
static void dissector_init_lay2(int (*fnt)(void *ptr))
{
	init_hash(&eth_lay2);
	INSERT_HASH_PROTOS(arp_ops, eth_lay2);
	INSERT_HASH_PROTOS(vlan_ops, eth_lay2);
	INSERT_HASH_PROTOS(ipv4_ops, eth_lay2);
	INSERT_HASH_PROTOS(ipv6_ops, eth_lay2);
	for_each_hash(&eth_lay2, fnt);
}
Пример #13
0
static void init_sockaddr_mapper(void)
{
	rwlock_init(&sockaddr_map_lock);
	rwlock_wr_lock(&sockaddr_map_lock);

	memset(&sockaddr_mapper, 0, sizeof(sockaddr_mapper));
	init_hash(&sockaddr_mapper);

	rwlock_unlock(&sockaddr_map_lock);
}
Пример #14
0
int main(int argc, char const *argv[])
{
	check_permission();

	setup_signal_chld();

	parseconf_load_file("ftpserver.conf");
	print_conf();

	init_hash();

	//创建一个监听fd
	int listenfd = tcp_server(tunable_listen_address, tunable_listen_port);

	pid_t pid;
	session_t sess;
	session_init(&sess);
	p_sess = &sess;	//配置全局变量
	
	while(1)
	{
		struct sockaddr_in addr;
		int peerfd = accept_timeout(listenfd, &addr, tunable_accept_timeout);
		if(peerfd  == -1 && errno == ETIMEDOUT)
			continue;
		else if(peerfd == -1)
			ERR_EXIT("accept_timeout");

		//获取ip地址,并在hash中添加一条记录
		uint32_t ip = addr.sin_addr.s_addr;
		sess.ip = ip;
		add_clients_to_hash(&sess, ip);
		
		if((pid = fork()) == -1)
			ERR_EXIT("fork");
		else if(pid == 0)
		{
			close(listenfd);
			
			sess.peerfd = peerfd;
			limit_num_clients(&sess);
			session_begin(&sess);
			exit(EXIT_SUCCESS);
		}
		else
		{
			//pid_to_ip
			add_pid_ip_to_hash(pid, ip);
			close(peerfd);
		}
	}

	return 0;
}
Пример #15
0
int main()
{
	int i;
	scanf("%d %d", &n, &m);
	init_hash();
	cnt = 0;
	for(i = 0;i < n; i++) scanf("%d %d", k + i, p + i);
	mid = n>>1;
	left(0, 0); right(0, mid);
	printf("%d\n", cnt);
	return 0;
}
Пример #16
0
static void dissector_init_layer_2(int type)
{
	init_hash(&eth_lay2);
	INSERT_HASH_PROTOS(arp_ops, eth_lay2);
	INSERT_HASH_PROTOS(lldp_ops, eth_lay2);
	INSERT_HASH_PROTOS(vlan_ops, eth_lay2);
	INSERT_HASH_PROTOS(ipv4_ops, eth_lay2);
	INSERT_HASH_PROTOS(ipv6_ops, eth_lay2);
	INSERT_HASH_PROTOS(QinQ_ops, eth_lay2);
	INSERT_HASH_PROTOS(mpls_uc_ops, eth_lay2);
	for_each_hash_int(&eth_lay2, dissector_set_print_type, type);
}
Пример #17
0
void init_cpusched(unsigned int cpus)
{
	rwlock_init(&map_lock);
	rwlock_wr_lock(&map_lock);

	cpu_len = cpus;
	cpu_assigned = xzmalloc(cpus * sizeof(*cpu_assigned));

	memset(&mapper, 0, sizeof(mapper));
	init_hash(&mapper);

	rwlock_unlock(&map_lock);
}
Пример #18
0
/*
 *函数名称:public_init
 *函数功能:public module init
 *输入参数:none
 *输出参数:none
 *返回值:  on success, return 0(YT_SUCCESS). on error, -1(YT_FAILED) is returned.
*/
int public_init()
{
    INFO_PRINT("\n----->Public模块初始化..........\n");

    //计数器
    global_shared.retain_count ++;

    mempool_init();
    init_hash();
    log_init();

    return YT_SUCCESSFUL;
}
Пример #19
0
static bool
init_multicast_group_table() {
  assert( multicast_groups == NULL );

  multicast_groups = malloc( sizeof( struct multicast_group_table ) );
  assert( multicast_groups != NULL );
  memset( multicast_groups, 0, sizeof( struct multicast_group_table ) );

  init_hash( &multicast_groups->groups, sizeof( struct in_addr ) );
  pthread_mutexattr_t attr;
  pthread_mutexattr_init( &attr );
  pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE_NP );
  pthread_mutex_init( &multicast_groups->mutex, &attr );

  return true;
}
Пример #20
0
void
global_setup( int use_random, int hash_bits ) {
  FILE *log_file;
  time_t timer;

  /* Clear the log file. No error handling done. */

#if defined(ANDROID)
  sprintf(log_file_path, "%s/%s", android_files_dir, LOG_FILE_NAME);
#elif defined(__linux__)
  strcpy( log_file_path, LOG_FILE_NAME );
#else
  char directory_buffer[MAX_PATH_LENGTH];
  getcwd( directory_buffer, MAX_PATH_LENGTH );
  if ( directory_buffer[strlen( directory_buffer ) - 1] == '\\' )
    sprintf( log_file_path, "%s%s", directory_buffer, LOG_FILE_NAME );
  else
    sprintf( log_file_path, "%s\\%s", directory_buffer, LOG_FILE_NAME );
#endif

  if ( use_log_file ) {
    log_file = fopen( log_file_path, "w" );
    if ( log_file != NULL ) {
      time( &timer );
      fprintf( log_file, "%s %s\n", LOG_TEXT, ctime( &timer ) );
      fprintf( log_file, "%s %s %s\n", ENGINE_TEXT, __DATE__, __TIME__ );
      fclose( log_file );
    }
  }

  if ( use_random ) {
    time( &timer );
    my_srandom( timer );
  }
  else
    my_srandom( 1 );

  init_hash( hash_bits );
  init_bitboard();
  init_moves();
  init_patterns();
  init_coeffs();
  init_timer();
  init_probcut();
  init_stable();
  setup_search();
}
Пример #21
0
struct dfont *
dfont_create(int width, int height) {
	int max_line = height / TINY_FONT;
	int max_char = max_line * width / TINY_FONT;
	size_t ssize = max_char * sizeof(struct hash_rect);
	size_t lsize = max_line * sizeof(struct font_line);
	struct dfont *df = (struct dfont *)malloc(sizeof(struct dfont) + ssize + lsize);
	df->width = width;
	df->height = height;
	df->max_line = 0;
	df->version = 0;
	INIT_LIST_HEAD(&df->time);
	df->freelist = (struct hash_rect *)(df+1);
	df->line = (struct font_line *)((intptr_t)df->freelist + ssize);
	init_hash(df, max_char);

	return df;
}
Пример #22
0
static void dissector_init_layer_3(int type)
{
	init_hash(&eth_lay3);
	INSERT_HASH_PROTOS(icmpv4_ops, eth_lay3);
	INSERT_HASH_PROTOS(icmpv6_ops, eth_lay3);
	INSERT_HASH_PROTOS(igmp_ops, eth_lay3);
	INSERT_HASH_PROTOS(ip_auth_ops, eth_lay3);
	INSERT_HASH_PROTOS(ip_esp_ops, eth_lay3);
	INSERT_HASH_PROTOS(ipv6_dest_opts_ops, eth_lay3);
	INSERT_HASH_PROTOS(ipv6_fragm_ops, eth_lay3);
	INSERT_HASH_PROTOS(ipv6_hop_by_hop_ops, eth_lay3);
	INSERT_HASH_PROTOS(ipv6_in_ipv4_ops, eth_lay3);
	INSERT_HASH_PROTOS(ipv6_mobility_ops, eth_lay3);
	INSERT_HASH_PROTOS(ipv6_no_next_header_ops, eth_lay3);
	INSERT_HASH_PROTOS(ipv6_routing_ops, eth_lay3);
	INSERT_HASH_PROTOS(tcp_ops, eth_lay3);
	INSERT_HASH_PROTOS(udp_ops, eth_lay3);
	for_each_hash_int(&eth_lay3, dissector_set_print_type, type);
}
Пример #23
0
int
common_init( void )
{
	if( init_hash() )
		return 1;

	if( !(g_sesstab=kmalloc_cont_mol(sizeof(*g_sesstab))) ) {
		cleanup_hash();
		return 1;
	}
	
	memset( g_sesstab, 0, sizeof(*g_sesstab) );
	init_MUTEX_mol( &g_sesstab->lock );
	
	if( arch_common_init() ) {
		free_MUTEX_mol( &g_sesstab->lock );
		kfree_cont_mol( g_sesstab );
		cleanup_hash();
		return 1;
	}
	return 0;
}
Пример #24
0
void csiebox_client_init(
    csiebox_client** client, int argc, char** argv) {
    csiebox_client* tmp = (csiebox_client*)malloc(sizeof(csiebox_client));
    if (!tmp) {
        fprintf(stderr, "client malloc fail\n");
        return;
    }
    memset(tmp, 0, sizeof(csiebox_client));
    if (!parse_arg(tmp, argc, argv)) {
        fprintf(stderr, "Usage: %s [config file]\n", argv[0]);
        free(tmp);
        return;
    }
    int fd = client_start(tmp->arg.name, tmp->arg.server);
    if (fd < 0) {
        fprintf(stderr, "connect fail\n");
        free(tmp);
        return;
    }
    tmp->conn_fd = fd;
    fd = inotify_init();
    if (fd < 0) {
        fprintf(stderr, "inotify fail\n");
        close(tmp->conn_fd);
        free(tmp);
        return;
    }
    tmp->inotify_fd = fd;
    if (!init_hash(&(tmp->inotify_hash), 100)) {
        destroy_hash(&(tmp->inotify_hash));
        fprintf(stderr, "hash fail\n");
        close(tmp->conn_fd);
        close(tmp->inotify_fd);
        free(tmp);
    }
    memset(tmp->root, 0, PATH_MAX);
    realpath(tmp->arg.path, tmp->root);
    *client = tmp;
}
Пример #25
0
pdt_hash_t* pdt_init_hash(int hs_two_pow)
{
	pdt_hash_t* hash = NULL;
	int hash_size;

	if(hs_two_pow>MAX_HSIZE_TWO_POW || hs_two_pow<0)
		hash_size = MAX_HASH_SIZE;
	else
		hash_size = 1<<hs_two_pow;	


	/* space for the double_hash is allocated in share memory */
	hash = (pdt_hash_t*)shm_malloc(sizeof(pdt_hash_t));
	if(hash == NULL)
	{
		LOG(L_ERR, "PDT:pdt_init_hash: no more shm\n");
		return NULL;
	}

	if(lock_init(&hash->diff_lock) == 0)
	{
		shm_free(hash);
		LOG(L_ERR, "PDT:pdt_init_hash: cannot init the diff lock\n");
		return NULL;
	}
	
	if( (hash->dhash = init_hash(hash_size)) == NULL )
	{
		lock_destroy(&hash->diff_lock);
		shm_free(hash);
		LOG(L_ERR, "PDT:pdt_init_hash: no more shm!\n");
		return NULL;
	}
	
	hash->hash_size = hash_size;

	return hash;
}
Пример #26
0
/* ARGSUSED */
DB *
__hash_open(const char *file, int flags, int mode,
    const HASHINFO *info,	/* Special directives for create */
    int dflags)
{
	HTAB *hashp;
	struct stat statbuf;
	DB *dbp;
	int bpages, hdrsize, new_table, nsegs, save_errno;

	if ((flags & O_ACCMODE) == O_WRONLY) {
		errno = EINVAL;
		return (NULL);
	}

	if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB))))
		return (NULL);
	hashp->fp = -1;

	/*
	 * Even if user wants write only, we need to be able to read
	 * the actual file, so we need to open it read/write. But, the
	 * field in the hashp structure needs to be accurate so that
	 * we can check accesses.
	 */
	hashp->flags = flags;

	if (file) {
		if ((hashp->fp = _open(file, flags | O_CLOEXEC, mode)) == -1)
			RETURN_ERROR(errno, error0);
		new_table = _fstat(hashp->fp, &statbuf) == 0 &&
		    statbuf.st_size == 0 && (flags & O_ACCMODE) != O_RDONLY;
	} else
		new_table = 1;

	if (new_table) {
		if (!(hashp = init_hash(hashp, file, info)))
			RETURN_ERROR(errno, error1);
	} else {
		/* Table already exists */
		if (info && info->hash)
			hashp->hash = info->hash;
		else
			hashp->hash = __default_hash;

		hdrsize = _read(hashp->fp, &hashp->hdr, sizeof(HASHHDR));
#if BYTE_ORDER == LITTLE_ENDIAN
		swap_header(hashp);
#endif
		if (hdrsize == -1)
			RETURN_ERROR(errno, error1);
		if (hdrsize != sizeof(HASHHDR))
			RETURN_ERROR(EFTYPE, error1);
		/* Verify file type, versions and hash function */
		if (hashp->MAGIC != HASHMAGIC)
			RETURN_ERROR(EFTYPE, error1);
#define	OLDHASHVERSION	1
		if (hashp->VERSION != HASHVERSION &&
		    hashp->VERSION != OLDHASHVERSION)
			RETURN_ERROR(EFTYPE, error1);
		if ((int32_t)hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY)
			RETURN_ERROR(EFTYPE, error1);
		/*
		 * Figure out how many segments we need.  Max_Bucket is the
		 * maximum bucket number, so the number of buckets is
		 * max_bucket + 1.
		 */
		nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) /
			 hashp->SGSIZE;
		if (alloc_segs(hashp, nsegs))
			/*
			 * If alloc_segs fails, table will have been destroyed
			 * and errno will have been set.
			 */
			return (NULL);
		/* Read in bitmaps */
		bpages = (hashp->SPARES[hashp->OVFL_POINT] +
		    (hashp->BSIZE << BYTE_SHIFT) - 1) >>
		    (hashp->BSHIFT + BYTE_SHIFT);

		hashp->nmaps = bpages;
		(void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *));
	}

	/* Initialize Buffer Manager */
	if (info && info->cachesize)
		__buf_init(hashp, info->cachesize);
	else
		__buf_init(hashp, DEF_BUFSIZE);

	hashp->new_file = new_table;
	hashp->save_file = file && (hashp->flags & O_RDWR);
	hashp->cbucket = -1;
	if (!(dbp = (DB *)malloc(sizeof(DB)))) {
		save_errno = errno;
		hdestroy(hashp);
		errno = save_errno;
		return (NULL);
	}
	dbp->internal = hashp;
	dbp->close = hash_close;
	dbp->del = hash_delete;
	dbp->fd = hash_fd;
	dbp->get = hash_get;
	dbp->put = hash_put;
	dbp->seq = hash_seq;
	dbp->sync = hash_sync;
	dbp->type = DB_HASH;

#ifdef DEBUG
	(void)fprintf(stderr,
"%s\n%s%p\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n",
	    "init_htab:",
	    "TABLE POINTER   ", hashp,
	    "BUCKET SIZE     ", hashp->BSIZE,
	    "BUCKET SHIFT    ", hashp->BSHIFT,
	    "DIRECTORY SIZE  ", hashp->DSIZE,
	    "SEGMENT SIZE    ", hashp->SGSIZE,
	    "SEGMENT SHIFT   ", hashp->SSHIFT,
	    "FILL FACTOR     ", hashp->FFACTOR,
	    "MAX BUCKET      ", hashp->MAX_BUCKET,
	    "OVFL POINT	     ", hashp->OVFL_POINT,
	    "LAST FREED      ", hashp->LAST_FREED,
	    "HIGH MASK       ", hashp->HIGH_MASK,
	    "LOW  MASK       ", hashp->LOW_MASK,
	    "NSEGS           ", hashp->nsegs,
	    "NKEYS           ", hashp->NKEYS);
#endif
#ifdef HASH_STATISTICS
	hash_overflows = hash_accesses = hash_collisions = hash_expansions = 0;
#endif
	return (dbp);

error1:
	if (hashp != NULL)
		(void)_close(hashp->fp);

error0:
	free(hashp);
	errno = save_errno;
	return (NULL);
}
Пример #27
0
int
wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
  Stab *s;
  int   ns;
  int   i;
  int   found = 0;

  char  *file, *lastfile = 0;

  char   srcfile[MAX_PATH];
  char   objfile[MAX_PATH];

  /* It appears to be necessary to clear the types table on each new stabs section */

  init_hash();

  if (!f->sym_name) return 0;

  s = (Stab *) sp;            /* Stabs data      */
  ns = size/sizeof(Stab);     /* number of stabs */

  srcfile[0] = 0;
  objfile[0] = 0;

  for (i = 0; i < ns; i++, s++) {
    if (wad_debug_mode & DEBUG_STABS) {
      /*      wad_printf("   %10d %10x %10d %10d %10d: '%s'\n", s->n_strx, s->n_type, s->n_other, s->n_desc, s->n_value, 
	      stabstr+s->n_strx); */
      
	     }
    if (s->n_type == N_LSYM) {
      stab_symbol(s,stabstr);
      continue;
    }
    if ((s->n_type == N_UNDF)) { /* && (s->n_desc >= 0)) { */
      /* New stabs section.  We need to be a little careful here. Do a recursive 
	 search of the subsection. */

      if (wad_search_stab(s+1,s->n_desc*sizeof(Stab), stabstr, f)) {
	return 1;
      }

      /* On solaris, each stabs section seems to increment the stab string pointer.  On Linux,
         the linker seems to do a certain amount of optimization that results in a single
         string table. */

#ifdef WAD_SOLARIS
      stabstr += s->n_value;     /* Update the string table location*/
#endif
      i += s->n_desc;
      s += s->n_desc;
      objfile[0] = 0;
      srcfile[0] = 0;
      continue;
    } else if (s->n_type == N_SO) {
      /* Source file specification */
      /* Look for directory */
      file = stabstr+s->n_strx;
      if (strlen(file) && (file[strlen(file)-1] == '/')) {
	wad_strcpy(srcfile,file);
      } else {
	wad_strcat(srcfile,file);
      }
      objfile[0] = 0;
      /* If we have a file match, we might be looking for a local symbol.   If so,
         we'll go ahead and set the srcfile field of the frame */

      /* We're going to check for a file match. Maybe we're looking for a local symbol */
      if (f->sym_file && strcmp(f->sym_file,file) == 0) {
	found = 1;
      }
      lastfile = file;
    } else if (s->n_type == N_OBJ) {
      /* Object file specifier */
      if (objfile[0]) {
	wad_strcat(objfile,"/");
      }
      wad_strcat(objfile,stabstr+s->n_strx);
    } else if (s->n_type == N_FUN) {
      if (match_stab_symbol(f->sym_name, stabstr+s->n_strx, f->sym_nlen)) {
	  if (!f->sym_file || (strcmp(f->sym_file,lastfile) == 0)) {
	    int n;
	    /* Go find debugging information for the function */
	    n = scan_function(s+1, stabstr, ns -i - 1, f);
	    f->loc_srcfile = wad_string_lookup(srcfile);
	    f->loc_objfile = wad_string_lookup(objfile);
	    return 1;
	  }
      }
    }
  }
  /* If found, but no other debugging information was filled in, go ahead and copy the
     source and objfile information */
  
  if ((found) && (!f->debug_check)) {
    f->loc_srcfile = wad_string_lookup(srcfile);
    f->loc_objfile = wad_string_lookup(objfile);
  }
  return found;
}
int main(int             argc, char           *argv[])
{

char onewdbfr[512],onewdaft[512];
char onetagbfr[512],twotagbfr[512],onetagaft[512],twotagaft[512];
char *freshcharvar;
Darray errorlist,temperrorkey,temperrorval;
Registry errorlistcount,SEENTAGGING,WORDS;

FILE *correct_file, *guess_file, *error_list,*correct_out;
char line[5000];  /* input line buffer */
char **split_ptr,**split_ptr2;

char wdpair[1024];
char *tempstr,*tempstr2;
float CONTINUE = 10000.0;
int count2,numwrong,lengthcount;
unsigned int count;
char globalprint[500];
char systemcall[500];
char forpasting[500];
char forpasting2[500];
float globalbest = 0.0;
char flag[20];
Registry currentwd,currentwd2;
Registry always,always2;
Registry wdnexttag,wdnexttag2,wdprevtag,wdprevtag2;
Registry rbigram,lbigram,rbigram2,lbigram2;
Registry next1tag,next1tag2,prev1tag,prev1tag2;
Registry next1or2tag,next1or2tag2,prev1or2tag,prev1or2tag2;
Registry next1or2or3tag,next1or2or3tag2,prev1or2or3tag,prev1or2or3tag2;
Registry next1wd,next1wd2,prev1wd,prev1wd2;
Registry next1or2wd,next1or2wd2,prev1or2wd,prev1or2wd2;
Registry nextbigram,nextbigram2,prevbigram,prevbigram2;
Registry surroundtag,surroundtag2;
Registry next2tag,next2tag2,prev2tag,prev2tag2;
Registry next2wd,next2wd2,prev2wd,prev2wd2;
char globaldif[20];
int printscore;
FILE *allowedmovefile;
char **perl_split_ptr,**perl_split_ptr2,*atempstr,atempstr2[1024];
char space[500];

SEENTAGGING = Registry_create(Registry_strcmp,Registry_strhash);
Registry_size_hint(SEENTAGGING,GUESSNUMWORDS);
WORDS = Registry_create(Registry_strcmp,Registry_strhash);
Registry_size_hint(WORDS,GUESSNUMWORDS);

allowedmovefile = fopen(argv[4], "r");
	  while(fgets(line,sizeof(line),allowedmovefile) != NULL) {
	    if (not_just_blank(line)) {
	      line[strlen(line) - 1] = '\0';

	      perl_split_ptr = perl_split(line);
	      perl_split_ptr2 = perl_split_ptr;
	      ++perl_split_ptr;
	      atempstr= mystrdup(*perl_split_ptr2);
	      Registry_add(WORDS,atempstr,(char *)1);
	      while(*perl_split_ptr != NULL) {
		sprintf(space,"%s %s",*perl_split_ptr2,
			*perl_split_ptr);
		atempstr=mystrdup(space);

		Registry_add(SEENTAGGING,atempstr,(char *)1);
		++perl_split_ptr; }
	      free(*perl_split_ptr2);
	      free(perl_split_ptr2);
	    }

	  }


system("/bin/rm AANEWRESTRJUNKKK");
correct_tag_corpus = Darray_create();
Darray_hint(correct_tag_corpus,100,400000);
word_corpus = Darray_create();
Darray_hint(word_corpus,100,400000);


correct_file = fopen(argv[1],"r");


while(fgets(line,sizeof(line),correct_file) != NULL) {
  Darray_addh(correct_tag_corpus,staart);
  Darray_addh(correct_tag_corpus,staart);
  Darray_addh(word_corpus,staart);
  Darray_addh(word_corpus,staart);
  line[strlen(line)-1] = '\0';
  split_ptr = perl_split_independent(line);
  while (*split_ptr != NULL) {
    Darray_addh(word_corpus,*split_ptr);
    while ((*(++*split_ptr)) != '/') {
    }
    **split_ptr = '\0';
    Darray_addh(correct_tag_corpus,++*split_ptr);
    ++split_ptr;
  }
}
fclose(correct_file);


printf("READ IN CORRECT FILE\n");




while(CONTINUE > THRESHOLD) {

  guess_tag_corpus = Darray_create();
  Darray_hint(guess_tag_corpus,100,400000);
  guess_file  = fopen(argv[2],"r");
  while(fgets(line,sizeof(line),guess_file) != NULL) {
    
    Darray_addh(guess_tag_corpus,staart);
    Darray_addh(guess_tag_corpus,staart);
    line[strlen(line)-1] = '\0';
    split_ptr = perl_split_independent(line); 
    split_ptr2 = split_ptr;
    while (*split_ptr != NULL) {
      tempstr = strtok(*split_ptr,"/");
      tempstr = strtok(NULL,"/");
      tempstr2  = mystrdup(tempstr);
      Darray_addh(guess_tag_corpus,tempstr2);
      free(*split_ptr);
      ++split_ptr;
    }
    free(split_ptr2);
  }
  fclose(guess_file);

printf("READ IN BAD FILE\n");

  errorlist = Darray_create();
  Darray_hint(errorlist,10,500);
  temperrorkey = Darray_create();
  temperrorval = Darray_create();
  Darray_hint(temperrorkey,10,500);
  Darray_hint(temperrorval,10,500);

  init_hash(&errorlistcount,500);


  printscore=0;
  for(count=0;count<Darray_len(guess_tag_corpus);++count) {
    if
      (! is_tagged_with((char *)Darray_get(correct_tag_corpus,count),(char *)Darray_get(guess_tag_corpus,count))) { 
	++printscore; 
	freshcharvar =
	  mystrdup(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count)));
	sprintf(forpasting,"%s %s",freshcharvar,
		                       (char *)Darray_get(correct_tag_corpus,count));
	increment_array_create(&errorlistcount,forpasting);
      } 
  }

  error_list = fopen("AANEWRESTRJUNKKK","a");
  Registry_fetch_contents(errorlistcount,temperrorkey,temperrorval);  
  for (count=0;count<Darray_len(temperrorkey);++count) {
    if (*(int *)(char *)Darray_get(temperrorval,count) > THRESHOLD)
      /*Darray_addh(errorlist,tempstr);*/
      fprintf(error_list,"%d %s\n",*(int *)(char *)Darray_get(temperrorval,count),
	                    (char *)Darray_get(temperrorkey,count));
    free((char *)Darray_get(temperrorval,count));
    free((char *)Darray_get(temperrorkey,count));
  }
  fclose(error_list);
  Darray_destroy(temperrorval);
  Darray_destroy(temperrorkey);
  Registry_destroy(errorlistcount);

  printf("NUM ERRORS: %d\n",printscore);
/* shoud sort error list !!!!!!!*/
  
  system("cat AANEWRESTRJUNKKK | sort -rn > AANEWRESTRJUNKKK2");
  system("mv AANEWRESTRJUNKKK2 AANEWRESTRJUNKKK");
  
  error_list = fopen("AANEWRESTRJUNKKK","r");
  while(fgets(line,sizeof(line),error_list) != NULL) {
    line[strlen(line)-1] = '\0';
    tempstr = mystrdup(line);
    Darray_addh(errorlist,tempstr); 
  }
  fclose(error_list);
  system("/bin/rm AANEWRESTRJUNKKK");

  globalbest= 0;
  strcpy(globalprint,"");
  
  
  for (count=0;count<Darray_len(errorlist);++count) {

    localbest =0;
    strcpy(localbestthing,"");
    /*printf("ERROR LIST GUY: %s\n",(char *)Darray_get(errorlist,count));      */

    split_ptr = perl_split_independent((char *)Darray_get(errorlist,count));
/*printf("ERRORLISTGUY: %s %s %s\n",split_ptr[0],split_ptr[1],split_ptr[2]);*/
    wrong = split_ptr[1];
    right = split_ptr[2];
    numwrong = atoi(split_ptr[0]);
    if (numwrong > THRESHOLD3) {
      
      printf("WRONG,RI: %s %s\n",wrong,right);
      printf("GLOBALBEST, GLOBALPRINT, GLOBALDIF: %f %s %s\n",globalbest,globalprint,globaldif);

      init_hash(&always,NUMTAGS/2);
      init_hash(&always2,NUMTAGS/2);
      init_hash(&rbigram,(NUMWDS*NUMWDS)/4);
      init_hash(&lbigram,(NUMWDS*NUMWDS)/4);
      init_hash(&rbigram2,(NUMWDS*NUMWDS)/4);
      init_hash(&lbigram2,(NUMWDS*NUMWDS)/4);
      init_hash(&wdnexttag,(NUMWDS*NUMTAGS)/4);
      init_hash(&wdnexttag2,(NUMWDS*NUMTAGS)/4);
      init_hash(&wdprevtag,(NUMWDS*NUMTAGS)/4);
      init_hash(&wdprevtag2,(NUMWDS*NUMTAGS)/4);
      init_hash(&next1tag,NUMTAGS/2);
      init_hash(&next1tag2,NUMTAGS/2);
      init_hash(&prev1tag,NUMTAGS/2);
      init_hash(&prev1tag2,NUMTAGS/2);
      init_hash(&next1or2tag,NUMTAGS/2);
      init_hash(&next1or2tag2,NUMTAGS/2);
      init_hash(&prev1or2tag,NUMTAGS/2);
      init_hash(&prev1or2tag2,NUMTAGS/2);
      init_hash(&next1wd,NUMWDS/2);
      init_hash(&next1wd2,NUMWDS/2);
      init_hash(&prev1wd,NUMWDS/2);
      init_hash(&prev1wd2,NUMWDS/2);
      init_hash(&currentwd,NUMWDS/2);
      init_hash(&currentwd2,NUMWDS/2);
      init_hash(&next1or2wd,NUMWDS/2);
      init_hash(&next1or2wd2,NUMWDS/2);
      init_hash(&prev1or2wd,NUMWDS/2);
      init_hash(&prev1or2wd2,NUMWDS/2);
      init_hash(&next1or2or3tag,NUMTAGS/2);
      init_hash(&next1or2or3tag2,NUMTAGS/2);
      init_hash(&prev1or2or3tag,NUMTAGS/2);
      init_hash(&prev1or2or3tag2,NUMTAGS/2);
      init_hash(&nextbigram,NUMTAGS);
      init_hash(&nextbigram2,NUMTAGS);
      init_hash(&prevbigram,NUMTAGS);
      init_hash(&prevbigram2,NUMTAGS);
      init_hash(&surroundtag,NUMTAGS);
      init_hash(&surroundtag2,NUMTAGS);
      init_hash(&next2tag,NUMTAGS/2);
      init_hash(&next2tag2,NUMTAGS/2);
      init_hash(&prev2tag,NUMTAGS/2);
      init_hash(&prev2tag2,NUMTAGS/2);
      init_hash(&next2wd,NUMWDS/2);
      init_hash(&next2wd2,NUMWDS/2);
      init_hash(&prev2wd,NUMWDS/2);
      init_hash(&prev2wd2,NUMWDS/2);


      lengthcount = Darray_len(correct_tag_corpus);
      for(count2=0;count2<lengthcount;++count2){
	sprintf(atempstr2,"%s %s",(char *)Darray_get(word_corpus,count2),right);
	if (Registry_get(WORDS,(char *)Darray_get(word_corpus,count2)) &&
	    ! Registry_get(SEENTAGGING,atempstr2)) 
	  strcpy(flag,"NOMATCH");
	else if 
	  (strcmp((char *)Darray_get(correct_tag_corpus,count2),right) == 0 &&
	   (strcmp
	    (first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2)),wrong) 
	    ==  0)
	    &&
	    (! is_tagged_with(right,(char *)Darray_get(guess_tag_corpus,count2))))
	  strcpy(flag,"BADMATCH");
	else if
	  (strcmp((char *)Darray_get(correct_tag_corpus,count2),right) != 0 &&
	   (strcmp
	    (first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2)),wrong) 
	    ==  0)
	   &&
	   (! is_tagged_with(right,(char *)Darray_get(guess_tag_corpus,count2))))
	  strcpy(flag,"GOODMATCH");
	else 
	  strcpy(flag,"NOMATCH");
	
	if (strcmp(flag,"BADMATCH") == 0) {
	  increment_array(&always,"DUMMY");
	  increment_array(&currentwd,(char *)Darray_get(word_corpus,count2));
	  if (count2 != lengthcount-1) {
	    strcpy(onewdaft,(char *)Darray_get(word_corpus,count2+1));
	    strcpy(onetagaft,
		   first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	    sprintf(wdpair,"%s %s",(char *)Darray_get(word_corpus,count2),
		                  (char *)Darray_get(word_corpus,count2+1));
    	    increment_array_create(&rbigram,wdpair);
	    sprintf(wdpair,"%s %s",(char *)Darray_get(word_corpus,count2),
		    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	    increment_array_create(&wdnexttag,wdpair);
	    increment_array_create(&next1or2tag,
			    first_tag_nospace(
				(char *)Darray_get(guess_tag_corpus,count2+1)));
	    increment_array_create(&next1or2or3tag,
			    first_tag_nospace(
				(char *)Darray_get(guess_tag_corpus,count2+1)));
	    increment_array_create(&next1tag,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	    increment_array(&next1wd,(char *)Darray_get(word_corpus,count2+1));
	    increment_array(&next1or2wd,(char *)Darray_get(word_corpus,count2+1));
	  }
	  if (count2 < lengthcount-2) {
	    strcpy(twotagaft,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    strcpy(forpasting2,
		   first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	    sprintf(forpasting,"%s %s",forpasting2,
		                       first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    increment_array_create(&nextbigram,forpasting);
	    increment_array_create(&next2tag,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    increment_array(&next2wd,(char *)Darray_get(word_corpus,count2+2));
	    if
	      (strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)),                 onetagaft) != 0)
	    {
	      increment_array_create(&next1or2tag,
		  first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	      
	      increment_array_create(&next1or2or3tag,
		  first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    }
	    if (strcmp((char *)Darray_get(word_corpus,count2+2),onewdaft) != 0)
	      increment_array(&next1or2wd,(char *)Darray_get(word_corpus,count2+2));
	  }
	  if (count2 < lengthcount-3) {
	    if (strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+3)),onetagaft) != 0
		&&
		strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+3)),twotagaft) != 0)
	      increment_array_create(&next1or2or3tag,
		 first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+3)));
	  }
	  if (count2 != 0) {
	    strcpy(onewdbfr,(char *)Darray_get(word_corpus,count2-1));
	    strcpy(onetagbfr,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    sprintf(wdpair,"%s %s",(char *)Darray_get(word_corpus,count2-1),
		                  (char *)Darray_get(word_corpus,count2));
    	    increment_array_create(&lbigram,wdpair);
	    sprintf(wdpair,"%s %s",first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)),
		                  (char *)Darray_get(word_corpus,count2));
    	    increment_array_create(&wdprevtag,wdpair);
	    increment_array_create(&prev1tag,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    increment_array(&prev1wd,(char *)Darray_get(word_corpus,count2-1));
	    increment_array(&prev1or2wd,(char *)Darray_get(word_corpus,count2-1));
	    increment_array_create(&prev1or2tag,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    increment_array_create(&prev1or2or3tag,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    if (count2 < lengthcount-1) {
	      strcpy(forpasting2,
		     first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	      sprintf(forpasting,"%s %s",forpasting2,
		                       first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	      increment_array_create(&surroundtag,forpasting);
	    }
	  }
	  if (count2 > 1) {
	    strcpy(twotagbfr,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    strcpy(forpasting2,
		   first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    sprintf(forpasting,"%s %s",forpasting2,
		                       first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    increment_array_create(&prevbigram,forpasting);
	    increment_array_create(&prev2tag,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    increment_array(&prev2wd,(char *)Darray_get(word_corpus,count2-2));
	    if (strcmp(first_tag_nospace(
		 (char *)Darray_get(guess_tag_corpus,count2-2)),onetagbfr) != 0){ 
	      increment_array_create(&prev1or2tag,
				     first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	      increment_array_create(&prev1or2or3tag,
				     first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    }
	    if (strcmp((char *)Darray_get(word_corpus,count2-2),onewdbfr) !=
		0)
	      increment_array(&prev1or2wd,(char *)Darray_get(word_corpus,count2-2));
	  }
	  if (count2 > 2) {
	     if (strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-3)),onetagbfr) != 0
		&&
		strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-3)),twotagbfr) != 0)
	       increment_array_create(&prev1or2or3tag,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-3)));
	  }
	}


	else if (strcmp(flag,"GOODMATCH") == 0) {
	  increment_array(&always2,"DUMMY");
	  increment_array(&currentwd2,(char *)Darray_get(word_corpus,count2));
	  if (count2 != lengthcount-1) {
	    strcpy(onewdaft,(char *)Darray_get(word_corpus,count2+1));
	    strcpy(onetagaft,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
            sprintf(wdpair,"%s %s",(char *)Darray_get(word_corpus,count2),
		                  (char *)Darray_get(word_corpus,count2+1));
    	    increment_array_create(&rbigram2,wdpair);
	    sprintf(wdpair,"%s %s",(char *)Darray_get(word_corpus,count2),
		                  first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
    	    increment_array_create(&wdnexttag2,wdpair);
	    increment_array_create(&next1tag2,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	    increment_array(&next1wd2,(char *)Darray_get(word_corpus,count2+1));
	    increment_array(&next1or2wd2,(char *)Darray_get(word_corpus,count2+1));
	    increment_array_create(&next1or2tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	    increment_array_create(&next1or2or3tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	  }
	  if (count2 < lengthcount-2) {
	    strcpy(twotagaft,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    strcpy(forpasting2,
		   first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
	    sprintf(forpasting,"%s %s",forpasting2,
		                       first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    increment_array_create(&nextbigram2,forpasting);
	    increment_array_create(&next2tag2,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    increment_array(&next2wd2,(char *)Darray_get(word_corpus,count2+2));
	    if (strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)),onetagaft) !=0) {
	      increment_array_create(&next1or2tag2,
		     first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	      increment_array_create(&next1or2or3tag2,
		    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+2)));
	    }
	    if (strcmp((char *)Darray_get(word_corpus,count2+2),onewdaft) !=0)
	      increment_array(&next1or2wd2,(char *)Darray_get(word_corpus,count2+2));
	  }
	  if (count2 < lengthcount-3) {
	    if (strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+3)),onetagaft) !=0 
		&&
		strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+3)),twotagaft) !=0 )
	      increment_array_create(&next1or2or3tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+3)));
	  }
	  if (count2 != 0) {
	    strcpy(onewdbfr,(char *)Darray_get(word_corpus,count2-1));
	    strcpy(onetagbfr,(char *)Darray_get(guess_tag_corpus,count2-1));
	    sprintf(wdpair,"%s %s",(char *)Darray_get(word_corpus,count2-1),
		                  (char *)Darray_get(word_corpus,count2));
    	    increment_array_create(&lbigram2,wdpair);
	    sprintf(wdpair,"%s %s",first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)),
		                  (char *)Darray_get(word_corpus,count2));
    	    increment_array_create(&wdprevtag2,wdpair);
	    increment_array_create(&prev1tag2,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    increment_array(&prev1wd2,(char *)Darray_get(word_corpus,count2-1));
	    increment_array(&prev1or2wd2,(char *)Darray_get(word_corpus,count2-1));
	    increment_array_create(&prev1or2tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    increment_array_create(&prev1or2or3tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    if (count2 < lengthcount-1) {
	      strcpy(forpasting2,
		     first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	      sprintf(forpasting,"%s %s",forpasting2,
		                       first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2+1)));
      increment_array_create(&surroundtag2,forpasting);
	    }
	  }
	  if (count2 >1 ) { 
	    strcpy(twotagbfr,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    strcpy(forpasting2,
		   first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    sprintf(forpasting,"%s %s",forpasting2,
		                       first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-1)));
	    increment_array_create(&prevbigram2,forpasting);
	    increment_array_create(&prev2tag2,first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    increment_array(&prev2wd2,(char *)Darray_get(word_corpus,count2-2));
	    if (strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)),onetagbfr) != 0){
	      increment_array_create(&prev1or2tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	      increment_array_create(&prev1or2or3tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-2)));
	    }
	    if (strcmp((char *)Darray_get(word_corpus,count2-2),onewdbfr) != 0)
	      increment_array(&prev1or2wd2,(char *)Darray_get(word_corpus,count2-2));
	  }
	  if (count2 > 2) {
	    if (strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-3)),onetagbfr) != 0 
		&&
		strcmp(first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-3)),twotagbfr) != 0)
	      increment_array_create(&prev1or2or3tag2,
			    first_tag_nospace((char *)Darray_get(guess_tag_corpus,count2-3)));
	  }
	}
      }  


check_counts(&always,&always2,"ALWAYS");
check_counts(&prev1tag,&prev1tag2,"PREVTAG");
check_counts(&next1tag,&next1tag2,"NEXTTAG");
check_counts(&next1or2tag,&next1or2tag2,"NEXT1OR2TAG");
check_counts(&prev1or2tag,&prev1or2tag2,"PREV1OR2TAG");
check_counts(&next1wd,&next1wd2,"NEXTWD");
check_counts(&currentwd,&currentwd2,"CURRENTWD");
check_counts(&prev1wd,&prev1wd2,"PREVWD");
check_counts(&rbigram,&rbigram2,"RBIGRAM");
check_counts(&lbigram,&lbigram2,"LBIGRAM");
check_counts(&wdnexttag,&wdnexttag2,"WDNEXTTAG");
check_counts(&wdprevtag,&wdprevtag2,"WDPREVTAG");
check_counts(&next1or2wd,&next1or2wd2,"NEXT1OR2WD");
check_counts(&prev1or2wd,&prev1or2wd2,"PREV1OR2WD");
check_counts(&next1or2or3tag,&next1or2or3tag2,"NEXT1OR2OR3TAG");
check_counts(&prev1or2or3tag,&prev1or2or3tag2,"PREV1OR2OR3TAG");
check_counts(&prevbigram,&prevbigram2,"PREVBIGRAM");
check_counts(&nextbigram,&nextbigram2,"NEXTBIGRAM");
check_counts(&surroundtag,&surroundtag2,"SURROUNDTAG");
check_counts(&next2tag,&next2tag2,"NEXT2TAG");
check_counts(&prev2tag,&prev2tag2,"PREV2TAG");
check_counts(&next2wd,&next2wd2,"NEXT2WD");
check_counts(&prev2wd,&prev2wd2,"PREV2WD");



    if (localbest > globalbest) {
      globalbest = localbest;
      strcpy(globaldif,localdif);
      strcpy(globalprint,localbestthing);}
    }
  }
  free(split_ptr[0]);
  free(split_ptr[1]);
  free(split_ptr[2]);
  free(split_ptr);
  for (count=0;count<strlen(globalprint);++count)
    if (*(globalprint+count) == '\'') 
      *(globalprint+count) = '\b'; 
  sprintf(systemcall,"cat %s | fix-kbest-rule-learn \'%s\' %s > aanewmynewtagggs",
	  argv[2],globalprint,argv[4]);
  system(systemcall);
  for (count=0;count<strlen(globalprint);++count)
    if (*(globalprint+count) == '\b') 
      *(globalprint+count) = '\''; 
  sprintf(systemcall,"mv aanewmynewtagggs %s",argv[2]);
  system(systemcall);
  correct_out = fopen(argv[3],"a");
  fprintf(correct_out,"%s\n",globalprint);
/*  fprintf(correct_out,"%d %s %s\n",globalbest,globalprint,globaldif);*/
  fclose(correct_out);
  CONTINUE = globalbest; 
  for (count=0;count<Darray_len(guess_tag_corpus);++count)
    if (strcmp((tempstr=(char *)Darray_get(guess_tag_corpus,count)),"STAART") != 0)
      free(tempstr);
  Darray_destroy(guess_tag_corpus);
  for (count=0;count<Darray_len(errorlist);++count)
    free((char *)Darray_get(errorlist,count));
  Darray_destroy(errorlist);
	 
}
return 0;
}
Пример #29
0
int main(int argc, char *argv[])
{
  time_t      delay = 0;
  aConfItem*  aconf;
  
  if(geteuid() == 0)
  {
  	fprintf(stderr, "ERROR: Don't run ircd as root!\n");
  	return -1;
  }

  /*
   * save server boot time right away, so getrusage works correctly
   */
  if ((CurrentTime = time(0)) == -1)
    {
      fprintf(stderr, "ERROR: Clock Failure: %s\n", strerror(errno));
      exit(errno);
    }

  /*
   * Setup corefile size immediately after boot
   */
  setup_corefile();

  /* 
   * set initialVMTop before we allocate any memory
   */
  initialVMTop = get_vm_top();

  /*
   * Initialize the Blockheap allocator
   */
  initBlockHeap();

  ServerRunning = 0;
  memset(&me, 0, sizeof(me));
  GlobalClientList = &me;       /* Pointer to beginning of Client list */
  cold_start = YES;             /* set when server first starts up */

  memset(&Count, 0, sizeof(Count));
  Count.server = 1;     /* us */

  initialize_global_set_options();

#ifdef REJECT_HOLD
  reject_held_fds = 0;
#endif

  ConfigFileEntry.dpath = DPATH;

  ConfigFileEntry.configfile = CPATH;   /* Server configuration file */

#ifdef KPATH
  ConfigFileEntry.klinefile = KPATH;         /* Server kline file */
#else
  ConfigFileEntry.klinefile = CPATH;
#endif /* KPATH */

#ifdef DLPATH
  ConfigFileEntry.dlinefile = DLPATH;
#else
  ConfigFileEntry.dlinefile = CPATH;
#endif /* DLPATH */

#ifdef GLINES
  ConfigFileEntry.glinefile = GLINEFILE;
#endif

#ifdef  ZIP_LINKS
  /* Make sure the include files match the library version number. */
  /* configure takes care of looking for zlib and zlibVersion(). */
  if (strcmp(zlibVersion(), ZLIB_VERSION) != 0)
  {
    fprintf(stderr, "WARNING: zlib include files differ from library.\n");
    fprintf(stderr, "WARNING: ZIPLINKS may fail!\n");
    fprintf(stderr, "WARNING: library %s, include files %s\n",
            zlibVersion(), ZLIB_VERSION);
  }
#endif

  myargv = argv;
  umask(077);                /* better safe than sorry --SRB */

  parse_command_line(argc, argv); 

  if (chdir(ConfigFileEntry.dpath))
    {
      perror("chdir");
      exit(-1);
    }

  /*
   * Check if daemon is already running
   */
  check_pidfile();

  init_sys(bootDaemon);
  init_log(logFileName);

  setup_signals();
  initialize_message_files();

  isupport = make_isupport();

  dbuf_init();  /* set up some dbuf stuff to control paging */
  init_hash();

  clear_scache_hash_table();    /* server cache name table */
  clear_ip_hash_table();        /* client host ip hash table */
  clear_Dline_table();          /* d line tree */
  initlists();
  initclass();
  initwhowas();
  init_stats();
  init_tree_parse(msgtab);      /* tree parse code (orabidoo) */

  fdlist_init();
  init_netio();

  read_conf_files(YES);         /* cold start init conf files */

  aconf = find_me();
  if (EmptyString(me.name))
    strncpy_irc(me.name, aconf->host, HOSTLEN);
  strncpy_irc(me.host, aconf->host, HOSTLEN);

  me.fd = -1;
  me.from = &me;
  me.servptr = &me;
  SetMe(&me);
  make_server(&me);

  me.serv->up = me.name;
  me.lasttime = me.since = me.firsttime = CurrentTime;
  add_to_client_hash_table(me.name, &me);
  
  check_class();
  write_pidfile();

  log(L_NOTICE, "Server Ready");

  ServerRunning = 1;
  while (ServerRunning) {
    usleep(100000);
    do_adns_io();
    delay = io_loop(delay);
    do_adns_io();

  }
  return 0;
}
Пример #30
0
int cmd_describe(int argc, const char **argv, const char *prefix)
{
	int contains = 0;
	struct option options[] = {
		OPT_BOOLEAN(0, "contains",   &contains, N_("find the tag that comes after the commit")),
		OPT_BOOLEAN(0, "debug",      &debug, N_("debug search strategy on stderr")),
		OPT_BOOLEAN(0, "all",        &all, N_("use any ref")),
		OPT_BOOLEAN(0, "tags",       &tags, N_("use any tag, even unannotated")),
		OPT_BOOLEAN(0, "long",       &longformat, N_("always use long format")),
		OPT__ABBREV(&abbrev),
		OPT_SET_INT(0, "exact-match", &max_candidates,
			    N_("only output exact matches"), 0),
		OPT_INTEGER(0, "candidates", &max_candidates,
			    N_("consider <n> most recent tags (default: 10)")),
		OPT_STRING(0, "match",       &pattern, N_("pattern"),
			   N_("only consider tags matching <pattern>")),
		OPT_BOOLEAN(0, "always",     &always,
			   N_("show abbreviated commit object as fallback")),
		{OPTION_STRING, 0, "dirty",  &dirty, N_("mark"),
			   N_("append <mark> on dirty working tree (default: \"-dirty\")"),
		 PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
		OPT_END(),
	};

	git_config(git_default_config, NULL);
	argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
	if (abbrev < 0)
		abbrev = DEFAULT_ABBREV;

	if (max_candidates < 0)
		max_candidates = 0;
	else if (max_candidates > MAX_TAGS)
		max_candidates = MAX_TAGS;

	save_commit_buffer = 0;

	if (longformat && abbrev == 0)
		die(_("--long is incompatible with --abbrev=0"));

	if (contains) {
		const char **args = xmalloc((7 + argc) * sizeof(char *));
		int i = 0;
		args[i++] = "name-rev";
		args[i++] = "--name-only";
		args[i++] = "--no-undefined";
		if (always)
			args[i++] = "--always";
		if (!all) {
			args[i++] = "--tags";
			if (pattern) {
				char *s = xmalloc(strlen("--refs=refs/tags/") + strlen(pattern) + 1);
				sprintf(s, "--refs=refs/tags/%s", pattern);
				args[i++] = s;
			}
		}
		memcpy(args + i, argv, argc * sizeof(char *));
		args[i + argc] = NULL;
		return cmd_name_rev(i + argc, args, prefix);
	}

	init_hash(&names);
	for_each_rawref(get_name, NULL);
	if (!names.nr && !always)
		die(_("No names found, cannot describe anything."));

	if (argc == 0) {
		if (dirty) {
			static struct lock_file index_lock;
			int fd;

			read_cache_preload(NULL);
			refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
				      NULL, NULL, NULL);
			fd = hold_locked_index(&index_lock, 0);
			if (0 <= fd)
				update_index_if_able(&the_index, &index_lock);

			if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1,
					    diff_index_args, prefix))
				dirty = NULL;
		}
		describe("HEAD", 1);
	} else if (dirty) {
		die(_("--dirty is incompatible with committishes"));
	} else {
		while (argc-- > 0) {
			describe(*argv++, argc == 0);
		}
	}
	return 0;
}