int token_get_string(struct finsh_token* self, u_char* str)
{
	unsigned char *p=str;
	char ch;

	ch = token_next_char(self);
	if (is_eof(self)) return -1;

	str[0] = '\0';

	if ( is_digit(ch) )/*the first character of identifier is not a digit.*/
	{
		token_prev_char(self);
		return -1;
	}

	while (!is_separator(ch) && !is_eof(self))
	{
		*p++ = ch;

		ch = token_next_char(self);
	}
	self->eof = 0;

	token_prev_char(self);
	*p = '\0';

	return 0;
}
Beispiel #2
0
static void
skip_spaces (scanner_t *scanner)
{
start:
	while (!is_eof (scanner) && isspace (CUR_CHAR)) {
		if (CUR_CHAR == '\n')
			++scanner->line;
		++scanner->idx;
	}
	if (CUR_CHAR == '#') {
		while (!is_eof (scanner) && CUR_CHAR != '\n') {
			++scanner->idx;
		}
		goto start;
	}
}
Beispiel #3
0
void print(Value x)
{
	if (is_nil(x))
		prints("nil");
	else if (is_eof(x))
		printf("#eof");
	else if (is_fixnum(x))
		printf("%d", as_fixnum(x));
	else if (is_bool(x))
		printf("%s", as_bool(x) ? "true" : "false");
	else if (is_char(x))
		printf("'%c'", as_char(x));
	else if (is_pair(x))
		print_list(x);
	else if (is_symbol(x))
		prints(as_symbol(x)->value);
	else if (is_string(x))
		print_string(as_string(x));
	else if (is_procedure(x))
		printf("#<procedure %s>", as_procedure(x)->name->value);
	else if (is_module(x))
		printf("#<module>");
	else if (is_type(x))
		printf("#<type %s>", as_type(x)->name->value);
	else if (is_ptr(x))
		printf("#<object %p>", as_ptr(x));
	else if (is_undefined(x))
		printf("#undefined");
	else
		printf("#ufo");
}
Beispiel #4
0
// Look at the next unused character in our source, without consuming it
static char look(lexer_t* lexer)
{
  if(is_eof(lexer))
    return '\0';

  return lexer->source->m[lexer->ptr];
}
Beispiel #5
0
// Process a triple quoted string, the leading """ of which has been seen, but
// not consumed
static token_t* triple_string(lexer_t* lexer)
{
  consume_chars(lexer, 3);  // Leading """

  while(true)
  {
    if(is_eof(lexer))
      return literal_doesnt_terminate(lexer);

    char c = look(lexer);

    if((c == '\"') && (lookn(lexer, 2) == '\"') && (lookn(lexer, 3) == '\"'))
    {
      consume_chars(lexer, 3);

      // Triple strings can end with 3 or more "s. If there are more than 3
      // the extra ones are part of the string contents
      while(look(lexer) == '\"')
      {
        append_to_token(lexer, '\"');
        consume_chars(lexer, 1);
      }

      normalise_string(lexer);
      return make_token_with_text(lexer, TK_STRING);
    }

    consume_chars(lexer, 1);
    append_to_token(lexer, c);
  }
}
Beispiel #6
0
		virtual const uint8_t pop_byte() {
			if( is_eof() ){
				return false;
			};

			return *m_pos++;
		};
Beispiel #7
0
int readLine(FILE* file, char** outStr)
{
	char buf[BUFSIZ];
	int i = 0;
	buf[i] = fgetc(file);
	if (is_eof(buf[i])) {
		return -1;
	}
	while (!is_eof(buf[i]) && !is_newline(buf[i])) {
		i++;
		buf[i] = fgetc(file);
	}
	buf[i] = '\0';
	COPY_STR((*outStr), buf);
	return i;
}
static u_char* token_proc_string(struct finsh_token* self)
{
	u_char* p;

	for ( p = &self->string[0]; p - &(self->string[0]) < FINSH_STRING_MAX; )
	{
		char ch = token_next_char(self);

		if ( is_eof(self) )
		{
			finsh_error_set(FINSH_ERROR_UNEXPECT_END);
			return NULL;;
		}
		if ( ch == '\\' )
		{
			ch = token_proc_escape(self);
		}
		else if ( ch == '"' )/*end of string.*/
		{
			*p = '\0';
			return self->string;
		}

		*p++ = ch;
	}

	return NULL;
}
Beispiel #9
0
static void
next_token (scanner_t *scanner)
{
	int start, end, type;
	char c;
	skip_spaces (scanner);
	start = scanner->idx;
	while (!is_eof (scanner) && !isspace (CUR_CHAR)) {
		if (scanner->idx == start) {
			if (is_special_char (CUR_CHAR)) {
				++scanner->idx;
				break;
			}
		} else if (is_special_char (CUR_CHAR))
			break;
		++scanner->idx;
	}
	end = scanner->idx;

	c = scanner->input [start];
	if (start >= scanner->size)
		type = TOKEN_EOF;
	else if (isdigit (c) || c == '\'')
		type = TOKEN_NUM;
	else if (ispunct_char (c))
		type = TOKEN_PUNC;
	else
		type = TOKEN_ID;
	scanner->current.start = start;
	scanner->current.end = end;
	scanner->current.type = type;
	scanner->current.line = scanner->line;

	DEBUG_SCANNER (dump_token (scanner, &scanner->current));
}
Beispiel #10
0
// Parse inlines from parent's string_content, adding as children of parent.
extern void cmark_parse_inlines(cmark_node* parent, cmark_reference_map *refmap, int options)
{
	subject subj;
	subject_from_buf(&subj, &parent->string_content, refmap);

	while (!is_eof(&subj) && parse_inline(&subj, parent, options)) ;

	process_emphasis(&subj, NULL);
}
std::streamsize download_source::read(char* s, std::streamsize n) {
   dgd_scopef(trace_download);

   dgd_echo(m_url);
   dgd_echo(n);

   if( m_mcurl == NULL ) {
      initialize();
   } 

   std::streamsize total_bytes = 0;
   std::streamsize bytes_to_read = 0;

   int handles_changed = 0;

   curl_multi_perform(m_mcurl, &handles_changed);
   dgd_echo(handles_changed);

   do {
      bytes_to_read = std::min(m_tail-m_head, n - total_bytes);
      dgd_echo(bytes_to_read);

      if( bytes_to_read > 0 ) {
         std::copy(m_head, m_head + bytes_to_read, s + total_bytes);
         m_head += bytes_to_read;
         if( m_tail == m_head ) {
            curl_easy_pause(m_curl, CURLPAUSE_CONT);
            dgd_logger << "resume curl" << std::endl;
         }
         total_bytes += bytes_to_read;
         dgd_echo(total_bytes);

         m_total_bytes += bytes_to_read;
         if(report_progress() != 0) {
            m_eof = true;
            dgd_logger << "download aborted" << std::endl;
            return -1;
         }
      } else if( is_eof() ) {         
         return ( total_bytes == 0 ) ? -1 : total_bytes;
      } else {
         handles_changed = 0;
         curl_multi_wait(m_mcurl, NULL, 0, 15000, &handles_changed);
         if( handles_changed == 0 ) 
         {
            m_eof = true;
            dgd_logger << "download timed out" << std::endl;
	    throw download_exception("Download timed out");
         }
      }

      curl_multi_perform(m_mcurl, &handles_changed);
   } while( total_bytes < n);
   
   return total_bytes;
}
        bool equal(fsq_iterator<Q, T_, P> const &x) const
        {
            if (is_eof())
                return x.is_eof();
            if (x.is_eof())
                return false;

            position_type const &rhs_pos = x.get_position();
            return (p.self == rhs_pos.self) && (p.pos == rhs_pos.pos);
        }
