Esempio n. 1
0
int main(int argc, char**argv)
{
  ProtobufCService *service;
  ProtobufC_RPC_Client *client;
  ProtobufC_RPC_AddressType address_type=0;
  const char *name = NULL;
  unsigned i;

  for (i = 1; i < (unsigned) argc; i++)
    {
      if (starts_with (argv[i], "--tcp="))
        {
          address_type = PROTOBUF_C_RPC_ADDRESS_TCP;
          name = strchr (argv[i], '=') + 1;
        }
      else if (starts_with (argv[i], "--unix="))
        {
          address_type = PROTOBUF_C_RPC_ADDRESS_LOCAL;
          name = strchr (argv[i], '=') + 1;
        }
      else
        usage ();
    }

  if (name == NULL)
    die ("missing --tcp=HOST:PORT or --unix=PATH");
  
  service = protobuf_c_rpc_client_new (address_type, name, &foo__dir_lookup__descriptor, NULL);
  if (service == NULL)
    die ("error creating client");
  client = (ProtobufC_RPC_Client *) service;

  fprintf (stderr, "Connecting... ");
  while (!protobuf_c_rpc_client_is_connected (client))
    protobuf_c_dispatch_run (protobuf_c_dispatch_default ());
  fprintf (stderr, "done.\n");

  for (;;)
    {
      char buf[1024];
      Foo__Name query = FOO__NAME__INIT;
      protobuf_c_boolean is_done = 0;
      fprintf (stderr, ">> ");
      if (fgets (buf, sizeof (buf), stdin) == NULL)
        break;
      if (is_whitespace (buf))
        continue;
      chomp_trailing_whitespace (buf);
      query.name = buf;
      foo__dir_lookup__by_name (service, &query, handle_query_response, &is_done);
      while (!is_done)
        protobuf_c_dispatch_run (protobuf_c_dispatch_default ());
    }
  return 0;
}
Esempio n. 2
0
bool ep_parse(struct effect_parser *ep, gs_effect_t effect,
              const char *effect_string, const char *file)
{
	bool success;

	const char *graphics_preprocessor = gs_preprocessor_name();

	if (graphics_preprocessor) {
		struct cf_def def;

		cf_def_init(&def);
		def.name.str.array = graphics_preprocessor;
		def.name.str.len   = strlen(graphics_preprocessor);

		strref_copy(&def.name.unmerged_str, &def.name.str);
		cf_preprocessor_add_def(&ep->cfp.pp, &def);
	}

	ep->effect = effect;
	if (!cf_parser_parse(&ep->cfp, effect_string, file))
		return false;

	while (ep->cfp.cur_token && ep->cfp.cur_token->type != CFTOKEN_NONE) {
		if (cf_token_is(&ep->cfp, ";") ||
		    is_whitespace(*ep->cfp.cur_token->str.array)) {
			/* do nothing */
			ep->cfp.cur_token++;

		} else if (cf_token_is(&ep->cfp, "struct")) {
			ep_parse_struct(ep);

		} else if (cf_token_is(&ep->cfp, "technique")) {
			ep_parse_technique(ep);

		} else if (cf_token_is(&ep->cfp, "sampler_state")) {
			ep_parse_sampler_state(ep);

		} else if (cf_token_is(&ep->cfp, "{")) {
			/* add error and pass braces */
			cf_adderror(&ep->cfp, "Unexpected code segment",
					LEX_ERROR, NULL, NULL, NULL);
			cf_pass_pair(&ep->cfp, '{', '}');

		} else {
			/* parameters and functions */
			ep_parse_other(ep);
		}
	}

	success = !error_data_has_errors(&ep->cfp.error_list);
	if (success)
		success = ep_compile(ep);

	return success;
}
Esempio n. 3
0
	std::optional<Range> Item::Range () const noexcept {
	
		std::optional<Unicode::Range> retr;
		
		auto begin=this->begin();
		auto end=this->end();
		
		//	Get and check the beginning of the range
		auto first=get_integer<Unicode::CodePoint::Type>(begin,end);
		if (
			!first ||
			(begin==end) ||
			is_whitespace(begin,end)
		) return retr;
		
		//	Get the range separator
		for (std::size_t i=0;i<2;++i) {
		
			if (*begin=='.') {
			
				++begin;
				continue;
			
			}
			
			if (is_whitespace(begin,end)) return retr;
		
		}
		
		//	Get and check the end of the range
		auto second=get_integer<Unicode::CodePoint::Type>(begin,end);
		if (!(
			second &&
			(
				(begin==end) ||
				is_whitespace(begin,end)
			)
		)) return retr;
		
		return Unicode::Range{*first,*second};
	
	}
