static int send_more(ikss_Stream *self)
{
  int len = 0;
  if (self->send_buf) {
    len = self->send_len - self->send_count;
  }
  if (len == 0) {
    assert(self->send_more_buf);
    reset_string(self->send_buf);
    self->send_buf = self->send_more_buf;
    self->send_more_buf = NULL;
    len = self->send_count = self->send_len = strlen(self->send_buf);
  }
  assert(len > 0);
  return ikst_Send (self->sock, self->send_buf + self->send_count, len);
}
示例#2
0
void compute_varint_size(){
  int* values;
  values = malloc(VALTAB_SIZE*sizeof(int));

  int* size_nodelta;
  size_nodelta = malloc(VALTAB_SIZE*sizeof(int));
  int* size_delta;
  size_delta = malloc(VALTAB_SIZE*sizeof(int));

  int i;
  int val;
  val = 0;
  for (i=0; i<VALTAB_SIZE; i++){
    values[i] = val;
    val+=STEP;
  }

  int j;
  for (j=0; j<VALTAB_SIZE; j++){
    appendInt32_nonDelta(values[j]);
    size_nodelta[j] = string_size();
  }

  char* res = data();

  reset_string();

  for (i=0; i<VALTAB_SIZE; i++){
    appendInt32(values[i]);
    size_delta[i] = string_size();
  }

  char* res2=data();

  FILE* f = fopen("varint_size.txt","w");
  for (i = 0; i<VALTAB_SIZE; i++) {
    int a, b, c;
    a= values[i];
    b= size_nodelta[i];
    c= size_delta[i];
    fprintf(f,"%d %d %d \n", a, b, c);
    if (i%100==0) printf("%d/10000\n",i);
  }
}
示例#3
0
文件: tablefunc.c 项目: colinet/sqlix
static struct tupstore *
build_tuplestore_recursively(char *key_fld,
							 char *parent_key_fld,
							 char *relname,
							 char *orderby_fld,
							 char *branch_delim,
							 char *start_with,
							 char *branch,
							 int level,
							 int *serial,
							 int max_depth,
							 bool show_branch,
							 bool show_serial,
							 struct mctx * per_query_ctx,
							 AttInMetadata *attinmeta,
							 struct tupstore *tupstore)
{
	struct tuple *	tupdesc = attinmeta->tupdesc;
	int			ret;
	int			proc;
	int			serial_column;
	struct string sql;
	char	  **values;
	char	   *current_key;
	char	   *current_key_parent;
	char		current_level[INT32_STRLEN];
	char		serial_str[INT32_STRLEN];
	char	   *current_branch;
	struct heap_tuple *	tuple;

	if (max_depth > 0 && level > max_depth)
		return tupstore;

	init_string(&sql);

	/* Build initial sql statement */
	if (!show_serial)
	{
		append_fstring(&sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s",
						 key_fld,
						 parent_key_fld,
						 relname,
						 parent_key_fld,
						 quote_literal_cstr(start_with),
						 key_fld, key_fld, parent_key_fld);
		serial_column = 0;
	}
	else
	{
		append_fstring(&sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s ORDER BY %s",
						 key_fld,
						 parent_key_fld,
						 relname,
						 parent_key_fld,
						 quote_literal_cstr(start_with),
						 key_fld, key_fld, parent_key_fld,
						 orderby_fld);
		serial_column = 1;
	}

	if (show_branch)
		values = (char **) palloc((CONNECTBY_NCOLS + serial_column) * sizeof(char *));
	else
		values = (char **) palloc((CONNECTBY_NCOLS_NOBRANCH + serial_column) * sizeof(char *));

	/* First time through, do a little setup */
	if (level == 0)
	{
		/* root value is the one we initially start with */
		values[0] = start_with;

		/* root value has no parent */
		values[1] = NULL;

		/* root level is 0 */
		sprintf(current_level, "%d", level);
		values[2] = current_level;

		/* root branch is just starting root value */
		if (show_branch)
			values[3] = start_with;

		/* root starts the serial with 1 */
		if (show_serial)
		{
			sprintf(serial_str, "%d", (*serial)++);
			if (show_branch)
				values[4] = serial_str;
			else
				values[3] = serial_str;
		}

		/* construct the tuple */
		tuple = build_tuple_from_cstrings(attinmeta, values);

		/* now store it */
		tts_put_tuple(tupstore, tuple);

		/* increment level */
		level++;
	}

	/* Retrieve the desired rows */
	ret = SPI_execute(sql.data, true, 0);
	proc = SPI_processed;

