Пример #1
0
/* Combine directory and filename to create a full path */
char * path_from_dir_base(char *dir, char *base) {
#if defined(__WIN32)
	char sep = '\\';
#else
	char sep = '/';
#endif
	GString *path = NULL;
	char *result;

	if ((base != NULL) && (is_separator(base[0]))) {
		path = g_string_new(base);
	} else {
		path = g_string_new(dir);

		/* Ensure that folder ends in "/" */
		if (!is_separator(path->str[strlen(path->str)-1]) ) {
			g_string_append_c(path, sep);
		}

		g_string_append_printf(path, "%s", base);
	}

	result = path->str;
	g_string_free(path, false);

	return result;
}
Пример #2
0
// Check whether LINE is a valid PS line.  Exclude occurrences of PS_COMMAND.
static bool valid_ps_line(const string& line, const string& ps_command)
{
    int pid = ps_pid(line);
    if (pid == 0)
	return false;		// No PID

    // You don't want to debug DDD, don't you?
    if (!remote_gdb() && pid == getpid())
	return false;

    // Neither should you debug GDB by itself.
    if (pid == gdb->pid())
	return false;

    // Don't issue lines containing `ps' (or whatever the first word
    // in PS_COMMAND is).
    string ps = ps_command;
    if (ps.contains(' '))
	ps = ps.before(' ');
    ps = basename(ps.chars());
    int index = line.index(ps);
    if (index > 0
	&& (line[index - 1] == '/' || is_separator(line[index - 1]))
	&& (line.length() == index + ps.length()
	    || is_separator(line[index + ps.length()])))
	return false;

    // Okay, just leave it
    return true;
}
Пример #3
0
static const char *get_token(const char *s, const char **e)
{
	const char *p;

	while (isspace(*s))	/* Skip spaces */
		s++;

	if (*s == '\0') {
		p = s;
		goto end;
	}

	p = s + 1;
	if (!is_separator(*s)) {
		/* End search */
retry:
		while (*p && !is_separator(*p) && !isspace(*p))
			p++;
		/* Escape and special case: '!' is also used in glob pattern */
		if (*(p - 1) == '\\' || (*p == '!' && *(p - 1) == '[')) {
			p++;
			goto retry;
		}
	}
end:
	*e = p;
	return s;
}
Пример #4
0
static const char *get_token(const char *s, const char **e)
{
	const char *p;

	while (isspace(*s))	/*             */
		s++;

	if (*s == '\0') {
		p = s;
		goto end;
	}

	p = s + 1;
	if (!is_separator(*s)) {
		/*            */
retry:
		while (*p && !is_separator(*p) && !isspace(*p))
			p++;
		/*                                                           */
		if (*(p - 1) == '\\' || (*p == '!' && *(p - 1) == '[')) {
			p++;
			goto retry;
		}
	}
end:
	*e = p;
	return s;
}
Пример #5
0
char *
parser_get_next_word(char **sp)
{
	static char buffer[512];
	char	*s = *sp, *p = buffer;

	while (is_separator(*s))
		++s;

	if (*s == '\0')
		goto done;

	if (is_punctuation(*s)) {
		*p++ = *s++;
		goto done;
	}

	while (*s && !is_separator(*s) && !is_punctuation(*s))
		*p++ = *s++;

done:
	*p++ = '\0';
	*sp = s;
	return buffer[0]? buffer : NULL;
}
Пример #6
0
  void path::m_path_iterator_decrement(path::iterator & it)
  {
    BOOST_ASSERT(it.m_pos && "path::iterator decrement past begin()");

    size_type end_pos(it.m_pos);

    // if at end and there was a trailing non-root '/', return "."
    if (it.m_pos == it.m_path_ptr->m_pathname.size()
      && it.m_path_ptr->m_pathname.size() > 1
      && is_separator(it.m_path_ptr->m_pathname[it.m_pos-1])
      && is_non_root_separator(it.m_path_ptr->m_pathname, it.m_pos-1) 
       )
    {
      --it.m_pos;
      it.m_element = dot_path;
      return;
    }

    size_type root_dir_pos(root_directory_start(it.m_path_ptr->m_pathname, end_pos));

    // skip separators unless root directory
    for (
      ; 
      end_pos > 0
      && (end_pos-1) != root_dir_pos
      && is_separator(it.m_path_ptr->m_pathname[end_pos-1])
      ;
      --end_pos) {}

    it.m_pos = filename_pos(it.m_path_ptr->m_pathname, end_pos);
    it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos);
    if (it.m_element.m_pathname == preferred_separator_string)
      it.m_element.m_pathname = separator_string;  // needed for Windows, harmless on POSIX
  }