Beispiel #13
0
// Process a line comment the leading // for which has been seen, but not
// consumed
static token_t* line_comment(lexer_t* lexer)
{
  consume_chars(lexer, 2); // Leading //

  // We don't consume the terminating newline here, but it will be handled next
  // as whitespace
  while(!is_eof(lexer) && (look(lexer) != '\n'))
    consume_chars(lexer, 1);

  return NULL;
}
Beispiel #14
0
static CMARK_INLINE bool skip_line_end(subject *subj) {
  bool seen_line_end_char = false;
  if (peek_char(subj) == '\r') {
    advance(subj);
    seen_line_end_char = true;
  }
  if (peek_char(subj) == '\n') {
    advance(subj);
    seen_line_end_char = true;
  }
  return seen_line_end_char || is_eof(subj);
}
Beispiel #15
0
int main(int argc, char *argv[])
{
  char *cases[] = {
    /* "(+. 1.1 1.2)", */
    /* "(integer->float 123)", */
    /* "(& 5 7)", */
    /* "'hello", */
    /* "-", */
    /* "(define a (string->in-port \"abc\"))", */
    /* "(read-string-in-port-char a)", */
    /* "(+i 1 2)", */
    /* "(*i 3 4)", */
    /* "(quotient 10 3)", */
    /* "(remainder 10 3)", */
    /* "(= 1 2)", */
    /* "(> 4 5)", */
    /* "(& 5 7)", */
    /* "(| 5 7)", */
    /* "(~ 5)", */
    /* "(eq? 'hello 'hello)", */
    /* "(eq? 1 1)", */
    /* "(eq? (string->symbol \"hello\") 'hello)", */
    /* "(type-of 'hello)", */
    /* "type-of", */
    /* "#\\a", */
    /* "(type-of #\\a)", */
    /* "(define a #(1 2 3))", */
    /* "#\\汉", */
    /* "(set! a 123)", */
    "(string-ref \"汉字\" 0)",
  };
  init_impl();
  /* printf("Address of `-': %p\n", &primitive_procs[1]); */
  for (int i = 0; i < sizeof(cases) / sizeof(char *); i++) {
    FILE *stream = fmemopen(cases[i], strlen(cases[i]), "r");
    sexp in_port = make_file_in_port(stream);
    /* inc_ref_count(in_port); */
    printf(">> %s\n=> ", cases[i]);
    sexp value = read_object(in_port);
    if (is_eof(value))
      break;
    /* inc_ref_count(input); */
    value = eval_object(value, repl_environment);
    /* if (!is_self_eval(input)) */
    /*   inc_ref_count(value); */
    write_object(value, scm_out_port);
    putchar('\n');
  }
  /* write_object(make_wstring("汉"), scm_out_port); */
  /* trigger_gc(); */
  return 0;
}
Beispiel #16
0
void FastaReader::readNext() {
	if(!is_opened()) {
		//throw GenericException("File is not opened");
	}

	if(is_eof()) {
		//throw GenericException("End of file reached");
	}

	if (kseq_read(seq) < 0) {
		is_eof_ = true;
	}
}
Beispiel #17
0
// Parse backslash-escape or just a backslash, returning an inline.
static cmark_node *handle_backslash(subject *subj) {
  advance(subj);
  unsigned char nextchar = peek_char(subj);
  if (cmark_ispunct(
          nextchar)) { // only ascii symbols and newline can be escaped
    advance(subj);
    return make_str(subj->mem, cmark_chunk_dup(&subj->input, subj->pos - 1, 1));
  } else if (!is_eof(subj) && skip_line_end(subj)) {
    return make_linebreak(subj->mem);
  } else {
    return make_str(subj->mem, cmark_chunk_literal("\\"));
  }
}
Beispiel #18
0
		virtual const uint32_t pop_bits( const size_t amount ){
			if( ( 32 < amount ) || is_eof() ){
				return 0;
			};

			if( m_sv_size < amount ){
				m_sv_data = ( m_sv_data << 8 ) | *m_pos++;
				m_sv_size += 8;
			};

			const size_t	offset	= m_sv_size - amount;
			const uint32_t	result	= m_sv_data >> offset;
			
			m_sv_data &= ~( 0xFFFFFFFFL << offset );
			m_sv_size -= amount;

			return result;
		};