	/* Check for qualifying tuples */
	if ((ret == SPI_OK_SELECT) && (proc > 0))
	{
		struct heap_tuple *	spi_tuple;
		struct SPI_tuple_table *tuptable = SPI_tuptable;
		struct tuple *	spi_tupdesc = tuptable->tupdesc;
		int			i;
		struct string branchstr;
		struct string chk_branchstr;
		struct string chk_current_key;

		/* First time through, do a little more setup */
		if (level == 0)
		{
			/*
			 * Check that return tupdesc is compatible with the one we got
			 * from the query, but only at level 0 -- no need to check more
			 * than once
			 */

			if (!compatConnectbyTupleDescs(tupdesc, spi_tupdesc))
				ereport(ERROR,
						(errcode(E_SYNTAX_ERROR),
						 errmsg("invalid return type"),
						 errdetail("Return and SQL tuple descriptions are " \
								   "incompatible.")));
		}

		init_string(&branchstr);
		init_string(&chk_branchstr);
		init_string(&chk_current_key);

		for (i = 0; i < proc; i++)
		{
			/* initialize branch for this pass */
			append_fstring(&branchstr, "%s", branch);
			append_fstring(&chk_branchstr, "%s%s%s", branch_delim, branch, branch_delim);

			/* get the next sql result tuple */
			spi_tuple = tuptable->vals[i];

			/* get the current key and parent */
			current_key = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
			append_fstring(&chk_current_key, "%s%s%s", branch_delim, current_key, branch_delim);
			current_key_parent = pstrdup(SPI_getvalue(spi_tuple, spi_tupdesc, 2));

			/* get the current level */
			sprintf(current_level, "%d", level);

			/* check to see if this key is also an ancestor */
			if (strstr(chk_branchstr.data, chk_current_key.data))
				elog(ERROR, "infinite recursion detected");

			/* OK, extend the branch */
			append_fstring(&branchstr, "%s%s", branch_delim, current_key);
			current_branch = branchstr.data;

			/* build a tuple */
			values[0] = pstrdup(current_key);
			values[1] = current_key_parent;
			values[2] = current_level;
			if (show_branch)
				values[3] = current_branch;
			if (show_serial)
			{
				sprintf(serial_str, "%d", (*serial)++);
				if (show_branch)
					values[4] = serial_str;
				else
					values[3] = serial_str;
			}

			tuple = build_tuple_from_cstrings(attinmeta, values);

			xpfree(current_key);
			xpfree(current_key_parent);

			/* store the tuple for later use */
			tts_put_tuple(tupstore, tuple);

			heap_free_tuple(tuple);

			/* recurse using current_key_parent as the new start_with */
			tupstore = build_tuplestore_recursively(key_fld,
													parent_key_fld,
													relname,
													orderby_fld,
													branch_delim,
													values[0],
													current_branch,
													level + 1,
													serial,
													max_depth,
													show_branch,
													show_serial,
													per_query_ctx,
													attinmeta,
													tupstore);

			/* reset branch for next pass */
			reset_string(&branchstr);
			reset_string(&chk_branchstr);
			reset_string(&chk_current_key);
		}

		xpfree(branchstr.data);
		xpfree(chk_branchstr.data);
		xpfree(chk_current_key.data);
	}

