コード例 #1
0
ファイル: count.c プロジェクト: luyi326/linguo
void free_count(Sentence sent)
{
	if (NULL == sent->count_ctxt) return;

	free_table(sent->count_ctxt);
	free(sent->count_ctxt);
	sent->count_ctxt = NULL;
}
コード例 #2
0
static int
vbbox_disconnect (sqlite3_vtab * pVTab)
{
/* disconnects the virtual table */
    VirtualBBoxPtr p_vt = (VirtualBBoxPtr) pVTab;
    free_table (p_vt);
    return SQLITE_OK;
}
コード例 #3
0
void main()
{
        int i;
        int findCnt;
        list_t*  listShow= NULL;
        
        char *find[]={"hello","home"};
        
        int wordsToHash = 20;//Remember to define your size!!!(how many phrase  is s[] )!

        static char *s[]={"steve","bOB","apple","ban","Johnson", 
        "banana","ice","happy","home","hello","love","wen","danny"
        ,"dog","hot" ,"cold","fato","fatrabbit","jerry","tux"};
        
        //timer
        hash_table_t *my_hash_table;
        clock_t         start, stop;
        struct timespec go, end;
        double cpu_time1;


        int size_of_table = 12;
        clock_gettime(CLOCK_REALTIME, &go);
        start = clock();
        my_hash_table = create_hash_table(size_of_table);
        
        
       
        //hashing   Remember
        for( i=0; i<wordsToHash ;i++){
        add_string(my_hash_table,s[i]);
        }

        listShow = lookup_string(my_hash_table,find[1]);


        stop = clock();
        clock_gettime(CLOCK_REALTIME, &end);
        cpu_time1 = diff_in_second(go, end);
        float   elapsedTime = (float)(stop - start) /(float)CLOCKS_PER_SEC * 1000.0f;
        printf( "Time to hash:  %3.1f ms\n", elapsedTime );
        printf("execution time of cpu : %lf sec\n", cpu_time1);
        printf("Found the word list \n");
        printList(listShow);
        printf("Found the word is %s \n",listShow->str);
        printf("-------------------------- \n");  



        printf("Print hash table content \n");
        for(i=0; i<size_of_table ;i++)
        {
         printList(my_hash_table->table[i]);
        printf("\n");
        }

        free_table(my_hash_table);
}
コード例 #4
0
ファイル: mu0.c プロジェクト: tessereth/mu0
void free_table(label_table_t *table)
{
    if (table != NULL)
    {
        free_table(table->next);
        free(table->label);
        free(table);
    }
}
コード例 #5
0
ファイル: match.c プロジェクト: ArthySundaram/firstrepo
/**
 * unpack_table - unpack a dfa table (one of accept, default, base, next check)
 * @blob: data to unpack
 * @bsize: size of blob
 *
 * Returns: pointer to table else NULL on failure
 *
 * NOTE: must be freed by free_table (not kmalloc)
 */
static struct table_header *unpack_table(char *blob, size_t bsize)
{
	struct table_header *table = NULL;
	struct table_header th;
	int unmap_alias = 0;
	size_t tsize;

	if (bsize < sizeof(struct table_header))
		goto out;

	/* loaded td_id's start at 1, subtract 1 now to avoid doing
	 * it every time we use td_id as an index
	 */
	th.td_id = be16_to_cpu(*(u16 *) (blob)) - 1;
	th.td_flags = be16_to_cpu(*(u16 *) (blob + 2));
	th.td_lolen = be32_to_cpu(*(u32 *) (blob + 8));
	blob += sizeof(struct table_header);

	if (!(th.td_flags == YYTD_DATA16 || th.td_flags == YYTD_DATA32 ||
	      th.td_flags == YYTD_DATA8))
		goto out;

	tsize = table_size(th.td_lolen, th.td_flags);
	if (bsize < tsize)
		goto out;