Пример #7
0
    //------------------------------------------------------------------------
    bool path_tokenizer::next()
    {
        if(m_path == 0) return false;

        // Skip all white spaces and other garbage
        while(*m_path && !is_command(*m_path) && !is_numeric(*m_path)) 
        {
            if(!is_separator(*m_path))
            {
                char buf[100];
                sprintf(buf, "path_tokenizer::next : Invalid Character %c", *m_path);
                throw exception(buf);
            }
            m_path++;
        }

        if(*m_path == 0) return false;

        if(is_command(*m_path))
        {
            // Check if the command is a numeric sign character
            if(*m_path == '-' || *m_path == '+')
            {
                return parse_number();
            }
            m_last_command = *m_path++;
            while(*m_path && is_separator(*m_path)) m_path++;
            if(*m_path == 0) return true;
        }
        return parse_number();
    }
Пример #8
0
static C_RESULT parse_string(FILE* f, char* str, int32_t maxlen)
{
  int32_t i = 0;
  bool_t is_quoted = is_quote(current_c);

  if( is_quoted )
  {
    while( SUCCEED(fetch_char(f)) && ! ( is_separator(current_c) && is_quote(current_c) ) )  {
      str[i] = current_c;
      i++;
    }
  }
  else
  {
    while( SUCCEED(fetch_char(f)) && !is_separator(current_c) )  {
      str[i] = current_c;
      i++;
    }
  }

  str[i] = '\0';
  // PRINT("parse_string: %s\n", str);

  return is_eol( current_c ) ? C_FAIL : C_OK;
}
Пример #9
0
void path::m_path_iterator_increment(path::iterator & it)
{
    BOOST_ASSERT(it.m_pos < it.m_path_ptr->m_pathname.size() && "path::basic_iterator increment past end()");

    // increment to position past current element
    it.m_pos += it.m_element.m_pathname.size();

    // if end reached, create end basic_iterator
    if (it.m_pos == it.m_path_ptr->m_pathname.size())
    {
        it.m_element.clear();
        return;
    }

    // both POSIX and Windows treat paths that begin with exactly two separators specially
    bool was_net(it.m_element.m_pathname.size() > 2
                 && is_separator(it.m_element.m_pathname[0])
                 && is_separator(it.m_element.m_pathname[1])
                 && !is_separator(it.m_element.m_pathname[2]));

    // process separator (Windows drive spec is only case not a separator)
    if (is_separator(it.m_path_ptr->m_pathname[it.m_pos]))
    {
        // detect root directory
        if (was_net
#       ifdef BOOST_WINDOWS_API
                // case "c:/"
                || it.m_element.m_pathname[it.m_element.m_pathname.size()-1] == colon
#       endif
           )
        {
            it.m_element.m_pathname = separator;
            return;
        }

        // bypass separators
        while (it.m_pos != it.m_path_ptr->m_pathname.size()
                && is_separator(it.m_path_ptr->m_pathname[it.m_pos]))
        {
            ++it.m_pos;
        }

        // detect trailing separator, and treat it as ".", per POSIX spec
        if (it.m_pos == it.m_path_ptr->m_pathname.size()
                && is_non_root_separator(it.m_path_ptr->m_pathname, it.m_pos-1))
        {
            --it.m_pos;
            it.m_element = dot_path;
            return;
        }
    }

    // get next element
    size_type end_pos(it.m_path_ptr->m_pathname.find_first_of(separators, it.m_pos));
    if (end_pos == string_type::npos) end_pos = it.m_path_ptr->m_pathname.size();
    it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos);
}
Пример #10
0
/* return 1 if attrs match, 0 otherwise */
static int
match_attrs(char *nas_arg, char *server_arg)
{
    while (*nas_arg && *server_arg) {
	if (is_separator(*nas_arg) && is_separator(*server_arg)) {
	    return(1);
	}
	if (*nas_arg != *server_arg)
	    return(0);
	nas_arg++;
	server_arg++;
    }
    return(0);
}
Пример #11
0
static int l_split( lua_State* L )
{
  size_t      length;
  const char* path = luaL_checklstring( L, 1, &length );
  const char* ext = path + length;
  
  while ( ext >= path && *ext != '.' && !is_separator( *ext ) )
  {
    ext--;
  }
  
  const char* name = ext;
  
  if ( *ext != '.' )
  {
    ext = NULL;
  }
  
  while ( name >= path && !is_separator( *name ) )
  {
    name--;
  }

  if ( is_separator( *name ) )
  {
    name++;
  }

  if ( name - path - 1 > 0 )
  {
    lua_pushlstring( L, path, name - path - 1 );
  }
  else
  {
    lua_pushliteral( L, "" );
  }
  
  if ( ext != NULL )
  {
    lua_pushlstring( L, name, ext - name );
    lua_pushstring( L, ext );
  }
  else
  {
    lua_pushstring( L, name );
    lua_pushliteral( L, "" );
  }
  
  return 3;
}
/**
 * Gets token from expression and writes it to buffer
 * If no more tokens then buffer will be empty string
 *
 * @param *expression       Expression with tokens
 * @param *buffer           Buffer for token
 * @param *position         Next token starts here
 */