Esempio n. 4
0
/* Windows XCOPY uses a simplified command line parsing algorithm
   that lacks the escaped-quote logic of build_argv(), because
   literal double quotes are illegal in any of its arguments.
   Example: 'XCOPY "c:\DIR A" "c:DIR B\"' is OK. */
static int find_end_of_word(const WCHAR *word, WCHAR **end)
{
    BOOL in_quotes = FALSE;
    const WCHAR *ptr = word;
    for (;;) {
        for (; *ptr != '\0' && *ptr != '"' &&
                 (in_quotes || !is_whitespace(*ptr)); ptr++);
        if (*ptr == '"') {
            in_quotes = !in_quotes;
            ptr++;
        }
        /* Odd number of double quotes is illegal for XCOPY */
        if (in_quotes && *ptr == '\0')
            return RC_INITERROR;
        if (*ptr == '\0' || (!in_quotes && is_whitespace(*ptr)))
            break;
    }
    *end = (WCHAR*)ptr;
    return RC_OK;
}
Esempio n. 5
0
static thing_th *read_literals(FILE *src, text_buffer *tb, int inputChar) {
    while(!literal_terminator_char(inputChar)) {
        tb_append(tb, inputChar);
        inputChar=get_character(src);
    }
    if(!is_whitespace(inputChar))
        ungetc(inputChar, src);
    if(is_decimal_text(tb->txt))
        return read_subcons(Number(tb->txt), src, tb);
    return read_subcons(Atom(tb->txt), src, tb);
}
Esempio n. 6
0
	bool is_token(const std::string& token)
	{
		if (is_comment_token(token)) return true; 
		else if (is_string_token(token)) return true;
		else if (is_char_token(token)) return true;
		else if (is_whitespace(token[token.size() - 1])) return false;
		else if (symbols.count(token) == 1) return true;
		else if (keywords.count(token) == 1) return true;
		else if (is_number_token(token)) return true;
		else return is_identifier_token(token);
	}
Esempio n. 7
0
//---------------------------------------------------------------------------
// Reads next word from input string
//
// Word is stored in state.word_buffer and its length in state.word_len
//
// Return value:
//   *  0: Success
//   * -1: No word
//   * -2: Word is longer than MAX_WORD_LEN
//---------------------------------------------------------------------------
int FMC_read_word(struct FMState *state) {
#define M_cur_char()    (state->input_string[state->input_index])
    
    state->word_len = 0;                                    // Reset word

    if (state->input_string == NULL) {                      // If no input string, no word
        return -1;
    }

    // Skip whitespace
    while (M_cur_char() != NUL && is_whitespace(M_cur_char())) {
        state->input_index++;
    }
    
    if (M_cur_char() == NUL) {                              // If at end of string, no word
        return -1;
    }

    // Copy word into buffer
    while(state->word_len <= MAX_WORD_LEN) {
        if (is_whitespace(M_cur_char())) {                  // Stop if hit whitespace,
            state->input_index++;                           // but advance past whitespace char first
            break;
        }
        if (M_cur_char() == NUL) {                          // Stop if hit EOS
            break;
        }
        if (state->word_len == MAX_WORD_LEN) {              // If we're about to exceed word_buffer...
            state->word_len = 0;                            // reset word,
            FMC_abort(state, "Dictionary full", __FILE__, __LINE__);
            return -2;                                      // and indicate error
        }

        state->word_buffer[state->word_len++] =             // Store next character
            M_cur_char();
        state->input_index++;                               // Go to next char in input
    }

    state->word_buffer[state->word_len] = NUL;              // When done, NUL terminate word,
    return 0;                                               // and indicate success
}
Esempio n. 8
0
/*
 * Reads a token from opened token file. The token must be initialized.
 * If token was found function returns TOK_OK and valid data are in the token structure.
 * Otherwise an error occured and there may be anything in the token structure.
 */
