Ejemplo n.º 1
0
int main(int argc,char **argv)
{
	char linebuffer[300];
	FILE *ifile = fopen("/tmp/refs", "r");
	char *t;
	unsigned int un;
	struct rc_obj *curr_obj, *count1_obj;
	struct rc_obj lookup;
	struct ast_hashtab_iter *it;
	struct ast_hashtab *objhash;
	
	if (!ifile) {
		printf("Sorry, Cannot open /tmp/refs!\n");
		exit(10);
	}
	
	objhash = ast_hashtab_create(9000, hashtab_compare_rc, ast_hashtab_resize_java, ast_hashtab_newsize_java, hashtab_hash_rc, 1);
	
	while (fgets(linebuffer, sizeof(linebuffer), ifile)) {
		/* collect data about the entry */
		un = strtoul(linebuffer, &t, 16);
		lookup.addr = un;
		lookup.count = 1;

		count1_obj = ast_hashtab_lookup(objhash, &lookup);
		
		if (count1_obj) {
			/* there IS a count1 obj, so let's see which one we REALLY want */
			if (*(t+1) == '=') {
				/* start a new object! */
				curr_obj = alloc_obj(un, ++count1_obj->last_count);
				/* put it in the hashtable */
				ast_hashtab_insert_safe(objhash, curr_obj);
			} else {
				if (count1_obj->last_count > 1) {
					lookup.count = count1_obj->last_count;
					curr_obj = ast_hashtab_lookup(objhash, &lookup);
				} else {
					curr_obj = count1_obj;
				}
				
			}

		} else {
			/* NO obj at ALL? -- better make one! */
			if (*(t+1) != '=') {
				printf("BAD: object %x appears without previous allocation marker!\n", un);
			}
			curr_obj = count1_obj = alloc_obj(un, 1);
			/* put it in the hashtable */
			ast_hashtab_insert_safe(objhash, curr_obj);
			
		}
		
		if (*(t+1) == '+' || *(t+1) == '-' ) {
			curr_obj->total_refcount += strtol(t+1, NULL, 10);
		} else if (*(t+1) == '*') {
			curr_obj->destroy_count++;
		}
		
		add_to_hist(linebuffer, curr_obj);
	}
	fclose(ifile);
	
	/* traverse the objects and check for problems */
	it = ast_hashtab_start_traversal(objhash);
	while ((curr_obj = ast_hashtab_next(it))) {
		if (curr_obj->total_refcount != 0 || curr_obj->destroy_count != 1) {
			struct rc_hist *h;
			if (curr_obj->total_refcount != 0)
				printf("Problem: net Refcount not zero for object %x\n", curr_obj->addr);
			if (curr_obj->destroy_count > 1 )
				printf("Problem: Object %x destroyed more than once!\n", curr_obj->addr);
			printf("Object %x history:\n", curr_obj->addr);
			for(h=curr_obj->hist;h;h=h->next) {
				printf("   %s", h->desc);
			}
			printf("==============\n");
		}
	}
	ast_hashtab_end_traversal(it);
	return 0;
}
Ejemplo n.º 2
0
int main(int argc,char **argv)
{
	int len;
	int set[20], currset[20];
	char vals[40];
	struct ast_hashtab_iter *it;
	char *sptr;
	int i;
	int matched =0;
	int unmatched = 0;
	int wronglen = 0;
	
	if( argc < 3 )
	{
		printf("twoword <scrambleOfTwoWords> <longestwordlen>\n");
		exit(10);
	}

		
	
	/* find all the n-digit numbers that have each digit mentioned only once. */
	/* all the numbers including only the numbers 1-n; */
	printf("Reading %s...\n", DICT);
	read_dict();
	printf("Done, wasn't that quick?\n");

	strcpy(vals,argv[1]);
	len = atoi(argv[2]);

	/* the initial set */
	for(i=0;i<len;i++)
	{
		set[i] = i;
	}

	printf("Searching... (Note: if you repeat the same letter more than once in a word, expect multiple matches!)\n");

	it = ast_hashtab_start_traversal(dict);
        while( (sptr = ast_hashtab_next(it)) ) {
		char buf3[40];
		char *p;
		int tlen = strlen(sptr);
		int i;
		if(tlen != len) {
			wronglen++;
			continue; // skip all the words not exactly "len" chars long!
		}
		strcpy(buf3, vals);
		for(i=0; i<tlen; i++) {
			char y;
			y=sptr[i];
			p = strchr(buf3,y);
			if(p) { 
				rmcharfromset(buf3,y);
			} else {
				break; // this ain't the word 
			}

		}
		if( p ) {
			char buf4[200];
			int len7;
			printf("Match: Word=%s remainder=%s\n", sptr, buf3); 
			/* the initial set */
			len7 = strlen(buf3);
			for(i=0;i<len7;i++)
			{
				set[i] = i;
			}
			permute(set, len7, buf3, 0, currset, 0);
			matched++;
		} else {
			unmatched++;
		}
	}
	printf ("Matched: %d\nUnmatched: %d\nWrong Length: %d\n", matched, unmatched, wronglen);
	
}