static void get_token(const char *expression, char *buffer, unsigned int *position)
{
    if (is_separator(expression[*position])) {
        *buffer++ = expression[*position];
        ++(*position);
    }
    else {
        while (expression[*position] && !is_separator(expression[*position])) {
            *buffer++ = expression[*position];
            ++(*position);
        }
    }
    *buffer = '\0';
}
Пример #13
0
gint gtk_text_buffer_get_word_count (GtkTextBuffer *buffer){
	GtkTextIter start, end;
	gchar *cstring=NULL;
	gint i, leng, icount;
	gtk_text_buffer_get_bounds (buffer, &start, &end);
	cstring = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
	leng = strlen (cstring);
	for ( i = (icount = 1) - 1; i < leng; i++ ){
	if ( is_separator (cstring[i]) && !is_separator (i ? cstring[i - 1] : 'h') )icount++;
	}
	if ( is_separator (cstring[i - 1]) )  icount--;
	g_free (cstring);
	return icount;
}
Пример #14
0
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;
}
Пример #15
0
extern int	lexeme_is_word(t_lex **lex, char *line,
			       char *str, int *i)
{
  int		j;
  char		c;

  j = 0;
  while (line[*i] && !is_separator(line[*i]))
    {
      if (((c = line[*i] == '"') &&
	   (*i != 0 && line[*i - 1] != '\\')) || (c = line[*i]) == '\'')
	{
	  str[j++] = line[(*i)++];
	  while (line[(*i)] != '\0' && line[(*i)] != c)
	    str[j++] = line[(*i)++];
	  if (line[(*i)] != '\0')
	    str[j++] = line[(*i)++];
	}
      if (line[(*i)] != '\0')
	str[j++] = line[(*i)++];
    }
  if (!my_count_printable(str))
    return (1);
  *lex = add_lexeme(*lex, COMMAND, str);
  return (0);
}
Пример #16
0
static int	check_muli_redirections(char **command)
{
  int		left;
  int		right;

  left = 0;
  right = 0;
  while (*command)
  {
    if (!strcmp(">", *command) || !strcmp(">>", *command))
    {
      if (right || !(right = 1))
	return (fprintf(stderr, "Ambiguous output redirect.\n") || 1);
    }
    if (!strcmp("<", *command) || !strcmp("<<", *command))
      if (left || !(left = 1))
	return (fprintf(stderr, "Ambiguous input redirect.\n") || 1);
    if (is_separator(*command))
    {
      left = 0;
      right = 0;
    }
    command++;
  }
  return (0);
}
Пример #17
0
static BOOL is_integer(parse_buffer* buf)
{
  char tmp[50];
  DWORD pos = 0;
  char c;
  DWORD integer;

  while (!is_separator(c = *(buf->buffer+pos)))
  {
    if (!((c >= '0') && (c <= '9')))
      return FALSE;
    tmp[pos++] = c;
  }
  tmp[pos] = 0;

  buf->buffer += pos;
  buf->rem_bytes -= pos;

  sscanf(tmp, "%d", &integer);

  TRACE("Found integer %s - %d\n", tmp, integer);

  *(DWORD*)buf->value = integer;

  return TRUE;
}
Пример #18
0
std::string folder_append_separator(const std::string& folder)
{
  std::string result = folder;
  if (!is_separator(result[result.size()-1]))
    result += preferred_separator;
  return result;
}
Пример #19
0
static BOOL is_string(parse_buffer* buf)
{
  char tmp[100];
  DWORD pos = 0;
  char c;
  BOOL ok = 0;

  if (*buf->buffer != '"')
    return FALSE;

  while (!is_separator(c = *(buf->buffer+pos+1)) && (pos < 99))
  {
    if (c == '"')
    {
      ok = 1;
      break;
    }
    tmp[pos++] = c;
  }
  tmp[pos] = 0;

  if (!ok)
  {
    TRACE("Wrong string %s\n", tmp);
    return FALSE;
  }

  buf->buffer += pos + 2;
  buf->rem_bytes -= pos + 2;

  TRACE("Found string %s\n", tmp);
  strcpy((char*)buf->value, tmp);

  return TRUE;
}
Пример #20
0
/* Return 1 if arg is mandatory, 0 otherwise */
static int
mandatory(char *arg)
{
    char *p = arg;

    while (*p && !is_separator(*p))
	p++;

    /* if we're not at the end, this must be the separator */
    if (*p && !is_separator(*p)) {
	report(LOG_ERR, "%s: Error on arg %s cannot find separator",
	       session.peer, arg);
	return(0);
    }
    return(*p == '=');
}
Пример #21
0
static BOOL is_name(parse_buffer* buf)
{
  char tmp[50];
  DWORD pos = 0;
  char c;
  BOOL error = 0;
  while (!is_separator(c = *(buf->buffer+pos)))
  {
    if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_') || (c == '-')))
      error = 1;
    tmp[pos++] = c;
  }
  tmp[pos] = 0;

  if (error)
  {
    TRACE("Wrong name %s\n", tmp);
    return FALSE;
  }

  buf->buffer += pos;
  buf->rem_bytes -= pos;

  TRACE("Found name %s\n", tmp);
  strcpy((char*)buf->value, tmp);

  return TRUE;
}
Пример #22
0
/**
 * 文字列が余分なセパレータで終わっているかどうかを返します。
 */