int fgetToken(TOKEN_FILE *tf, TOKEN *token) {

	// Check params.
	if (!tf || !token)
		return TOK_INVALID_PARAMS;
	
	// Set token to empty string.
	token->len = 0;
	token->str[0] = '\0';

	// Skip leading whitespace.
	int c = tfpeek(tf);
	token->newline = 0;
	while ((c != EOF) && is_whitespace(c)) {
		if (c == '\n') token->newline = 1;
		tfgetc(tf);
		c = tfpeek(tf);
	}
		
	// If there are no more data or error occured, announce it.
	if (c == EOF) return (tferror(tf) == 0) ? TOK_EOF : TOK_READING_ERROR;
	
	// Read the token.
	while ((c != EOF) && !is_whitespace(c)) {
		
		// Ensure that token string capacity is sufficient.
		if (token->len == token->capacity) {
			if (reallocToken(token) != TOK_OK)
				return TOK_OUT_OF_MEMORY;
		}
		
		// Add char to the token and read another one.
		token->str[ token->len++ ] = tfgetc(tf);
		c = tfpeek(tf);
	}
	
	// Add trailing null char into token string.
	token->str[token->len] = '\0';
	
	return (tferror(tf) == 0) ? TOK_OK : TOK_READING_ERROR;
}
Esempio n. 9
0
static void skip_whitespace(FILE *fp)
{
    for (;;) {
	int c;
	c = getc(fp);
	if (feof(fp)) return;
	if (!is_whitespace(c)) {
	    ungetc(c, fp);
	    break;
	}
    }
}
Esempio n. 10
0
static char *
read_expression (struct parsebuf *p)
{
  int start;
  int end;

  skip_whitespace (p);
  if (peek_char (p) == '"')
    {
      /* Read as a quoted string.  
         The quotation marks are not included in the expression value.  */
      /* Skip opening quotation mark.  */
      read_char (p);
      start = p->pos;
      while (has_more (p) && peek_char (p) != '"')
        read_char (p);
      end = p->pos;
      /* Skip the terminating quotation mark.  */
      read_char (p);
    }
  else if (peek_char (p) == '(')
    {
      /* Read as a parenthesized string -- for tuples/coordinates.  */
      /* The parentheses are included in the expression value.  */
      int c;

      start = p->pos;
      do
        {
          c = read_char (p);
        }
      while (c != -1 && c != ')');
      end = p->pos;
    }
  else if (has_more (p))
    {
      /* Read as a single word -- for numeric values or words without
         whitespace.  */
      start = p->pos;
      while (has_more (p) && ! is_whitespace (peek_char (p)))
        read_char (p);
      end = p->pos;
    }
  else
    {
      /* The end of the theme file has been reached.  */
      grub_error (GRUB_ERR_IO, "%s:%d:%d expression expected in theme file",
                  p->filename, p->line_num, p->col_num);
      return 0;
    }

  return grub_new_substring (p->buf, start, end);
}
Esempio n. 11
0
File: expr.c Progetto: bcho/homework
int validate_expr(char *expression)
{
    char x, op;
    int vt, opt, level;
    char ops[STACK_SIZE];

    vt = -1; opt = -1;
    while ((x = *expression++) != '\0')
        if (is_value(x)) {
            vt += 1;
        } else if (is_op(x)) {
            level = op_level(x);
            while (opt >= 0 && level < op_level(ops[opt]) && \
                    ops[opt] != LEFTP) {
                op = ops[opt];
                opt -= 1;
                if (op == PLUS || op == MULT)
                    vt -= 1;
                if (vt < 0)
                    return 0;
            }
            if (x == RIGHP) {
                while (opt >=0 && ops[opt] != LEFTP) {
                    op = ops[opt];
                    if (op == PLUS || op == MULT)
                        vt -= 1;
                    if (vt < 0)
                        return 0;
                    opt -= 1;
                }
                if (opt < 0)
                    return 0;
                opt -= 1;
            } else {
                ops[++opt] = x;
            }
        } else if (!is_whitespace(x)){
            return 0;
        }

    while (opt >= 0) {
        op = ops[opt];
        if (op == LEFTP)
            return 0;
        if (op == PLUS || op == MULT)
            vt -= 1;
        if (vt < 0)
            return 0;
        opt -= 1;
    }

    return vt == 0 && opt == -1;
}
Esempio n. 12
0
char last_non_whitespace(char* string, int start)
{
  int x;
  if(start>0) // start from inside array and work backwards
  {
    for(x=start; x; x--)
    {
      if(!is_whitespace(string[x]))
        return string[x];
    }
  }
  else // start from beginning and work forwards
  {
    for(x=0; x<(signed)strlen(string); x++)
    {
      if(!is_whitespace(string[x]))
        return string[x];
    }
  }
  return 'x';
}
Esempio n. 13
0
File: e5.c Progetto: voidcycles/void
static char*
e5_trim(
    char* input, int left, int right, size_t maxlen)
{
    size_t n = 0;
    char* start = input;
    while (left && is_whitespace(*start))
        start++;

    n = start - input;
    char* ptr = start;
    char* end = start;
    while (right && *ptr++ != '\0' && n++ < (maxlen-1))
    {
        if (!is_whitespace(*ptr))
            end = ptr;
    }

    *(++end) = '\0';
    return start;
}
Esempio n. 14
0
int translate_range_string_to_vector(const char *range_string, std::vector<int> &indices)
  {
  char *str = strdup(range_string);
  char *ptr = str;
  int   prev;
  int   curr;

  while (*ptr != '\0')
    {
    prev = strtol(ptr, &ptr, 10);

    if (*ptr == '-')
      {
      ptr++;
      curr = strtol(ptr, &ptr, 10);
      
      while (prev <= curr)
        {
        indices.push_back(prev);
        
        prev++;
        }
      
      if ((*ptr == ',') ||
          (is_whitespace(*ptr)))
        ptr++;
      }
    else
      {
      indices.push_back(prev);
      
      if ((*ptr == ',') ||
          (is_whitespace(*ptr)))
        ptr++;
      }
  }

  free(str);
  return(PBSE_NONE);
  }