	return tupstore;
}
示例#4
0
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
	(void) r0;
	(void) r1;
	(void) atags;
 
	uart_init();

	/** GPIO Register set */
	volatile unsigned int *gpio = led_init();

	/* Assign the address of the GPIO peripheral (Using ARM Physical Address) */
    //gpio = (unsigned int*)GPIO_BASE;

    /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO
       peripheral register to enable GPIO16 as an output */
    //gpio[LED_GPFSEL] |= (1 << LED_GPFBIT);

	(void) r0;
	(void) r1;
	(void) atags;
 
	uart_init();
	uart_puts("> Hello, World!\r\n");

	int str_len = 80;
	char stringin[str_len];
	int i=0;
	uart_puts("> ");

	int x = 0;
	int *calc = &x;

	while (true){
		//art_puts("hello");
		//led_blink(gpio, .25);
		char x = uart_getc();
		//Checks if current str is being written outside size allotment
		if (i > str_len-1){
			uart_puts(stringin);
			reset_string(stringin, i);
		
			uart_puts("Max string len reached\r\n");
			i = 0;
		}
		// if enter is pressed
		else if (x == '\r')
		{
			uart_puts("\r\n");

			if (memcmp(stringin, "calc", sizeof("calc")) == 0) {
				uart_puts("CALC RECOGNIZED!\r\n");
				calc_init();
				*calc = 1;
			}
			if (memcmp(stringin, "blink", sizeof("blink")) == 0) {
				uart_puts("LEDDDDDD!\r\n");
				led_blink(gpio, 1);
			}
			if (memcmp(stringin, "stop", sizeof("stop")) == 0) {
				uart_puts("LEDDDDDD STOP!\r\n");
				led_blink(gpio, 0);
			}
			else{
				uart_puts(stringin);
				uart_puts("\n");
				// char str[16];
				// int c = -146;
				// uart_puts(itos(c, str));
			}
			
			reset_string(stringin, i);
			uart_puts("> ");
			i = 0;
		}
		else if (x == 127 || x == 8) // backspace character
		{
			if (i>0)
			{
				uart_putc('\b'); // move cursor back
				uart_putc(' '); // insert space in terminal
				uart_putc('\b'); // move cursor back before space
				stringin[i-1] = 0x00; // replace last char with empty
				i--; // decrement length
			}
		}
		else{
			stringin[i] = x;
			uart_putc(stringin[i]);
			i++;
		}

	}

}
static void resetSendBuf(ikss_Stream *self)
{
  reset_string(self->send_buf);
  reset_string(self->send_more_buf);
  self->send_len = self->send_count = 0;
}
示例#6
0
文件: query.c 项目: SciLifeLab/facs
char *query (char *query, char *bloom_filter, double tole_rate, double sampling_rate, char *list, char *target_path, char *report_fmt, char mode)
{
  gzFile zip = NULL;
  char type = '@';
  int normal = 0;
  int threads = 0;
  BIGCAST offset = 0;
  char *position = NULL;
  static char timestamp[40] = {0};

  // Get current timestamp, for benchmarking purposes (begin of run timestamp)
  isodate(timestamp);
  bloom *bl_2 = NEW (bloom);
  F_set *File_head = make_list (bloom_filter, list);
  /*initialization for python interface*/
  File_head->hits = 0;
  File_head->all_k = 0;
  File_head->reads_num = 0;
  File_head->reads_contam = 0;
  File_head->filename = bloom_filter;           //extra initialization for python interface
  if (load_bloom (File_head->filename, bl_2)<=0)	//load a bloom filter
	exit(-1);
  
  if (tole_rate == 0)
  {
  	tole_rate = mco_suggestion (bl_2->k_mer); // suggest an optimal match cut-off
  }
  if (mode == 'r')
  {
 	init_string(ONEG); // initialize strings for containing reads
  }
/*
  if ((get_size (query) < 2 * ONEG) && !strstr (query, ".gz") && !strstr (query, ".tar"))
        normal = 0;
  else
  {
      if ((zip = gzopen (query, "rb")) < 0)
	{
          perror ("query open error...\n");
          exit (-1);
	}
      normal = 0;
  }
*/
  if ((zip = gzopen (query, "rb")) <= 0)
  {
  	fprintf(stderr, "%s\n", strerror(errno));
  	exit(EXIT_FAILURE);
  }
  
  if (strstr (query, ".fastq") != NULL || strstr (query, ".fq") != NULL)
  	type = '@';
  else
  	type = '>';
  if (normal == 0)
  	position = (char *) calloc (1,(ONEG+1)*sizeof (char));
  while (offset != -1)
  {
      if (normal == 1)
      {
	  position = mmaping (query);
	  offset = -1;
      }
      else
      {
	  offset = CHUNKer (zip, offset, ONEG, position, type);
      }
      Queue *head = NEW (Queue);
      head->location = NULL;
      Queue *tail = NEW (Queue);
      head->next = tail;
      Queue *head2 = head;
      get_parainfo (position, head, type);
#pragma omp parallel
      {
// XXX: Awesome will be the day when OpenMP is in OSX
#ifndef __APPLE__ 
          threads = omp_get_num_threads();
#endif
#pragma omp single nowait
	{
	  while (head != tail)
	    {
#pragma omp task firstprivate(head)
	      {
		if (head->location != NULL)
		{
			read_process (bl_2, head, tail, File_head, sampling_rate, tole_rate, mode, type);
		}
	      }
	      head = head->next;
	    }			// End of firstprivate
	}			// End of single - no implied barrier (nowait)
      }				// End of parallel region - implied barrier
  if (position != NULL && normal == 0)
  {
  	memset (position, 0, strlen (position));
  } 
  else if (normal == 1)
  {
	munmap (position, strlen (position));
  } 
  else
  {
 	perror ("Cannot memset, wrong position on fastq file\n");
	exit (-1);
  }
  clean_list (head2, tail);
  if (mode == 'r')
  {
	if (target_path!=NULL)
	{
      		save_result (query, File_head->filename, type, target_path, re_clean(), re_contam()); //save results into file if facs remove is called
  	}
	else
	{
		write_default(re_clean(), re_contam(), offset);
	}
	reset_string();
  }
  }				//end while
  if (normal == 0)
  {
 	bloom_destroy(bl_2);
  	gzclose(zip);
  	free (position);        //dont like file mapping, strings need to be freed in a normal way
  }

  /*
  mode c and r refer to contamination checking and removal function respectively. 
  The following 9 lines make sure that json/tsv output is printed after the checking 
  process, but willnot be written in stdout when running removal process.
  */
  if (target_path!=NULL || mode == 'c')
  {
  	return report(File_head, query, report_fmt, target_path, timestamp, prob_suggestion(bl_2->k_mer), threads);
  }
  else
  {
	char *s = "";
	return s;
  }
}