	/* freed by free_table */
	table = kmalloc(tsize, GFP_KERNEL | __GFP_NOWARN);
	if (!table) {
		tsize = tsize < sizeof(struct work_struct) ?
			sizeof(struct work_struct) : tsize;
		unmap_alias = 1;
		table = vmalloc(tsize);
	}
	if (table) {
		*table = th;
		if (th.td_flags == YYTD_DATA8)
			UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
				     u8, byte_to_byte);
		else if (th.td_flags == YYTD_DATA16)
			UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
				     u16, be16_to_cpu);
		else if (th.td_flags == YYTD_DATA32)
			UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
				     u32, be32_to_cpu);
		else
			goto fail;
	}

out:
	if (unmap_alias)
		vm_unmap_aliases();
	return table;
fail:
	free_table(table);
	return NULL;
}
コード例 #6
0
ファイル: MF_moduledb.c プロジェクト: DavidEGrayson/dynamorio
static void
event_exit(void)
{
    VDISPLAY_FUNC(NAME" exiting.");

    /* free structures */
    free_table();
    dr_mutex_destroy(table_lock);
}
コード例 #7
0
ファイル: env3.c プロジェクト: lastro/perso
char	*alias_name(char *buff)
{
	char	**split;
	char	*ret;

	split = ft_strsplit(buff, '=');
	ret = ft_strdup(&split[0][6]);
	free_table(split);
	return (ret);
}
コード例 #8
0
ファイル: env3.c プロジェクト: lastro/perso
char	*alias_value(char *buff)
{
	char	**split;
	char	*ret;

	split = ft_strsplit(buff, '=');
	split[1][ft_strlen(split[1]) - 1] = 0;
	ret = ft_strdup(&split[1][1]);
	free_table(split);
	return (ret);
}
コード例 #9
0
ファイル: match.c プロジェクト: ArthySundaram/firstrepo
/**
 * aa_dfa_free - free a dfa allocated by aa_dfa_unpack
 * @dfa: the dfa to free  (MAYBE NULL)
 *
 * Requires: reference count to dfa == 0
 */