Esempio n. 15
0
static int parse_word(lua_State *L, parse_state *state, const char *word, const char *err_msg) {
    const char *ptr = state->ptr;
    while (*ptr == *word && *ptr != 0 && *word != 0) {
        ptr++;
        word++;
    }
    if (*word == 0 && (is_whitespace(*ptr) || is_punct(*ptr) || *ptr == 0)) {
        state->ptr = ptr;
        return 1;
    } else {
        return push_parse_error(L, state, err_msg);
    }
}
Esempio n. 16
0
int
is_delimiter(char c)
{
    if (is_whitespace(c) || c == '!' || c == '<' || c == '>' ||
                c == ';' || c == '=' || c == '{' || c == '}' ||
                c == '(' || c == ')' || c == '&' || c == '|' ||
                c == EOF)
    {
        return 1;
    }
    else
        return 0;
}
Esempio n. 17
0
	void lexer::skip() {
		bool inComment = false;

		for (; current != end; current++, column++) {
			if (!inComment && *current == ';') {
				inComment = true;
			} else if (!inComment && !is_whitespace(*current)) {
				break;
			} else if (inComment && *current == '\n') {
				break;
			}
		}
	}
Esempio n. 18
0
/* Check if a line is a label, returns 1 if it is, and 0 if not */
int is_label_line(char *line) {
	int i;
	char *p, *colon;
	char *alphanumeric;
	
	assert(line != NULL);
	
	colon = strchr(line, ':');
	
	/* should have a : marking the end of the label name */
	if (colon == NULL)
		return 0;
	
	/* only characters that should come after the colon are spaces */
	for (i = 1; i < strlen(colon); i++)
		if (!is_whitespace(colon[i]))
			return 0;

	/* and everything before it should be alphanumeric or a space or underscore */
	for (p = line; p < colon; p++)
		if (!is_alphanumeric(*p) && !is_whitespace(*p) && *p != '_')
			return 0;

	/* ...but we cannot have a space in the middle of the label (e.g. "LA BEL:" disallowed)
	   AND we must have atleast one alphanumeric character for the label name */
	alphanumeric = get_first_alphanumeric(line);
	if (alphanumeric == NULL)
		return 0;
	
	/* from the first alphanumeric character to the : */
	for (p = alphanumeric; p < colon; p++) {
		if (!is_alphanumeric(*p) && *p != '_') /* we should only have alphanumeric characters or underscores */
			return 0;
		p++;
	}
	
	return 1;
}
Esempio n. 19
0
END_TEST