bool isTerminatedByRedundantSeparator(const PathString &s)
{
	// 完全修飾パス
	// \\Server\a\ => true?
	// \\Server\ => true?
	// \\?\C:\ => false
	// \\?\ => false
	// C:\a\ => true
	// C:\ => false
	//
	// 非完全修飾パス
	// \ => false
	// C:a\ => true
	// .\ => true
	// a\ => true

	std::size_t lastSepPos = s.size();
	NativeChar prevChar = AUSH_NATIVE_L('\0');
	NativeChar lastSepPrevChar = AUSH_NATIVE_L('\0');

	for(std::size_t pos = 0; pos < s.size(); pos = next_char_pos(s, pos)){
		NativeChar currChar = s[pos];
		if(is_separator()(currChar)){
			lastSepPos = pos;
			lastSepPrevChar = prevChar;
		}
		prevChar = currChar;
	}

	return (lastSepPos + 1 == s.size()
		&& lastSepPrevChar != AUSH_NATIVE_L(':')
		&& lastSepPrevChar != AUSH_NATIVE_L('?')
		&& lastSepPrevChar != AUSH_NATIVE_L('\0'));
}
Пример #23
0
static int	check_redirection(char **command)
{
  int		pipe;
  int		right;

  pipe = 0;
  right = 0;
  while (*command)
  {
    if (!strcmp("|", *command) && (pipe = 1))
      if (right)
	return (fprintf(stderr, "Ambiguous output redirect.\n") || 1);
    if (!strcmp(">", *command) || !strcmp(">>", *command))
      right = 1;
    if (!strcmp("<", *command) || !strcmp("<<", *command))
      if (pipe)
	return (fprintf(stderr, "Ambiguous input redirect.\n") || 1);
    if (is_separator(*command))
    {
      pipe = 0;
      right = 0;
    }
    command++;
  }
  return (0);
}
Пример #24
0
static BOOL is_float(parse_buffer* buf)
{
  char tmp[50];
  DWORD pos = 0;
  char c;
  float decimal;
  BOOL dot = 0;

  while (!is_separator(c = *(buf->buffer+pos)))
  {
    if (!((!pos && (c == '-')) || ((c >= '0') && (c <= '9')) || (!dot && (c == '.'))))
      return FALSE;
    if (c == '.')
      dot = TRUE;
    tmp[pos++] = c;
  }
  tmp[pos] = 0;

  buf->buffer += pos;
  buf->rem_bytes -= pos;

  sscanf(tmp, "%f", &decimal);

  TRACE("Found float %s - %f\n", tmp, decimal);

  *(float*)buf->value = decimal;

  return TRUE;
}
/**
 * Scans the token list from the beginning and moves to the token that covers the given 
 * caret position. Line is one-based and offset is the zero-based offset in that line.
 */