static void aa_dfa_free(struct aa_dfa *dfa)
{
	if (dfa) {
		int i;

		for (i = 0; i < ARRAY_SIZE(dfa->tables); i++) {
			free_table(dfa->tables[i]);
			dfa->tables[i] = NULL;
		}
	}
	kfree(dfa);
}
コード例 #10
0
ファイル: db.c プロジェクト: AsherBond/MondocosmOS
int db__driver_close_database()
{
    int i;

    for (i = 0; i < db.ntables; i++) {
	save_table(i);
	free_table(i);
    }
    G_free(db.tables);

    return DB_OK;
}
コード例 #11
0
ファイル: MF_moduledb.c プロジェクト: DavidEGrayson/dynamorio
static void
event_nudge(void *drcontext, uint64 argument)
{
    DISPLAY_FUNC(NAME" received nudge event; re-reading config file.");

    /* An external process has nudged us with dr_nudge_process() telling us
     * to re-read the configuration file. */
    dr_mutex_lock(table_lock);
    free_table();
    read_table();
    dr_mutex_unlock(table_lock);
}
コード例 #12
0
ファイル: tables.c プロジェクト: rstallman/sdust
int main()
{
     
     SymbolTable* tb1 = create_table(SYMTBL_UNIQUE_NAME);
     SymbolTable* tb2 = create_table(SYMTBL_UNIQUE_NAME);

     
     add_to_table(tb1, "Loop1", 0x400000);
     add_to_table(tb1, "Loop2", 0xF00000);
     add_to_table(tb1, "Loop3", 0xFF0000);
     add_to_table(tb1, "Loop4", 0xEF0000);
     add_to_table(tb1, "Done:", 0xEE0000);

     char str[255];
     strcpy(str, "Label0");
     
     for(int i = 0; i < 100; i++) {
	  str[5] = i;
	  add_to_table(tb1, str, 0xEFFF00);
	  add_to_table(tb2, str, 0xFFFFFF00);
     }
     
     write_table(tb1, stdout);
     
     int64_t res = get_addr_for_symbol(tb1, "Done:");

     if(res != -1) {
	  printf("Find symbol: addr: %lld\n", res);
     }
     else {
	  printf("No symbol in Table\n");	  
     }
     
     
     free_table(tb1);
     free_table(tb2);
     
     return 0;
}
コード例 #13
0
ファイル: mymenu.c プロジェクト: nihui/oxygenspread
void MYMENU_FileNew()
{
    free_table( table );
    free_history();
    // a new table
    table = create_table();
    set_caption( NULL );
    restore_view();
    update_row_tails();
    update_col_tails();
    update_selection_rect();
    update_table_view( hwnd );
    unsaved = 1;
}
コード例 #14
0
ファイル: srvapi.c プロジェクト: tomidelucca/TP1-SO
void
process_request(Packet * pckt_req, Packet * pckt_ans)
{
	int i;
	TableStatus nstatus[MAX_TABLES];

	switch (pckt_req->opcode) {
		case CHECK_TABLE:
			check_table(
				pckt_req->data.req_check_table.id,
				&(pckt_ans->data.ans_check_table.status)
			);
			break;

		case CHECK_TABLES:
			check_tables(nstatus);
			for (i = 0; i < MAX_TABLES; i++)
				pckt_ans->data.ans_check_tables.status[i] = nstatus[i];

			break;

		case OCCUPY_TABLE:
			occupy_table(
				pckt_req->data.req_occupy_table.id,
				&(pckt_ans->data.ans_occupy_table.success)
			);
			break;

		case FREE_TABLE:
			free_table(
				pckt_req->data.req_free_table.id,
				&(pckt_ans->data.ans_free_table.success)
			);
			break;

		case RESERVE_TABLE:
			reserve_table(
				pckt_req->data.req_reserve_table.id,
				&(pckt_ans->data.ans_reserve_table.success)
			);
			break;

		default:
			// TODO unknown operation code
			break;
	}
}
コード例 #15
0
ファイル: exclusive.c プロジェクト: Die9teWoge/popeye
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void exclusive_chess_exclusivity_detector_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  assert(ply_horizon==maxply);
  ply_horizon = nbply+6;

  exclusive_chess_undecidable_continuations[nbply] = allocate_table();

  detect_exclusivity_and_solve_accordingly(si);

  free_table(exclusive_chess_undecidable_continuations[nbply]);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
