static dict_bin_t *bd_no_binary(char *txt_file_name, char *binary_file_name , int *w_count)
{
	dict_elem_t *head_p = NULL;
	dict_bin_t  *b_head_p = NULL;
	void *value;

	*w_count = wd_get_elem_count(txt_file_name);
	if (w_count < 0)
		return (void *)NULL;
	PRINT(*w_count);
	printf("%d\n", *w_count);

	head_p = malloc((*w_count) * sizeof(*head_p));

	PRINT_P(head_p);
	PRINT_P(&head_p);
	PRINT((*w_count) * sizeof(*head_p));

	if ((head_p = wd_read_elem_from_txt(txt_file_name, head_p, *w_count)) == NULL) {
		printf("wd_word_default() wd_read_elem_from_txt() is error\n");
		return NULL;
	}
#if DEBUGB1
//	wd_print_data(head_p, *w_count);
#endif

	b_head_p = malloc((*w_count) * sizeof(*b_head_p));
//#if DEBUGB1
//	printf("%d %p\n", (*w_count)*sizeof(*b_head_p), b_head_p);
//#endif
//#if DEBUGB2
//	printf("debug bd_copy_from_wd\n");
	bd_copy_from_wd(b_head_p, head_p, *w_count);

	free(head_p);

//	bd_print_data(b_head_p, *w_count);
//#endif
	if ((value = bd_fwrite(b_head_p, *w_count, binary_file_name)) == NULL)
	{
		printf("error in bd_no_binary \n");
		return NULL;
	}

#if DEBUGB3
#endif
#if 0
#endif 
	
	return b_head_p;
}
예제 #2
0
static char * wd_read_trans(FILE *fp, dict_elem_t *word_p)
//return EOF
{
	char *tmp;
	//char buf[BUFSIZ/10];
	char buf[BUFSIZ];
	int len;
	int n_trans = 1;
	int i;

	if ((tmp = fgets(buf, BUFSIZ, fp)) == NULL)
		return NULL;	//EOF
	len = strlen(buf);
	if (buf[len-1] == '\n')
		buf[len-1] = '\0';

	for (i = 0; buf[i] != '\0'; i++)
		if (buf[i] == '@' && buf[i+1] != '@' && buf[i+1] != '\0')
			n_trans++;
	word_p->n_trans = n_trans;
	PRINT(n_trans);

	word_p->trans = malloc(sizeof(char *) * n_trans);

	for (tmp = buf, i = 0; tmp = strtok(tmp, "@"); i++, tmp = NULL) {
		len = strlen(tmp);
		word_p->trans[i] = malloc(len + 1);
		strncpy(word_p->trans[i], tmp, len);
		PRINT_P(word_p->trans[i]);
		PRINT_S(word_p->trans[i]);
	}

	return (char *)1;
}
예제 #3
0
static char * wd_read_key(FILE *fp, dict_elem_t *word_p)
// return EOF or malloc of word_p->key 
{
	//char buf[BUFSIZ/10];
	char buf[BUFSIZ];
	char *ret;
	int len;
	if ((ret = fgets(buf, BUFSIZ, fp)) == NULL)
		return NULL;	//EOF
	len = strlen(buf);
	if (buf[len-1] == '\n') {
		buf[len-1] = '\0';
		wd_remove_first(buf, len-1);
		len = strlen(buf);
		word_p->key = malloc(len + 1);
	} else {
		wd_remove_first(buf, len);
		len = strlen(buf);
		word_p->key = malloc(len + 1);
	}
	
	strncpy(word_p->key, buf, len);

	PRINT_P(word_p->key);
	PRINT_S(word_p->key);

	return word_p->key;
}
예제 #4
0
static void
radio_off(){
  PRINT_P("radio_off\n");
  if(is_radio_on ==1){
    NETSTACK_RADIO.off();
    is_radio_on = 0;
  }
}
예제 #5
0
/*---------------------------------------------------------------------------*/
static void
radio_on(){
  PRINT_P("radio_on\n");
  if(is_radio_on ==0){
    NETSTACK_RADIO.on();
    is_radio_on = 1;
  }
}
예제 #6
0
char *get_addr(char *head, size_t size)
{
	char *ret;

	((memctl_t *)head)->left -= size;
	ret = ((memctl_t *)head)->cur;
	((memctl_t *)head)->cur += size;

	PRINT_P(head);
	PRINT(((memctl_t *)head)->left);
	PRINT_P(((memctl_t *)head)->cur);
	PRINT_P(((memctl_t *)head)->next);

	PRINT_P(ret);

	return ret;
}
예제 #7
0
void * wd_word_default(char *filename)
{
	int i;
	dict_elem_t *head_p = NULL;
	dict_elem_t *elem_fund= NULL;
	int w_count = wd_get_elem_count(FILENAME);
	if (w_count < 0)
		return (void *)NULL;
	PRINT(w_count);
	printf("%d\n", w_count);
#if DEBUG2
	head_p = malloc(1000000000);
#endif
#if  DEBUG1
#else
	head_p = malloc(w_count * sizeof(*head_p));
	PRINT_P(head_p);
	PRINT_P(&head_p);
	PRINT(w_count * sizeof(*head_p));

	if ((head_p = wd_read_elem_from_txt(FILENAME, head_p, w_count)) == NULL)
		printf("wd_word_default() wd_read_elem_from_txt() is error\n");

	wd_shell_sort(head_p, 0, w_count-1);

	printf("Welcome enjoy this dictionary soft\n");
	for (;;) {
//		wd_print_data(head_p, w_count);
		elem_fund = wd_search(head_p, w_count);
		if (elem_fund == NULL)
			continue;
		for (i = 0; i < elem_fund->n_trans; i++) {
			printf("%s\n", elem_fund->trans[i]);
		}
	}
	wd_distory(head_p, w_count);

#endif
}
static void *bd_fwrite(dict_bin_t *b_head_p, int w_count, char *binary_file_name)
{
	FILE *fbp;
	int i, j;
	int len;

	if ((fbp = fopen(binary_file_name, "wb")) == NULL) {
		perror("bd_fwrite at fopen:");
		return NULL;
	}
#if DEBUGB4
	fwrite("abcdefg", 7, 1, fbp);
#endif 

	fwrite(&w_count, sizeof(w_count), 1, fbp); //word_count;

	for (i = 0; i < w_count; i++) { //word info
		fwrite(&(b_head_p[i].key_len), sizeof(b_head_p[i].key_len), 1, fbp);
		PRINT_P(b_head_p[i].key);
		PRINT_P(&b_head_p[i].key);
		PRINT_S(b_head_p[i].key);
		PRINT(b_head_p[i].key_len);
		fwrite(b_head_p[i].key, b_head_p[i].key_len, 1, fbp);

		fwrite(&(b_head_p[i].n_trans), sizeof(b_head_p[i].n_trans), 1, fbp);

		for (j = 0; j < b_head_p[i].n_trans; j++) {
			len = strlen(b_head_p[i].trans[j]);
			fwrite(&(len), sizeof(len), 1, fbp);
			fwrite(b_head_p[i].trans[j], len, 1, fbp);
		}
	}

	fclose(fbp);
	return (void *) 1;
}
예제 #9
0
/*---------------------------------------------------------------------------*/
static char
plb_powercycle(void)
{

  PRINT_P("plb_powercycle [sr:%d cw:%d]\n",send_req,c_wait);

  PT_BEGIN(&pt);
  while(1) {
    // check on/send state
    if(send_req == 1 && c_wait==1){
    	PRINTF("plb_powercycle send DATA <start>\n");
    	send_req = 0;	//avoid repeat sending
    	plb_send_data(sent_callback, sent_ptr);
    	PRINTF("plb_powercycle send DATA <end>\n");
    	radio_off();
    	NETSTACK_MAC.input();
    }

    /* on */
    radio_on();
    rtimer_set(&rt, RTIMER_NOW() + PC_ON_TIME, 1,
	       (void (*)(struct rtimer *, void *))plb_powercycle, NULL);
    PT_YIELD(&pt);

    /* off */
    if(wait_packet == 0){
      radio_off();
    }
    else if (wait_packet > 0)
    {
    	wait_packet = 0;
    }
    rtimer_set(&rt, RTIMER_NOW() + PC_OFF_TIME, 1,
	       (void (*)(struct rtimer *, void *))plb_powercycle, NULL);
    PT_YIELD(&pt);
  }
  PT_END(&pt);
}