Beispiel #19
0
// Parse inlines from parent's string_content, adding as children of parent.
extern void cmark_parse_inlines(cmark_mem *mem, cmark_node *parent,
                                cmark_reference_map *refmap, int options) {
  subject subj;
  subject_from_buf(mem, &subj, &parent->content, refmap);
  cmark_chunk_rtrim(&subj.input);

  while (!is_eof(&subj) && parse_inline(&subj, parent, options))
    ;

  process_emphasis(&subj, NULL);
  // free bracket and delim stack
  while (subj.last_delim) {
    remove_delimiter(&subj, subj.last_delim);
  }
  while (subj.last_bracket) {
    pop_bracket(&subj);
  }
}
Beispiel #20
0
/* handler for parser LINE_START state */
static
const CHAR*
line_start_state(
    struct parser *parser,
    const CHAR *pos)
{
    const CHAR *p;

    for (p = pos; !is_eof(parser, p); p++)
    {
        switch(*p)
        {
        case '\r':
            continue;

        case '\n':
            parser->line_pos++;
            close_current_line(parser);
            break;

        case ';':
            push_state(parser, LINE_START);
            set_state(parser, COMMENT);
            return p + 1;

        case '[':
            parser->start = p + 1;
            set_state(parser, SECTION_NAME);
            return p + 1;

        default:
            if (!isspace((unsigned char)*p))
            {
                parser->start = p;
                set_state(parser, KEY_NAME);
                return p;
            }
            break;
        }
    }
    close_current_line(parser);
    return NULL;
}
Beispiel #21
0
/* handler for parser EOL_BACKSLASH state */
static
const CHAR*
eol_backslash_state(
    struct parser *parser,
    const CHAR *pos )
{
    const CHAR *p;

    for (p = pos; !is_eof(parser, p); p++)
    {
        switch(*p)
        {
        case '\r':
            continue;

        case '\n':
            parser->line_pos++;
            parser->start = p + 1;
            set_state(parser, LEADING_SPACES);
            return p + 1;

        case '\\':
            continue;

        case ';':
            push_state(parser, EOL_BACKSLASH);
            set_state(parser, COMMENT);
            return p + 1;

        default:
            if (isspace((unsigned char)*p))
                continue;
            push_token(parser, p);
            pop_state(parser);
            return p;
        }
    }
    parser->start = p;
    pop_state(parser);

    return p;
}
Beispiel #22
0
// Try to process a backtick code span that began with a
// span of ticks of length openticklength length (already
// parsed).  Return 0 if you don't find matching closing
// backticks, otherwise return the position in the subject
// after the closing backticks.
static int scan_to_closing_backticks(subject* subj, int openticklength)
{
	// read non backticks
	unsigned char c;
	while ((c = peek_char(subj)) && c != '`') {
		advance(subj);
	}
	if (is_eof(subj)) {
		return 0;  // did not find closing ticks, return 0
	}
	int numticks = 0;
	while (peek_char(subj) == '`') {
		advance(subj);
		numticks++;
	}
	if (numticks != openticklength) {
		return(scan_to_closing_backticks(subj, openticklength));
	}
	return (subj->pos);
}
Beispiel #23
0
// Try to process a backtick code span that began with a
// span of ticks of length openticklength length (already
// parsed).  Return 0 if you don't find matching closing
// backticks, otherwise return the position in the subject
// after the closing backticks.
static bufsize_t scan_to_closing_backticks(subject *subj,
                                           bufsize_t openticklength) {

  bool found = false;
  if (openticklength > MAXBACKTICKS) {
    // we limit backtick string length because of the array subj->backticks:
    return 0;
  }
  if (subj->scanned_for_backticks &&
      subj->backticks[openticklength] <= subj->pos) {
    // return if we already know there's no closer
    return 0;
  }
  while (!found) {
    // read non backticks
    unsigned char c;
    bufsize_t numticks = 0;
    while ((c = peek_char(subj)) && c != '`') {
      advance(subj);
    }
    if (is_eof(subj)) {
      break;
    }

    while (peek_char(subj) == '`') {
      advance(subj);
      numticks++;
    }
    // store position of ender
    if (numticks <= MAXBACKTICKS) {
      subj->backticks[numticks] = subj->pos - numticks;
    }
    if (numticks == openticklength) {
      return (subj->pos);
    }
  }
  // got through whole input without finding closer
  subj->scanned_for_backticks = true;
  return 0;
}
Beispiel #24
0
// Process a triple quoted string, the leading """ of which has been seen, but
// not consumed
static token_t* triple_string(lexer_t* lexer)
{
  consume_chars(lexer, 3);  // Leading """

  while(true)
  {
    if(is_eof(lexer))
      return literal_doesnt_terminate(lexer);

    char c = look(lexer);

    if((c == '\"') && (lookn(lexer, 2) == '\"') && (lookn(lexer, 3) == '\"'))
    {
      consume_chars(lexer, 3);
      normalise_string(lexer);
      return make_token_with_text(lexer, TK_STRING);
    }

    consume_chars(lexer, 1);
    append_to_token(lexer, c);
  }
}
Beispiel #25
0
/**
	Get all the entries in the directory
	@param fs FS_Instance to find all the information from
	@param directory To find all the entries for
	@return List of entries in the directory
**/
FS_EntryList* get_entries(FS_Instance *fs, uint32_t directory) {
	uint8_t root_directory = find_root_of_directory(fs, directory);
	uint32_t bytes_per_cluster = ((!root_directory) ? fs->BPB_SecPerClus : 1) * fs->BPB_BytsPerSec;
	uint32_t entries_per_cluster = bytes_per_cluster / sizeof(FatEntry);
	FatEntry *entries = malloc(entries_per_cluster * sizeof(FatEntry));
	
	if(NULL == entries) {
		return NULL;
	}
		
	uint16_t *long_name = NULL;
	FS_EntryList *list_head = NULL;
	FS_EntryList *list_tail = NULL;
	
	if(root_directory) {
		directory = fs->current_directory_position;
	}
		
	do {
		uint64_t seek = directory;
		
		if(!root_directory) {
			seek = get_first_sector(fs, directory);
		}
			
		fseek(fs->image, (seek * fs->BPB_BytsPerSec), SEEK_SET);
		fread(entries, sizeof(FatEntry), entries_per_cluster, fs->image);
		
		for(int i = 0; i < entries_per_cluster; i++) {
			FatEntry *entry = &(entries[i]);
			
			if(0x00 == entry->DIR_Name[0]) {
				break;
			}
				
			if(0xE5 == entry->DIR_Name[0]) {
				continue;
			}
				
			if(0x05 == entry->DIR_Name[0]) {
				entry->DIR_Name[0] = 0xE5;
			}
				
			if(!check_mask(entry->DIR_Attr, ATTR_LONG_NAME)) {
				uint8_t valid = 1;
				for (int j = 0; j < DIR_Name_LENGTH; j++) {
					if (0x20 > entry->DIR_Name[j]) {
						valid = 0;
					}
				}
					
				if(!valid) {
					continue;
				}
					
				FS_EntryList *listEntry = malloc(sizeof(FS_EntryList));
				listEntry->node = malloc(sizeof(FS_Entry));
				listEntry->node->entry = malloc(sizeof(FatEntry));
				memcpy(listEntry->node->entry, entry, sizeof(FatEntry));
				listEntry->node->file_name = long_name;
				long_name = NULL;
				listEntry->next = NULL;
				
				if(NULL != list_tail) {
					list_tail->next = listEntry;
				}
					
				list_tail = listEntry;
				
				if(NULL == list_head) {
					list_head = listEntry;
				}
			}
		}
		if(!root_directory) {
			directory = find_first_entry(fs, directory);
		} else {
			directory++;
		}
	} while(root_directory ? (directory < (fs->current_directory_position + fs->root_sectors)) : !is_eof(fs, directory));
	free(entries);
	return list_head;
}
Beispiel #26
0
sysdig_table_action sinsp_cursesui::handle_input(int ch)
{
	//
	// Avoid parsing keys during file load
	//
	if((!m_inspector->is_live()) && !is_eof())
	{
		if(ch != KEY_BACKSPACE &&
			ch != 127 &&
			ch != 'q' &&
			ch != KEY_F(10))
		{
			return STA_NONE;
		}
	}

	if(m_mainhelp_page != NULL)
	{
		sysdig_table_action actn = m_mainhelp_page->handle_input(ch);

		if(actn == STA_DESTROY_CHILD)
		{
			delete m_mainhelp_page;
			m_mainhelp_page = NULL;

			if(m_spy_box)
			{
				m_spy_box->render();
			}

			if(m_viz != NULL)
			{
				m_viz->render(true);
			}

			if(m_viewinfo_page)
			{
				m_viewinfo_page->render();
			}

			render();
			return STA_NONE;
		}
		else if(actn != STA_PARENT_HANDLE)
		{
			return actn;			
		}
	}

	if(m_sidemenu)
	{
		sysdig_table_action ta = m_sidemenu->handle_input(ch);
		if(ta == STA_SWITCH_VIEW)
		{
			if(m_viewinfo_page)
			{
				delete m_viewinfo_page;
				m_viewinfo_page = NULL;
			}

			return ta;
		}
		else if(ta != STA_PARENT_HANDLE)
		{
			return STA_NONE;
		}
	}

	if(m_output_filtering || m_output_searching || m_search_caller_interface != NULL)
	{
		ASSERT(m_sidemenu == NULL);
		return handle_textbox_input(ch);
	}

	if(m_spy_box != NULL)
	{
		ASSERT(m_sidemenu == NULL);
		ASSERT(m_output_filtering == false);
		ASSERT(m_output_searching == false);
		sysdig_table_action actn = m_spy_box->handle_input(ch);

		if(actn != STA_PARENT_HANDLE)
		{
			return actn;
		}
	}

	//
	// Note: the info page doesn't handle input when the sidemenu is on, because in that
	//       case it's just going to passively show the info for the selected view
	//
	if(m_viewinfo_page && m_sidemenu == NULL)
	{
		sysdig_table_action actn = m_viewinfo_page->handle_input(ch);

		if(actn == STA_DESTROY_CHILD)
		{
			delete m_viewinfo_page;
			m_viewinfo_page = NULL;
			if(m_viz != NULL)
			{
				m_viz->render(true);
			}

			render();
			return STA_NONE;
		}

		return actn;
	}

	//
	// Pass the event to the table viz
	//
	if(m_viz)
	{
		sysdig_table_action actn = m_viz->handle_input(ch);
		if(actn != STA_PARENT_HANDLE)
		{
			return actn;
		}
	}

	switch(ch)
	{
		case '?':
		case 'h':
		case KEY_F(1):
			m_mainhelp_page = new curses_mainhelp_page(this);
			break;
		case KEY_F(10):
		case 'q':
			return STA_QUIT;
		case 'p':
			pause();
			break;
		case KEY_F(2):
			if(m_sidemenu == NULL)
			{
				m_viz->set_x_start(SIDEMENU_WIDTH);
				m_sidemenu = new curses_table_sidemenu(this);
				m_sidemenu->set_entries(&m_sidemenu_viewlist);
				m_sidemenu->m_selct = m_selected_sidemenu_entry;
				m_sidemenu->set_title("Select View");

				render();

				m_viewinfo_page = new curses_viewinfo_page(this, 
					m_selected_view,
					TABLE_Y_START,
					SIDEMENU_WIDTH,
					m_screenh - TABLE_Y_START - 1,
					m_screenw - SIDEMENU_WIDTH);
			}
			else
			{
				if(m_viewinfo_page)
				{
					delete m_viewinfo_page;
					m_viewinfo_page = NULL;
				}

				m_viz->set_x_start(0);
				delete m_sidemenu;
				m_sidemenu = NULL;
				m_viz->recreate_win(m_screenh - 3);
				render();
			}

			break;
		case '/':
		case 6:	// CTRL+F
			m_search_caller_interface = NULL;
			m_output_searching = true;
			//m_manual_search_text = "";
			m_cursor_pos = 0;
			curs_set(1);
			render();
			break;
		//case KEY_F(3):
		//	break;
		case '\\':
		case KEY_F(4):
			m_search_caller_interface = NULL;
			m_output_filtering = true;
			m_cursor_pos = 0;
			curs_set(1);
			render();
			break;
		case KEY_F(5):
		case 'e':
			if(m_datatable == NULL)
			{
				//
				// No F5 for non table displays
				//
				return STA_NONE;
			}
			else if(m_datatable->m_type == sinsp_table::TT_LIST)
			{
				//
				// No F5 for list tables
				//
				return STA_NONE;
			}

			if(m_datatable->m_sample_data != NULL && m_datatable->m_sample_data->size() != 0)
			{
				m_selected_sidemenu_entry = 0;
				return STA_SPY;
			}
			break;
		case KEY_F(6):
		case 'd':
			if(m_datatable == NULL)
			{
				//
				// No F5 for non table displays
				//
				return STA_NONE;
			}
			else if(m_datatable->m_type == sinsp_table::TT_LIST)
			{
				//
				// No F5 for list tables
				//
				return STA_NONE;
			}

			if(m_datatable->m_sample_data != NULL && m_datatable->m_sample_data->size() != 0)
			{
				m_selected_sidemenu_entry = 0;
				return STA_DIG;
			}

			break;
		case KEY_F(7):
			m_viewinfo_page = new curses_viewinfo_page(this,
				m_selected_view,
				0,
				0,
				m_screenh,
				m_screenw);
			break;
		case KEY_RESIZE:
			getmaxyx(stdscr, m_screenh, m_screenw);
			
			render();

			if(m_spy_box)
			{
				m_spy_box->render();
				m_spy_box->render();
			}

			if(m_viz != NULL)
			{
				m_viz->recreate_win(m_screenh - 3);
				m_viz->render(true);
				m_viz->render(true);
			}

			if(m_viewinfo_page)
			{
				m_viewinfo_page->render();
				m_viewinfo_page->render();
			}

			render();

			break;
		case KEY_MOUSE:
			{
				MEVENT* event = NULL;

				if(m_sidemenu != NULL)
				{
					event = &m_sidemenu->m_last_mevent;
				}
				else if(m_spy_box != NULL)
				{
					event = &m_spy_box->m_last_mevent;
				}
				else if(m_viz != NULL)
				{
					event = &m_viz->m_last_mevent;
				}

				if(event == NULL)
				{
					ASSERT(false);
					break;
				}

				if(event->bstate & BUTTON1_CLICKED ||
					event->bstate & BUTTON1_DOUBLE_CLICKED)
				{
					if((uint32_t)event->y == m_screenh - 1)
					{
						int keyc = m_mouse_to_key_list.get_key_from_coordinates(event->x, event->y);
						if(keyc != -1)
						{
							return handle_input(keyc);
						}
					}
					else if((uint32_t)event->y == 1 &&
						(uint32_t)event->x >= m_filterstring_start_x &&
						(uint32_t)event->x <= m_filterstring_end_x)
					{
						m_search_caller_interface = NULL;
						m_is_filter_sysdig = true;
						m_output_filtering = true;
						m_manual_filter = m_complete_filter;
						m_cursor_pos = 0;
						curs_set(1);
						render();
					}
				}
			}

			break;
		default:
			break;
	}

	return STA_NONE;
}
Beispiel #27
0
int do_it(const char * project_name) {
/* Main entry point. It is assumed that log_level_limit 
   and GUI_mode are already set. */

  int err, first, iseof;
  FILE *fp;

  if(ps_project_name(project_name, &fp)!=NO_ERROR) return(ERROR);

  first=YES;
  err = NO_ERROR;
  linenum=0;
  for(;;) {
    log_level=0;
    iseof=is_eof(fp);
    if(iseof==YES) {
      if( first!=YES ) break;
      else {
        print_derr("Empty parameter file?");
        fclose(fp);
	goto WLe_do_it;
      }
    }
    /* so there is something to read */
    err = get_next_line(name, NAME_LEN_LIMIT, fp);
    if( err!=NO_ERROR ) {
      fclose(fp);
      goto WLe_do_it;
    }
    first=NO;
    if(strcmp(name, "\\begin_command")!= 0) {
      print_derr("Missing \\begin_command.");
      hlp_par_format();
      fclose(fp);
      err = ERROR;
      goto WLe_do_it;
    }
    err = rd_pars(fp);
    if(err != NO_ERROR ) {
      fclose(fp);
      goto WLe_do_it;
    }
    if( get_next_line(name, NAME_LEN_LIMIT, fp) != NO_ERROR) {
      fclose(fp);
      err = ERROR;
      goto WLe_do_it;
    }
    if(strcmp(name, "\\end_command")!= 0) {
      print_derr("Missing \\end_command.");
      hlp_par_format();
      fclose(fp);
      err = ERROR;
      goto WLe_do_it;
    }
  }
  fclose(fp);
WLe_do_it:

  fprintf( log_file_p, "\n" );
  fflush( log_file_p );
  fprintf( results_file_p, "\n" );
  fflush( results_file_p );
  if( err == INTERRUPT ) {
      print_derr("Calculation interrupted.\n");
      return(err);
  }
  if( err == NO_ERROR ) {
      print_spdo("Calculation terminated succesfully.\n");
      return(err);
  }
  print_derr("Calculation terminated on error.\n");
  return(err);

}
memcache_item* file_reader::read_item(void)
{
    // parse next line
    unsigned int s_dumpflags = 0;
    unsigned int s_time = 0;
    unsigned int s_exptime = 0;
    unsigned int s_nbytes = 0;
    unsigned int s_nsuffix = 0;
    unsigned int s_flags = 0;
    unsigned int s_clsid = 0;
    unsigned int s_nkey = 0;

    // scan int values
    if (fscanf(m_file, "%u, %u, %u, %u, %u, %u, %u, %u, ",
        &s_dumpflags,
        &s_time,
        &s_exptime,
        &s_nbytes,
        &s_nsuffix,
        &s_flags,
        &s_clsid,
        &s_nkey) < 8) {

        if (is_eof())
            return NULL;
        
        fprintf(stderr, "%s:%u: error parsing item values.\n",
            m_filename, m_line);
        return NULL;
    }

    // read key
    unsigned int key_actlen = 0;
    char *key = read_string(s_nkey, s_nkey + 1, &key_actlen);
    if (key_actlen != s_nkey) {
        fprintf(stderr, "%s:%u: warning: key column is %u bytes, expected %u bytes.\n",
            m_filename, m_line, key_actlen, s_nkey);
    }
    key[s_nkey] = '\0';
    
    // read data
    int c = fgetc(m_file);
    if (c != ',') {
        fprintf(stderr, "%s:%u: error parsing csv file, got '%c' instead of delmiter.\n", 
            m_filename, m_line, c);
        free(key);
        return NULL;
    }
    fgetc(m_file);
    
    unsigned int data_actlen = 0;
    char *data = read_string(s_nbytes - 2, s_nbytes, &data_actlen);
    if (data_actlen != s_nbytes - 2) {
        fprintf(stderr, "%s:%u: warning: data column is %u bytes, expected %u bytes.\n",
            m_filename, m_line, data_actlen, s_nbytes);
        free(key);
        free(data);
        return NULL;
    }
    data[s_nbytes - 2] = '\r';
    data[s_nbytes - 1] = '\n';

    // handle end of line
    c = fgetc(m_file);
    if (c == '\r') {
        c = fgetc(m_file);
    }
    if (c != '\n') {
        fprintf(stderr, "%s:%u: warning: end of line expected but not found.\n",
            m_filename, m_line);
    }

    m_line++;

    // return item
    memcache_item *item = new memcache_item(s_dumpflags, 
        s_time, s_exptime, s_flags, s_nsuffix, s_clsid);
    item->set_key(key, s_nkey);
    item->set_data(data, s_nbytes);
    
    return item;
}
Beispiel #29
0
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  grpc_test_only_set_metadata_hash_seed(0);
  if (squelch) gpr_set_log_function(dont_log);
  input_stream inp = {data, data + size};
  grpc_resolve_address = my_resolve_address;
  grpc_tcp_client_connect_impl = my_tcp_client_connect;
  gpr_now_impl = now_impl;
  grpc_init();

  GPR_ASSERT(g_channel == NULL);
  GPR_ASSERT(g_server == NULL);

  bool server_shutdown = false;
  int pending_server_shutdowns = 0;
  int pending_channel_watches = 0;
  int pending_pings = 0;

  g_active_call = new_call(NULL, ROOT);

  grpc_completion_queue *cq = grpc_completion_queue_create(NULL);

  while (!is_eof(&inp) || g_channel != NULL || g_server != NULL ||
         pending_channel_watches > 0 || pending_pings > 0 ||
         g_active_call->type != ROOT || g_active_call->next != g_active_call) {
    if (is_eof(&inp)) {
      if (g_channel != NULL) {
        grpc_channel_destroy(g_channel);
        g_channel = NULL;
      }
      if (g_server != NULL) {
        if (!server_shutdown) {
          grpc_server_shutdown_and_notify(
              g_server, cq, create_validator(assert_success_and_decrement,
                                             &pending_server_shutdowns));
          server_shutdown = true;
          pending_server_shutdowns++;
        } else if (pending_server_shutdowns == 0) {
          grpc_server_destroy(g_server);
          g_server = NULL;
        }
      }
      call_state *s = g_active_call;
      do {
        if (s->type != PENDING_SERVER && s->call != NULL) {
          s = destroy_call(s);
        } else {
          s = s->next;
        }
      } while (s != g_active_call);

      g_now = gpr_time_add(g_now, gpr_time_from_seconds(1, GPR_TIMESPAN));
    }

    switch (next_byte(&inp)) {
      // terminate on bad bytes
      default:
        end(&inp);
        break;
      // tickle completion queue
      case 0: {
        grpc_event ev = grpc_completion_queue_next(
            cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL);
        switch (ev.type) {
          case GRPC_OP_COMPLETE: {
            validator *v = ev.tag;
            v->validate(v->arg, ev.success);
            gpr_free(v);
            break;
          }
          case GRPC_QUEUE_TIMEOUT:
            break;
          case GRPC_QUEUE_SHUTDOWN:
            abort();
            break;
        }
        break;
      }
      // increment global time
      case 1: {
        g_now = gpr_time_add(
            g_now, gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN));
        break;
      }
      // create an insecure channel
      case 2: {
        if (g_channel == NULL) {
          char *target = read_string(&inp);
          char *target_uri;
          gpr_asprintf(&target_uri, "dns:%s", target);
          grpc_channel_args *args = read_args(&inp);
          g_channel = grpc_insecure_channel_create(target_uri, args, NULL);
          GPR_ASSERT(g_channel != NULL);
          grpc_channel_args_destroy(args);
          gpr_free(target_uri);
          gpr_free(target);
        } else {
          end(&inp);
        }
        break;
      }
      // destroy a channel
      case 3: {
        if (g_channel != NULL) {
          grpc_channel_destroy(g_channel);
          g_channel = NULL;
        } else {
          end(&inp);
        }
        break;
      }
      // bring up a server
      case 4: {
        if (g_server == NULL) {
          grpc_channel_args *args = read_args(&inp);
          g_server = grpc_server_create(args, NULL);
          GPR_ASSERT(g_server != NULL);
          grpc_channel_args_destroy(args);
          grpc_server_register_completion_queue(g_server, cq, NULL);
          grpc_server_start(g_server);
          server_shutdown = false;
          GPR_ASSERT(pending_server_shutdowns == 0);
        } else {
          end(&inp);
        }
      }
      // begin server shutdown
      case 5: {
        if (g_server != NULL) {
          grpc_server_shutdown_and_notify(
              g_server, cq, create_validator(assert_success_and_decrement,
                                             &pending_server_shutdowns));
          pending_server_shutdowns++;
          server_shutdown = true;
        } else {
          end(&inp);
        }
        break;
      }
      // cancel all calls if shutdown
      case 6: {
        if (g_server != NULL && server_shutdown) {
          grpc_server_cancel_all_calls(g_server);
        } else {
          end(&inp);
        }
        break;
      }
      // destroy server
      case 7: {
        if (g_server != NULL && server_shutdown &&
            pending_server_shutdowns == 0) {
          grpc_server_destroy(g_server);
          g_server = NULL;
        } else {
          end(&inp);
        }
        break;
      }
      // check connectivity
      case 8: {
        if (g_channel != NULL) {
          uint8_t try_to_connect = next_byte(&inp);
          if (try_to_connect == 0 || try_to_connect == 1) {
            grpc_channel_check_connectivity_state(g_channel, try_to_connect);
          } else {
            end(&inp);
          }
        } else {
          end(&inp);
        }
        break;
      }
      // watch connectivity
      case 9: {
        if (g_channel != NULL) {
          grpc_connectivity_state st =
              grpc_channel_check_connectivity_state(g_channel, 0);
          if (st != GRPC_CHANNEL_FATAL_FAILURE) {
            gpr_timespec deadline = gpr_time_add(
                gpr_now(GPR_CLOCK_REALTIME),
                gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN));
            grpc_channel_watch_connectivity_state(
                g_channel, st, deadline, cq,
                create_validator(validate_connectivity_watch,
                                 make_connectivity_watch(
                                     deadline, &pending_channel_watches)));
            pending_channel_watches++;
          }
        } else {
          end(&inp);
        }
        break;
      }
      // create a call
      case 10: {
        bool ok = true;
        if (g_channel == NULL) ok = false;
        grpc_call *parent_call = NULL;
        if (g_active_call->type != ROOT) {
          if (g_active_call->call == NULL || g_active_call->type == CLIENT) {
            end(&inp);
            break;
          }
          parent_call = g_active_call->call;
        }
        uint32_t propagation_mask = read_uint32(&inp);
        char *method = read_string(&inp);
        char *host = read_string(&inp);
        gpr_timespec deadline =
            gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
                         gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN));

        if (ok) {
          call_state *cs = new_call(g_active_call, CLIENT);
          cs->call =
              grpc_channel_create_call(g_channel, parent_call, propagation_mask,
                                       cq, method, host, deadline, NULL);
        } else {
          end(&inp);
        }
        gpr_free(method);
        gpr_free(host);
        break;
      }
      // switch the 'current' call
      case 11: {
        g_active_call = g_active_call->next;
        break;
      }
      // queue some ops on a call
      case 12: {
        if (g_active_call->type == PENDING_SERVER ||
            g_active_call->type == ROOT || g_active_call->call == NULL) {
          end(&inp);
          break;
        }
        size_t num_ops = next_byte(&inp);
        if (num_ops > 6) {
          end(&inp);
          break;
        }
        grpc_op *ops = gpr_malloc(sizeof(grpc_op) * num_ops);
        bool ok = true;
        size_t i;
        grpc_op *op;
        for (i = 0; i < num_ops; i++) {
          op = &ops[i];
          switch (next_byte(&inp)) {
            default:
              /* invalid value */
              op->op = (grpc_op_type)-1;
              ok = false;
              break;
            case GRPC_OP_SEND_INITIAL_METADATA:
              op->op = GRPC_OP_SEND_INITIAL_METADATA;
              read_metadata(&inp, &op->data.send_initial_metadata.count,
                            &op->data.send_initial_metadata.metadata,
                            g_active_call);
              break;
            case GRPC_OP_SEND_MESSAGE:
              op->op = GRPC_OP_SEND_MESSAGE;
              op->data.send_message = read_message(&inp);
              break;
            case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
              op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
              break;
            case GRPC_OP_SEND_STATUS_FROM_SERVER:
              op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
              read_metadata(
                  &inp,
                  &op->data.send_status_from_server.trailing_metadata_count,
                  &op->data.send_status_from_server.trailing_metadata,
                  g_active_call);
              op->data.send_status_from_server.status = next_byte(&inp);
              op->data.send_status_from_server.status_details =
                  read_string(&inp);
              break;
            case GRPC_OP_RECV_INITIAL_METADATA:
              op->op = GRPC_OP_RECV_INITIAL_METADATA;
              op->data.recv_initial_metadata =
                  &g_active_call->recv_initial_metadata;
              break;
            case GRPC_OP_RECV_MESSAGE:
              op->op = GRPC_OP_RECV_MESSAGE;
              op->data.recv_message = &g_active_call->recv_message;
              break;
            case GRPC_OP_RECV_STATUS_ON_CLIENT:
              op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
              op->data.recv_status_on_client.status = &g_active_call->status;
              op->data.recv_status_on_client.trailing_metadata =
                  &g_active_call->recv_trailing_metadata;
              op->data.recv_status_on_client.status_details =
                  &g_active_call->recv_status_details;
              op->data.recv_status_on_client.status_details_capacity =
                  &g_active_call->recv_status_details_capacity;
              break;
            case GRPC_OP_RECV_CLOSE_ON_SERVER:
              op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
              op->data.recv_close_on_server.cancelled =
                  &g_active_call->cancelled;
              break;
          }
          op->reserved = NULL;
          op->flags = read_uint32(&inp);
        }
        if (ok) {
          validator *v = create_validator(finished_batch, g_active_call);
          g_active_call->pending_ops++;
          grpc_call_error error =
              grpc_call_start_batch(g_active_call->call, ops, num_ops, v, NULL);
          if (error != GRPC_CALL_OK) {
            v->validate(v->arg, false);
            gpr_free(v);
          }
        } else {
          end(&inp);
        }
        for (i = 0; i < num_ops; i++) {
          op = &ops[i];
          switch (op->op) {
            case GRPC_OP_SEND_INITIAL_METADATA:
              break;
            case GRPC_OP_SEND_MESSAGE:
              grpc_byte_buffer_destroy(op->data.send_message);
              break;
            case GRPC_OP_SEND_STATUS_FROM_SERVER:
              gpr_free((void *)op->data.send_status_from_server.status_details);
              break;
            case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
            case GRPC_OP_RECV_INITIAL_METADATA:
            case GRPC_OP_RECV_MESSAGE:
            case GRPC_OP_RECV_STATUS_ON_CLIENT:
            case GRPC_OP_RECV_CLOSE_ON_SERVER:
              break;
          }
        }
        gpr_free(ops);

        break;
      }
      // cancel current call
      case 13: {
        if (g_active_call->type != ROOT && g_active_call->call != NULL) {
          grpc_call_cancel(g_active_call->call, NULL);
        } else {
          end(&inp);
        }
        break;
      }
      // get a calls peer
      case 14: {
        if (g_active_call->type != ROOT && g_active_call->call != NULL) {
          free_non_null(grpc_call_get_peer(g_active_call->call));
        } else {
          end(&inp);
        }
        break;
      }
      // get a channels target
      case 15: {
        if (g_channel != NULL) {
          free_non_null(grpc_channel_get_target(g_channel));
        } else {
          end(&inp);
        }
        break;
      }
      // send a ping on a channel
      case 16: {
        if (g_channel != NULL) {
          pending_pings++;
          grpc_channel_ping(g_channel, cq,
                            create_validator(decrement, &pending_pings), NULL);
        } else {
          end(&inp);
        }
        break;
      }
      // enable a tracer
      case 17: {
        char *tracer = read_string(&inp);
        grpc_tracer_set_enabled(tracer, 1);
        gpr_free(tracer);
        break;
      }
      // disable a tracer
      case 18: {
        char *tracer = read_string(&inp);
        grpc_tracer_set_enabled(tracer, 0);
        gpr_free(tracer);
        break;
      }
      // request a server call
      case 19: {
        if (g_server == NULL) {
          end(&inp);
          break;
        }
        call_state *cs = new_call(g_active_call, PENDING_SERVER);
        cs->pending_ops++;
        validator *v = create_validator(finished_request_call, cs);
        grpc_call_error error =
            grpc_server_request_call(g_server, &cs->call, &cs->call_details,
                                     &cs->recv_initial_metadata, cq, cq, v);
        if (error != GRPC_CALL_OK) {
          v->validate(v->arg, false);
          gpr_free(v);
        }
        break;
      }
      // destroy a call
      case 20: {
        if (g_active_call->type != ROOT &&
            g_active_call->type != PENDING_SERVER &&
            g_active_call->call != NULL) {
          destroy_call(g_active_call);
        } else {
          end(&inp);
        }
        break;
      }
    }
  }

  GPR_ASSERT(g_channel == NULL);
  GPR_ASSERT(g_server == NULL);
  GPR_ASSERT(g_active_call->type == ROOT);
  GPR_ASSERT(g_active_call->next == g_active_call);
  gpr_free(g_active_call);

  grpc_completion_queue_shutdown(cq);
  GPR_ASSERT(
      grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL)
          .type == GRPC_QUEUE_SHUTDOWN);
  grpc_completion_queue_destroy(cq);

  grpc_shutdown();
  return 0;
}
Beispiel #30
0
static void token_run(struct finsh_token* self)
{
	char ch;

	token_trim_space(self); /* first trim space and tab. */
	token_get_string(self, &(self->string[0]));

	if ( is_eof(self) ) { /*if it is eof, break;*/
		self->current_token = finsh_token_type_eof;
		return ;
	}

	if (self->string[0] != '\0') { /*It is a key word or a identifier.*/
		if ( !token_match_name(self, (char*)self->string) ) {
			self->current_token = finsh_token_type_identifier;
		}
		return;
	} else { /*It is a operator character.*/
		ch = token_next_char(self);

		switch ( ch ) {
		case '(':
			self->current_token = finsh_token_type_left_paren;
			break;

		case ')':
			self->current_token = finsh_token_type_right_paren;
			break;

		case ',':
			self->current_token = finsh_token_type_comma;
			break;

		case ';':
			self->current_token = finsh_token_type_semicolon;
			break;

		case '&':
			self->current_token = finsh_token_type_and;
			break;

		case '*':
			self->current_token = finsh_token_type_mul;
			break;

		case '+':
			ch = token_next_char(self);

			if ( ch == '+' ) {
				self->current_token = finsh_token_type_inc;
			} else {
				token_prev_char(self);
				self->current_token = finsh_token_type_add;
			}
			break;

		case '-':
			ch = token_next_char(self);

			if ( ch == '-' ) {
				self->current_token = finsh_token_type_dec;
			} else {
				token_prev_char(self);
				self->current_token = finsh_token_type_sub;
			}
			break;

		case '/':
			ch = token_next_char(self);
			if (ch == '/') {
				/* line comments, set to end of file */
				self->current_token = finsh_token_type_eof;
			} else {
				token_prev_char(self);
				self->current_token = finsh_token_type_div;
			}
			break;

		case '<':
			ch = token_next_char(self);

			if ( ch == '<' ) {
				self->current_token = finsh_token_type_shl;
			} else {
				token_prev_char(self);
				self->current_token = finsh_token_type_bad;
			}
			break;

		case '>':
			ch = token_next_char(self);

			if ( ch == '>' ) {
				self->current_token = finsh_token_type_shr;
			} else {
				token_prev_char(self);
				self->current_token = finsh_token_type_bad;
			}
			break;

		case '|':
			self->current_token = finsh_token_type_or;
			break;

		case '%':
			self->current_token = finsh_token_type_mod;
			break;

		case '~':
			self->current_token = finsh_token_type_bitwise;
			break;

		case '^':
			self->current_token = finsh_token_type_xor;
			break;

		case '=':
			self->current_token = finsh_token_type_assign;
			break;

		case '\'':
			self->value.char_value = token_proc_char(self);
			self->current_token = finsh_token_type_value_char;
			break;

		case '"':
			token_proc_string(self);
			self->current_token = finsh_token_type_value_string;
			break;

		default:
			if ( is_digit(ch) ) {
				token_prev_char(self);
				token_proc_number(self);
				break;
			}

			finsh_error_set(FINSH_ERROR_UNKNOWN_TOKEN);
			self->current_token = finsh_token_type_bad;

			break;
		}
	}
}