START_TEST(trim_whitespace_test)
  {
  char *strs[] = { (char *)"   one ", (char *)" \ntwo", (char *)"three   ", (char *)" four", (char *)"five ", (char *)" six ", (char *)"\t" };
  char  firsts[] = { 'o', 't', 't', 'f', 'f', 's', '\0' };
  char  lasts[] = { 'e', 'o', 'e', 'r', 'e', 'x' };
  int   num_strs = 7;
  int   i;
  int   last;
  char *duped;
  char *retd;

  fail_unless(is_whitespace(' ') == TRUE, "doesn't think a space is whitespace");
  fail_unless(is_whitespace('\n') == TRUE, "doesn't think a newline is whitespace");
  fail_unless(is_whitespace('\f') == TRUE, "doesn't think a formfeed is whitespace");
  fail_unless(is_whitespace('\t') == TRUE, "doesn't think a tab is whitespace");
  fail_unless(is_whitespace('\r') == TRUE, "doesn't think a carriage return is whitespace");

  for (i = 0; i < num_strs; i++)
    {
    duped = strdup(strs[i]);
    retd = trim(duped);
    snprintf(buf, sizeof(buf), "didn't trim the front correctly, found '%s' but expected to start with %c",
      retd, firsts[i]);
    fail_unless(retd[0] == firsts[i], buf);
    last = strlen(retd) - 1;
    if (last > 0)
      {
      snprintf(buf, sizeof(buf), "didn't trim the back correctly, found '%s' but expected to end with %c",
        retd, lasts[i]);
      fail_unless(retd[last] == lasts[i], buf);
      }
    }

  fail_unless(trim(NULL) == NULL, "returned a non-null for null string");
  }
Esempio n. 20
0
static thing_th *read_expressions(FILE *src, text_buffer *tb) {
    int inputChar;
    tb_clear(tb);
    while(is_whitespace(inputChar=get_character(src)));
    if(inputChar==EOF || is_closer(inputChar))
        return NULL;
    if(character_is_break_out_token(inputChar))
        return read_subcons(breakout_character(inputChar), src, tb);
    if(is_quotation(inputChar))
        return read_string(inputChar, src, tb);
    if(is_opener(inputChar)) 
        return read_subcons(open_sub_cons(src, tb, inputChar), src, tb);
    return read_literals(src, tb, inputChar);
}
Esempio n. 21
0
void DocumentView::trim_trailing_whitespace() {
    //FIXME: Don't strip whitespace if the language doesn't like it (e.g. 'diff')
    auto current = buffer()->begin();

    while(current != buffer()->end()) {
        current.forward_to_line_end(); //Move to the newline character
        auto line_end = current; //Store the end of the line
        while(is_whitespace(--current)) {} //Move backward until we get to non-whitespace

        current = buffer()->erase(++current, line_end);

        current.forward_line(); //Move to the next line, or the end of the final line
    }
}
Esempio n. 22
0
static int parse_literal(parsebuf_p pb, char **start, char **stop, int terminator)
{
  int c;
  DEBUG();

  *start = pb->s + pb->i;
  for(; (c = __parsebuf_next(pb)) > 0 && is_symbolchar(c) && (c != terminator););
  if (c <= 0) return -1;
  __parsebuf_prev(pb);
  *stop = pb->s + pb->i;
  if (*start >= *stop) return -1;
  if (!is_whitespace(c) && c != terminator) return -1;

  return 0;
}
Esempio n. 23
0
static boolean is_else (const char* line)
{
  uintL n = strlen(line);
  uintL i = 0;
  /* Skip whitespace. */
  for (; i < n && is_whitespace(line[i]); i++) {}
  /* Parse a '#'. */
  if (i < n && line[i] == '#')
    i++;
  else
    return FALSE;
  /* Skip whitespace. */
  for (; i < n && is_whitespace(line[i]); i++) {}
  /* Check for "else". */
  if (i+4 <= n
      && line[i+0] == 'e'
      && line[i+1] == 'l'
      && line[i+2] == 's'
      && line[i+3] == 'e'
      && (i+4 == n || is_whitespace(line[i+4]))) {
    return TRUE;
  }
  return FALSE;
}
Esempio n. 24
0
void run(struct iso *context)
{
    char cmd[MAX_COMMAND_SIZE + 1];

    while (running && prompt(cmd, MAX_COMMAND_SIZE + 1))
    {
        int argc = 0;
        char *argv[MAX_COMMAND_SIZE];

        ssize_t read_b = 0;
        for (char *s = cmd; *s; ++s)
            ++read_b;

        char *s = cmd + read_b - 1;
        for (; read_b > 0; --read_b, --s)
        {
            for (; read_b > 0 && is_whitespace(*s); --read_b, --s)
                continue;
            if (read_b)
            {
                *(s + 1) = '\0';
                for (; read_b > 0 && !is_whitespace(*s); --read_b, --s)
                    continue;
                argv[argc++] = s + 1;
            }
        }

        if (!argc)
            continue;

        for (int i = 0; i < argc / 2; ++i)
            swap(argv, i, argc - i - 1);

        get_command(argv[0])(context, argc, argv);
    }
}
Esempio n. 25
0
static int get_indent(const std::string text) {
   auto range = codepoint_range(text);
   auto it = range.end();
   std::size_t indent = 0;
   while (it != range.begin()) {
      auto ch = *--it;
      if (!is_whitespace(ch)) break;
      if (ch == '\n') return indent;
      ++indent;
   }
   while (it != range.begin()) {
      auto ch = *--it;
      if (ch == '\n') return 0;
   }
   return -1;
}
Esempio n. 26
0
void move_past_whitespace(

  char **str)

  {
  if ((str == NULL) ||
      (*str == NULL))
    return;

  char *current = *str;

  while (is_whitespace(*current) == TRUE)
    current++;

  *str = current;
  } // END move_past_whitespace()