void MySQLScanner::seek(size_t line, size_t offset)
{
  // When scanning keep in mind a token can span more than one line (think of multi-line comments).
  // A simple pos + length computation doesn't cut it.
  d->_token_index = 0;
  if ( d->_tokens[d->_token_index]->type == ANTLR3_TOKEN_EOF)
    return;

  while (true)
  {
    // When we reach the input end check if the current token can alone separate from the next token.
    // Some tokens require a whitespace for separation, some do not.
    pANTLR3_COMMON_TOKEN token = d->_tokens[d->_token_index + 1];
    if (token->type == ANTLR3_TOKEN_EOF)
    {
      // At the end of the input. We have no more tokens to make the lookahead work (nothing after EOF).
      // Instead we define: if the last good token is a separator and the caret is at its end
      // we consider the EOF as the current token (a separator is always only 1 char long).
      if (is_separator() &&  (size_t)d->_tokens[d->_token_index]->charPosition < offset)
        ++d->_token_index;
      break;
    }

    if (token->line > line)
      break;

    if (token->line == line && (size_t)token->charPosition > offset)
      break;

    ++d->_token_index;
  };
}
Пример #26
0
    bool is_separator(const std::string K) {
      for (auto cit = K.begin(); cit != K.end(); cit++) {
	if (!is_separator(*cit)) {
	  return false;
	}
      }
      return true;
    }
Пример #27
0
 /**
  * Remove trailinig path separator.
  */
 string
 remove_trailing_path_separator(const string& in_path)
 {
     string new_string = in_path;
     if (!new_string.empty() && is_separator(new_string[new_string.size() - 1]))
         new_string.erase(new_string.size() - 1);
     return new_string;
 }
Пример #28
0
  path path::root_name() const
  {
    iterator itr(begin());

    return (itr.m_pos != m_pathname.size()
      && (
          (itr.m_element.m_pathname.size() > 1
            && is_separator(itr.m_element.m_pathname[0])
            && is_separator(itr.m_element.m_pathname[1])
   )
#       ifdef BOOST_WINDOWS_API
        || itr.m_element.m_pathname[itr.m_element.m_pathname.size()-1] == colon
#       endif
  ))
      ? itr.m_element
      : path();
  }
Пример #29
0
static unsigned long long __get_mult_bytes(const char *p, void *data,
					   int *percent)
{
	unsigned int kb_base = fio_get_kb_base(data);
	unsigned long long ret = 1;
	unsigned int i, pow = 0, mult = kb_base;
	char *c;

	if (!p)
		return 1;

	c = strdup(p);

	for (i = 0; i < strlen(c); i++) {
		c[i] = tolower(c[i]);
		if (is_separator(c[i])) {
			c[i] = '\0';
			break;
		}
	}

	if (!strncmp("pib", c, 3)) {
		pow = 5;
		mult = 1000;
	} else if (!strncmp("tib", c, 3)) {
		pow = 4;
		mult = 1000;
	} else if (!strncmp("gib", c, 3)) {
		pow = 3;
		mult = 1000;
	} else if (!strncmp("mib", c, 3)) {
		pow = 2;
		mult = 1000;
	} else if (!strncmp("kib", c, 3)) {
		pow = 1;
		mult = 1000;
	} else if (!strncmp("p", c, 1) || !strncmp("pb", c, 2))
		pow = 5;
	else if (!strncmp("t", c, 1) || !strncmp("tb", c, 2))
		pow = 4;
	else if (!strncmp("g", c, 1) || !strncmp("gb", c, 2))
		pow = 3;
	else if (!strncmp("m", c, 1) || !strncmp("mb", c, 2))
		pow = 2;
	else if (!strncmp("k", c, 1) || !strncmp("kb", c, 2))
		pow = 1;
	else if (!strncmp("%", c, 1)) {
		*percent = 1;
		free(c);
		return ret;
	}

	while (pow--)
		ret *= (unsigned long long) mult;

	free(c);
	return ret;
}
Пример #30
0
 path & path::operator/=(const path & p)
 {
   if (p.empty())
     return *this;
   if (!is_separator(*p.m_pathname.begin()))
     m_append_separator_if_needed();
   m_pathname += p.m_pathname;
   return *this;
 }