コード例 #16
0
ファイル: hash.c プロジェクト: pchapin/spica
int main(void)
{
  hash_table table;
  char *strings[] = {
    "The first key string",
    "The second key string",
    "The third key string",
    "The fourth key string",
    "The fifth key string",
    "The sixth key string",
    NULL
  };

  char *junk[] = {
    "The first data",
    "The second data",
    "The third data",
    "The fourth data",
    "The fifth data",
    "The sixth data"
  };

  int i;
  void *j;

  construct_table(&table, 200);
  for (i = 0; NULL != strings[i]; i++) insert(strings[i], junk[i], &table);
  for (i = 0; NULL != strings[i]; i++)
    {
      printf("\n");
      enumerate(&table, printer);
      del(strings[i], &table);
    }
  for (i = 0; NULL != strings[i]; i++)
    {
      j = lookup(strings[i], &table);
      if (NULL == j)
        printf("\n'%s' is not in table", strings[i]);
      else
        printf("\nERROR: %s was deleted but is still in table.", strings[i]);
    }
  free_table(&table, NULL);
  return 0;
}
コード例 #17
0
static void
table_sweep (void)
{
    table *x = all_tables;
    all_tables = 0;
    while (x != 0)
    {
	table *next = x->next;
	if (!rep_GC_CELL_MARKEDP (rep_VAL(x)))
	    free_table (x);
	else
	{
	    rep_GC_CLR_CELL (rep_VAL(x));
	    x->next = all_tables;
	    all_tables = x;
	}
	x = next;
    }
}
コード例 #18
0
ファイル: main.c プロジェクト: af-inet/chash
void test_strings(){
	htable *table;

	table = create_table(32);

	// Wrappers
	char  (* set)(htable*, char*, char*);
	char* (* get)(htable*, char*);
	set = &hash_sets;
	get = &hash_gets;

	set(table, "a", "aaa");
	set(table, "b", "bbb");
	set(table, "c", "ccc");
	set(table, "d", "ddd");
	set(table, "e", "e");
	set(table, "f", "f");
	set(table, "g", "g");
	set(table, "h", "h");
	set(table, "i", "i");
	set(table, "j", "j");
	set(table, "k", "k");
	set(table, "l", "l");
	set(table, "i", "XXX");
	
	printf("[%s] = %s\n", "a", get(table, "a"));
	printf("[%s] = %s\n", "b", get(table, "b"));
	printf("[%s] = %s\n", "c", get(table, "c"));
	printf("[%s] = %s\n", "d", get(table, "d"));
	printf("[%s] = %s\n", "e", get(table, "e"));
	printf("[%s] = %s\n", "f", get(table, "f"));
	printf("[%s] = %s\n", "g", get(table, "g"));
	printf("[%s] = %s\n", "h", get(table, "h"));
	printf("[%s] = %s\n", "i", get(table, "i"));
	printf("[%s] = %s\n", "j", get(table, "j"));
	printf("[%s] = %s\n", "k", get(table, "k"));
	printf("[%s] = %s\n", "l", get(table, "l"));
	printf("[%s] = %s\n", "None?", get(table, "none"));

	free_table(table);
}
コード例 #19
0
ファイル: process_request.c プロジェクト: Amnacog/Bordel
int						process_request(int sockfd, int verbose)
{
	char				*cmd_names[CMD_NB + 1] = {"CONNECT", NULL};
	void				(*f[CMD_NB])(char **, int, int) = {r_connect};
	char				buffer[BUFF_SIZE];
	int					ret;
	char				**cmd;
	int					i;

	if ((ret = read(sockfd, buffer, BUFF_SIZE - 1)) <= 0) {
		close(sockfd);
		return (1);
	}

	if (buffer[ret - 1] == '\n') {
		buffer[ret - 1] = '\0';
	} else {
		buffer[ret] = '\0';
	}

	if (verbose) {
		dprintf(1, "got command: '%s'\n", buffer);
	}
	if ((cmd = ft_strsplit(buffer, ' ')) == NULL) {
		writen(sockfd, ERROR_500, STRLEN(ERROR_500));
		close(sockfd);
		return (1);
	}

	i = 0;
	while (cmd_names[i]) {
		if (!strcmp(cmd_names[i], cmd[i])) {
			f[i](cmd, sockfd, verbose);
			break ;
		}
		++i;
	}
	free_table(cmd);
	return (0);
}
コード例 #20
0
ファイル: exclusive.c プロジェクト: Die9teWoge/popeye
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void exclusive_chess_nested_exclusivity_detector_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  assert(ply_horizon<maxply);

  if (nbply>ply_horizon)
  {
    TraceText("stopping recursion");
    remember_previous_move_as_undecidable();
    solve_result = previous_move_is_illegal;
  }
  else
  {
    ply const save_ply_horizon = ply_horizon;

    exclusive_chess_undecidable_continuations[nbply] = allocate_table();

    detect_exclusivity_and_solve_accordingly(si);

    TraceValue("%u",nbply);
    TraceValue("%u",exclusive_chess_nr_continuations_reaching_goal[nbply]);
    TraceValue("%u",nr_decidable_continuations_not_reaching_goal[nbply]);
    TraceValue("%u\n",table_length(exclusive_chess_undecidable_continuations[nbply]));

    if (nr_decidable_continuations_not_reaching_goal[nbply]==0
        && exclusive_chess_nr_continuations_reaching_goal[nbply]<=1
        && table_length(exclusive_chess_undecidable_continuations[nbply])+exclusive_chess_nr_continuations_reaching_goal[nbply]>1)
      remember_previous_move_as_undecidable();

    free_table(exclusive_chess_undecidable_continuations[nbply]);

    ply_horizon = save_ply_horizon;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
コード例 #21
0
ファイル: api.c プロジェクト: mclumd/Alfred
int sentence_parse(Sentence sent, Parse_Options opts) {
    int nl;

    verbosity = opts->verbosity;
 
    free_sentence_disjuncts(sent);
    resources_reset_space(opts->resources);

    if (resources_exhausted(opts->resources)) {
	sent->num_valid_linkages = 0;
	return 0;
    }

    expression_prune(sent); 
    print_time(opts, "Finished expression pruning");
    prepare_to_parse(sent, opts);

    init_fast_matcher(sent);
    init_table(sent);

    /* A parse set may have been already been built for this sentence,
       if it was previously parsed.  If so we free it up before building another.  */
    free_parse_set(sent);
    init_x_table(sent);

    for (nl = opts->min_null_count; 
	 (nl<=opts->max_null_count) && (!resources_exhausted(opts->resources)); ++nl) {
	sent->null_count = nl;
	sent->num_linkages_found = parse(sent, sent->null_count, opts);
	print_time(opts, "Counted parses");
	post_process_linkages(sent, opts);
	if (sent->num_valid_linkages > 0) break;
    }

    free_table(sent);
    free_fast_matcher(sent);
    print_time(opts, "Finished parse");

    return sent->num_valid_linkages;
}
コード例 #22
0
ファイル: mu0.c プロジェクト: tessereth/mu0
void assemble(FILE *fin, FILE *fout, int verbose) 
{
    label_table_t *table;
    char line[LINE_SIZE];
    int line_ok;

    table = generate_label_table(fin, verbose);
    /* Iterate through all the lines. This is full of pointer magic
     * which is why the code is so fragile.
     */
    while (fgets(line, LINE_SIZE, fin) != NULL)
    {
        line_ok = 0;
        if (*line == LABEL_C || *line == COMMENT_C || isspace(*line))
        {
            /* ignore line */
            line_ok = 1;
        }
        else if (*line == NUM_LITERAL_C)
        {
            fprintf(fout, "%04lx\n", strtol(line+1, NULL, 0));
            line_ok = 1;
        }
        else if (*line == CHAR_LITERAL_C)
        {
            fprintf(fout, "%04x\n", (int) line[1]);
            line_ok = 1;
        }
        else
        {
            line_ok = process_opcode(line, table, fout, verbose);
        }
        if (!line_ok)
        {
            fprintf(stderr, "Warning: Ignoring bad line: %s", line);
        }
    }
    free_table(table);
	return;
}
コード例 #23
0
ファイル: assembler.c プロジェクト: harshmujoo/proj2
/* Runs the two-pass assembler. Most of the actual work is done in pass_one()
   and pass_two().
 */
int assemble(const char* in_name, const char* tmp_name, const char* out_name) {
    FILE *src, *dst;
    int err = 0;
    SymbolTable* symtbl = create_table(SYMTBL_UNIQUE_NAME);
    SymbolTable* reltbl = create_table(SYMTBL_NON_UNIQUE);

    if (in_name) {
        printf("Running pass one: %s -> %s\n", in_name, tmp_name);
        if (open_files(&src, &dst, in_name, tmp_name) != 0) {
            free_table(symtbl);
            free_table(reltbl);
            exit(1);
        }

        if (pass_one(src, dst, symtbl) != 0) {
            err = 1;
        }
        close_files(src, dst);
    }

    if (out_name) {
        printf("Running pass two: %s -> %s\n", tmp_name, out_name);
        if (open_files(&src, &dst, tmp_name, out_name) != 0) {
            free_table(symtbl);
            free_table(reltbl);
            exit(1);
        }

        fprintf(dst, ".text\n");
        if (pass_two(src, dst, symtbl, reltbl) != 0) {
            err = 1;
        }
        
        fprintf(dst, "\n.symbol\n");
        write_table(symtbl, dst);

        fprintf(dst, "\n.relocation\n");
        write_table(reltbl, dst);

        close_files(src, dst);
    }
    
    free_table(symtbl);
    free_table(reltbl);
    return err;
}
コード例 #24
0
ファイル: main.c プロジェクト: naaf/Master
void *run_com(void *arg) {
	char response[512];
	char **tab = NULL;
	int size;

	memset(response, 0, 1024);

	fprintf(stderr, "thread com demarre :\n");

	/*--------------Blocquer les signaux------------------*/
	sigset_t mask;
	sigfillset(&mask);
	pthread_sigmask(SIG_SETMASK, &mask, NULL);

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

	while (TRUE) {
		read_response(sc, response);
		fprintf(stderr, "com: recu reponse len %zu : %s\n", strlen(response),
				response);

		if (0 == strlen(response)) {
			fprintf(stderr, "ERROR : Connection Socket");
			erreur("ERROR : Connection Socket", TRUE);
			break;
		}

		tab = string_to_arraystring(response, &size, '/');

		traitement(tab, size);

		/*free resources*/
		free_table(tab, size);
		memset(response, 0, sizeof(response));
	}
	pthread_cancel(thread_chat); //TODO
	return NULL;
}
コード例 #25
0
ファイル: main.c プロジェクト: BlackSenf/MyRepository
int main(int argc, char** argv) {
	int i;
	INDEX* list = NULL;

	FILE* in = fopen("adb.txt", "rt");

	unsigned int count = load_table(in, &list);
	printf("Elements: %u\n", count);
	for(i = 0; i < count; i++)
		printf("nick(%d) = '%s'\n", i, list[i].nick);

	INDEX* index = find_nick("priska", list, count);

	ENTRY entry;
	fseek(in, 0, SEEK_SET);
	load_entry(index, &entry, in);
	printf("nick: '%s'\n", entry.nick);
	printf("email: '%s'\n", entry.email);
	printf("comment: '%s'\n", entry.comment);

	free_table(&list);
	fclose(in);
}
コード例 #26
0
ファイル: hash.c プロジェクト: SibghatullahSheikh/kamailio
/*
 * Generate hash table, use did as hash key
 */
int gen_did_table(struct hash_entry** table, domain_t* list)
{
	unsigned int slot;
	struct hash_entry* e;

	if (!table) {
		ERR("Invalid parameter value\n");
		return -1;
	}

	while(list) {
		e = new_hash_entry(&list->did, list);
		if (!e) goto error;
		slot = calc_hash(&list->did);
		e->next = table[slot];
		table[slot] = e;
		list = list->next;
	}
	return 0;
 error:
	free_table(table);
	return -1;
}
コード例 #27
0
ファイル: threat.c プロジェクト: thomas-maeder/popeye
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void threat_solver_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  threats[nbply] = allocate_table();

  if (!is_in_check(SLICE_STARTER(si)))
  {
    fork_solve_delegate(si);
    threat_lengths[nbply] = solve_result-1;
  }

  pipe_solve_delegate(si);

  free_table(threats[nbply]);
  threat_lengths[nbply] = no_threats_found;
  threats[nbply] = table_nil;

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
コード例 #28
0
ファイル: encode.c プロジェクト: shiyingzheng/huffman_encode
/*
 * prints the bits from the linked list as chars
 * takes chars from stream as needed with extend list
 * until the file reaches EOF.
 * prints the new eof mapping as well
 * fills out the rest of the bits with 0's
 */
void printbits(huffmantree* tree,FILE* stream,FILE* out){
	char** t=table(tree);
	linkedlist* list=treebits(tree,t);
	int counter=0;
	int maxcharlength=(tree->size+1)/2;
	int sum=0;
	int i=0;
	int eof=0;
	while(linkedlist_size(list)){
		//printf("%d\n",linkedlist_size(list));
		if(linkedlist_size(list)<maxcharlength){
			if(maxcharlength>CHAR_BIT) extendlist(list,t,maxcharlength/CHAR_BIT,stream);
			else extendlist(list,t,maxcharlength,stream);
		}
		if(feof(stream)&&!eof){
			extendlistwitheof(list,t);
			eof=1;
		}
		char* frontbit=(char*)linkedlist_rmfront(list);
		sum=sum*2+(*frontbit-'0');
		free(frontbit);
		counter++;
		if (counter%CHAR_BIT==0){
			fprintf(out,"%c",sum);
			sum=0;
		}
	}
	i=0;
	while(counter%CHAR_BIT!=0){
		i++;
		sum=sum*2;
		counter++;
	}
	if(i)fprintf(out,"%c",sum);
	linkedlist_free(list);
	free_table(t);
}
コード例 #29
0
ファイル: spell_check.c プロジェクト: Sartre78/Spellchecker
// main 
int main (void)
{
    // Open dictionary    
    FILE* file = fopen("large_dictionary.txt", "r");

    /* begin loop to read words from file.  "143091" is being hard coded in as 
       the known value of total words in the file. */
    for (int i = 0; i < 143091; i++)
    {
        // allocate new node and check for NULL
        node* new_node = malloc(sizeof(node)); {if (new_node == NULL) return false;}
    
        // scan word from file into the "word" portion of the new node struct
        fscanf(file, "%s", new_node->word);
        
        // initial insertion scenario (i.e., the spot in the table array is empty)
        if (table[hash(new_node->word)] == NULL)  {table[hash(new_node->word)] = new_node;}
    
        /* otherwise, put the new string in the first position and link the
           previous node to the new head of the list */
        else 
        {
            // create a node equal to the current value of the table
            node* curr = table[hash(new_node->word)];  
            /* point "new_node" (the struct holding the value of the desired
               word to be inserted) to the newly created node that equals what
               to this point was the start of the list */ 
            new_node->next = curr;
            /* set the head pointer of the "k"th spot in the array (i.e., the 
               "head") to be the node containing the desired string to be 
               inserted.  */ 
            table[hash(new_node->word)] = new_node;
        }        
    }
    printf(".\n\n\n");

    // prompt the user to print dictionary
    
    // switch case
    while (true)
    {
        printf("\nPlease enter a valid option\n"); 
        printf("\n 1 - Quit\n"); 
        printf("\n 2 - Print a letter of the dictionary\n");
        printf("\n 3 - Print the full dictionary\n");
        printf("\n 4 - Check to see if a specific word is in the dictionary\n\n");
        int option = GetInt();

        switch (option)
        {
            // quit
            case 1: free_table(); printf("\nGoodbye!\n\n"); fclose(file); return 0;
            
            // print an individual section ("Letter") of the dictionary
            case 2: printf("\nWhich letter of the dictionary would you like to print?\n\n"); // prompt user
                    char* c = GetString(); // get string from user
                    int alpha = c[0];
                    if (isalpha(alpha) == 0) {printf("\nNot a letter!\n"); break;}
                    int h = hash(c); // determine hash key
                    print_i(h); free(c); break; // print table for letter & free memory

            // print dictionary
            case 3: print_all(); break;
            
            case 4: printf("\nWhich word would you like to check?\n\n"); // prompt user
                    char* w = GetString(); // get string from user
                    // check the first character of the word to avoid seg fault                   
                    if (isalpha(w[0]) == 0) {printf("\nThat's not a word!\n"); free(w); break;}
                    check(w); free(w); break; // check word and free memory   

            default: printf("Not a valid option.\n"); break;
        }   
    }  
} 
コード例 #30
0
ファイル: builtin.c プロジェクト: jdtatz/Cuttlefish
void pop_call_stack(){
    obj * o = stack_pop(call_stack);
    free_obj(o);
    free_table(call_stack_top->names);
    call_stack_top = call_stack_top->next;
}