Esempio n. 27
0
void skip_whitespace(muj_source source)
{
	char byte;
    for(;;)
	{
		bool success = muj_peek_byte(source, &byte);
		if (!success)
			break;
		if (is_whitespace(byte))
		{
			muj_read_byte(source, &byte); // will always succeed because peek did
		}
		else
			break;
	}
}
Esempio n. 28
0
static gboolean
find_whitepace_region (const GtkTextIter *center,
                       GtkTextIter       *start,
                       GtkTextIter       *end)
{
  *start = *center;
  *end   = *center;

  if (gtk_text_iter_backward_find_char (start, is_not_whitespace, NULL, NULL))
    gtk_text_iter_forward_char (start); /* we want the first whitespace... */

  if (is_whitespace (gtk_text_iter_get_char (end), NULL))
    gtk_text_iter_forward_find_char (end, is_not_whitespace, NULL, NULL);

  return ! gtk_text_iter_equal (start, end);
}
Esempio n. 29
0
void	handle_alias_glob(char **expr, int **t_ind, int **l_ind)
{
	t_norm_hag t;

	(t.i) = 0;
	(t.first_time) = TRUE;
	(t.len) = ft_strlen((*expr));
	while ((t.i) < (t.len))
	{
		(t.continu) = FALSE;
		if (is_whitespace((*expr)[(t.i)]) &&
		!is_intouchable((t.i), (*t_ind), (*l_ind)))
			(t.i)++;
		else
			handle_alias_glob2(expr, t_ind, l_ind, &t);
	}
}
Esempio n. 30
0
static int parse_number(lua_State *L, parse_state *state) {
    char *end;
    double n = strtod(state->ptr, &end);
    if (state->ptr == end || (*end != 0 && !is_whitespace(*end) && !is_punct(*end))) {
        return push_parse_error(L, state, "invalid number");
    } else {
        state->ptr = end;
        if ((double)((int)n) == n) {
            // in case we're using different representation for
            // integers in the lua vm
            lua_pushinteger(L, (int)n);
        } else {
            lua_pushnumber(L, n);
        }
        return 1;
    }
}