Example #1
0
bool GCodeReader::GCodeLine::has_value(char axis, float &value) const
{
    const char *c = m_raw.c_str();
    // Skip the whitespaces.
    c = skip_whitespaces(c);
    // Skip the command.
    c = skip_word(c);
    // Up to the end of line or comment.
    while (! is_end_of_gcode_line(*c)) {
        // Skip whitespaces.
        c = skip_whitespaces(c);
        if (is_end_of_gcode_line(*c))
            break;
        // Check the name of the axis.
        if (*c == axis) {
            // Try to parse the numeric value.
            char   *pend = nullptr;
            double  v = strtod(++ c, &pend);
            if (pend != nullptr && is_end_of_word(*pend)) {
                // The axis value has been parsed correctly.
                value = float(v);
                return true;
            }
        }
        // Skip the rest of the word.
        c = skip_word(c);
    }
    return false;
}
Example #2
0
/* Scan a line of the specified /proc/devices FILE buffer and advance the
 * current file position pointer respectively. If the current line matches
 * the correct pattern, fill in the corresponding data into ENTRY and return 0.
 * Return non-zero otherwise. */
static int
scan_dev_entry(struct file_buffer* file, struct proc_dev_entry* entry,
	       int blockdev)
{
	int rc;
	size_t dev_major;
	char* name;

	/* Scan for: (\s*)(\d+)(\s+)(\S+)(\.*)$ */
	skip_whitespaces(file);
	rc = scan_number(file, &dev_major);
	if (rc)
		return rc;
	rc = skip_whitespaces(file);
	if (rc)
		return rc;
	rc = scan_name(file, &name);
	if (rc)
		return rc;
	skip_line(file);
	entry->device = makedev(dev_major, 0);
	entry->name = name;
	entry->blockdev = blockdev;
	return 0;
}
Example #3
0
/*-------------------------------------------------------------------------------*/
short file_copy(FILE *destination,FILE *origin)
{

char ch;
long pos=0;


if(destination==NULL || origin==NULL) t_error("This file was not opened yet");

		ch=getc(origin);
		while(ch!=EOF){
		       if(ch=='\n'){
		    		fprintf(destination,"\n");
		    		skip_whitespaces(origin); 
		    	}else{
		    	
		    		fprintf(destination,"%c",ch);
		    	}
			ch=getc(origin);
		}
pos=ftell(origin);
if(pos==0){
	printf("\nWarning::Empty file encountered");
	return 0;
} else {
	return 1;
}

	return 0;
}
Example #4
0
bool parser::parse_list(utf8str::iterator& it, utf8str::iterator& it_end, shared_ptr<expr>& result)
{
	if (it != it_end)
	{
		uint32_t ch = utf8::peek_next(it, it_end);		
		if (ch == '(')
		{
			utf8::unchecked::next(it);
			vector<shared_ptr<expr> > list;
			shared_ptr<expr> innerExpr;
			bool exprParseRes = true;
			while (exprParseRes)
			{
				exprParseRes = parse_expr(it, it_end, innerExpr);
				if (exprParseRes)
				{
					list.push_back(innerExpr);
					innerExpr.reset();
				}
			}
			skip_whitespaces(it, it_end);
			expect(')', it, it_end);
			result = shared_ptr<expr>(new expr(list));
			return true;			
		}
		else
		{			
			return false;
		}
	}
	return false;
}
Example #5
0
	PrologElement * get_partial_request (void) {
		skip_whitespaces ();
		if (* command != '/') return 0;
		command++;
		int ap = 0; area [0] = '\0';
		char * cp = area;
		while (* command != '/' && * command != '?' && * command > 32) copy_char (& cp, & command);
		* cp = '\0';
		return interpret ();
	}
Example #6
0
/* Scan a line of the specified /proc/partitions FILE buffer and advance the
 * current file position pointer respectively. If the current line matches
 * the correct pattern, fill in the corresponding data into ENTRY and return 0.
 * Return non-zero otherwise. */
static int
scan_part_entry(struct file_buffer* file, struct proc_part_entry* entry)
{
	int rc;
	size_t dev_major;
	size_t dev_minor;
	size_t blockcount;
	char* name;

	/* Scan for: (\s*)(\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\S+)(\.*)$ */
	skip_whitespaces(file);
	rc = scan_number(file, &dev_major);
	if (rc)
		return rc;
	rc = skip_whitespaces(file);
	if (rc)
		return rc;
	rc = scan_number(file, &dev_minor);
	if (rc)
		return rc;
	rc = skip_whitespaces(file);
	if (rc)
		return rc;
	rc = scan_number(file, &blockcount);
	if (rc)
		return rc;
	rc = skip_whitespaces(file);
	if (rc)
		return rc;
	rc = scan_name(file, &name);
	if (rc)
		return rc;
	skip_line(file);
	entry->device = makedev(dev_major, dev_minor);
	entry->blockcount = blockcount;
	entry->name = name;
	return 0;
}
Example #7
0
/* pair = key ':' value */
static int parse_pair(struct frozen *f) {
  int current_path_len;
  const char *tok;
  skip_whitespaces(f);
  tok = f->cur;
  TRY(parse_key(f));
  current_path_len =
      append_to_path(f, *tok == '"' ? tok + 1 : tok,
                     *tok == '"' ? f->cur - tok - 2 : f->cur - tok);
  TRY(test_and_skip(f, ':'));
  TRY(parse_value(f));
  truncate_path(f, current_path_len);
  return 0;
}
Example #8
0
static t_lexer_result   lex_from_str(const char *string)
{
  t_token_list          *tokens;
  t_result              res;

  tokens = NULL;
  while (*string)
    {
      skip_whitespaces(&string);
      if (!*string)
        break ;
      res = lex_token(&string);
      if (res.error)
        return ((t_lexer_result){.tokens = NULL, .error = res.error});
      token_list_add(&tokens, res.token);
    }
Example #9
0
bool parser::parse_expr(utf8str::iterator& it, utf8str::iterator& it_end, shared_ptr<expr>& result)
{	
	if (it != it_end)
	{
		skip_whitespaces(it, it_end);
		if (parse_list(it, it_end, result))
		{
			return true;
		}
		if (parse_atom(it, it_end, result))
		{
			return true;
		}
	}	
	return false;
}
Example #10
0
static int get_deltaupdate_recoverycount(void)
{
    FILE* f;
    int len, num;
    char* buf;

    f = fopen_path(NUM_OF_RECOVERY, "r");
    if(f == NULL)
    {
       LOGI("Error opening recovery count file. Ignore.\n");
       return 0;
    }

    fseek(f, 0, SEEK_END);
    len = ftell(f);
    buf = malloc(len+1);
    if (buf == NULL) {
        LOGI("Failed to allocate buffer\n");
        return 0;
    }
    memset(buf,0x0,len+1);
    fseek(f, 0, SEEK_SET);
    fread(buf, sizeof(char), len, f);
    check_and_fclose(f,NUM_OF_RECOVERY);

    if ((buf = strstr((const char*)buf, "numRecovery")) == NULL)
    {
        LOGI("Recovery count string doesn't match.Ignore.\n");
    }
    else
    {
        buf += 11;
        if ((buf = strstr((const char*)buf, "=")) == NULL)
        {
            LOGI("Invalid recovery count value. Ignore.\n");
        }
        else
        {
            buf += 1;
            buf = (char*)skip_whitespaces((const char*)buf);
            num = atoi((const char*)buf);
            return num;
        }
    }
    return 0;
}
Example #11
0
	bool get_header_line (void) {
		if (* command <= 32) {skip_line (); return false;}
		char * cp = key;
		while (* command > 32 && * command != ':') * cp++ = * command++;
		* cp = '\0';
		if (* command == ':') command++;
		skip_whitespaces ();
		int ap = 0; area [0] = '\0';
		while (* command >= 32) ap = area_cat (area, ap, * command++);
		skip_line ();
		if (strcmp (key, "Content-Type") == 0) {
			if (strstr (area, "multipart/form-data") != 0) {
				char * bdp = strstr (area, "boundary");
				if (bdp != 0) {
					bdp += 9;
					char * bcp = boundary;
					* bcp++ = '-'; * bcp++ = '-';
					while (* bdp >= 32) * bcp++ = * bdp++;
					* bcp = '\0';
				}
			}
		}
		return true;
	}
Example #12
0
static int cur(struct frozen *f) {
  skip_whitespaces(f);
  return f->cur >= f->end ? END_OF_STRING : *(unsigned char *) f->cur;
}
Example #13
0
int
config_parse_file( const char *filename, config_t *c ){
	int fd;
	char *line;
  char *arg,*val;
  int in_profile = 0;
  int rc = 0;
  profile_config_t *p = NULL;
	fd = open( filename, O_RDONLY );
	if( fd == -1 ){
    LOGERROR( "Could not open file %s: (%d) %s", filename, errno, strerror( errno ) );
		return 1;
	}
  val = NULL;
	while ( ( line = f_readline( fd ) ) ){
    arg = skip_whitespaces( line );
    if( arg[0] == '#' || arg[0] == ';' ){
      free(line);
      continue;
    }
    if( !strncmp( arg, "<profile>", strlen( "<profile>" ) ) ){
      in_profile = 1;
      p = profile_config_new( );
      free(line);
      if( p == NULL ){
        LOGERROR( "Could not allocate memory for new profile" );
        rc = 1;
        break;
      }
      list_append( c->profiles, p );
      continue;
    }
    if( !strncmp( arg, "</profile>", strlen( "</profile>" ) ) ){
      in_profile = 0;
      STRDUP_IFNOTSET(p->search_filter, OSEARCH_FILTER);
      p = NULL;
      free(line);
      continue;
    }
    arg = strtok( arg, "=" );
    if(arg && *arg != '\n'){
      val = strtok( NULL, "\n");
      /* global conf -> ldap */
      if( !strcmp( arg, "uri" ) ){
        STRDUP_IFNOTSET(c->ldap->uri, val );
      } else if ( !strcmp( arg, "binddn" ) ) {
        STRDUP_IFNOTSET(c->ldap->binddn, val );
      }else if ( !strcmp( arg, "bindpw" ) ) {
        STRDUP_IFNOTSET(c->ldap->bindpw, val );
      }else if ( !strcmp( arg, "version" ) ){
        if(!c->ldap->version) c->ldap->version = atoi(val);
      }else if ( !strcmp( arg, "ssl" ) ){
        STRDUP_IFNOTSET(c->ldap->ssl, val );
      }else if ( !strcmp( arg, "tls_cacertfile" ) ){
        STRDUP_IFNOTSET(c->ldap->tls_cacertfile, val );
      }else if ( !strcmp( arg, "tls_cacertdir" ) ){
        STRDUP_IFNOTSET(c->ldap->tls_cacertdir, val );
      }else if ( !strcmp( arg, "tls_certfile" ) ){
        STRDUP_IFNOTSET(c->ldap->tls_certfile, val );
      }else if ( !strcmp( arg, "tls_certkey" ) ){
        STRDUP_IFNOTSET(c->ldap->tls_certkey, val );
      }else if ( !strcmp( arg, "tls_ciphersuite" ) ){
        STRDUP_IFNOTSET(c->ldap->tls_ciphersuite, val );
      }else if ( !strcmp( arg, "tls_reqcert" ) ){
        STRDUP_IFNOTSET(c->ldap->tls_reqcert, val );
      }else if( !strcmp( arg, "timeout" ) ){
        if( !c->ldap->timeout ) c->ldap->timeout = atoi(val);
      /* profile conf */
      }else if ( !strcmp( arg, "basedn" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->basedn, val );
      }else if ( !strcmp( arg, "search_filter" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->search_filter, val );
      }else if ( !strcmp( arg, "search_scope" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        if( !strcasecmp( val, "LDAP_SCOPE_BASE" ) ){
          p->search_scope = LA_SCOPE_BASE;
        }else if( !strcasecmp( val, "LDAP_SCOPE_ONELEVEL" ) ){
          p->search_scope = LA_SCOPE_ONELEVEL;
        }else if( !strcasecmp( val, "LDAP_SCOPE_SUBTREE" ) ){
          p->search_scope = LA_SCOPE_SUBTREE;
        }
      /* Group */
      }else if( !strcmp( arg, "groupdn" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->groupdn, val );
      }else if( !strcmp( arg, "group_search_filter" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->group_search_filter, val );
      }else if( !strcmp( arg, "member_attribute" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->member_attribute, val );
      /* Default GW */
      }else if( !strcmp( arg, "redirect_gateway_prefix" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->redirect_gateway_prefix, val );
      }else if( !strcmp( arg, "redirect_gateway_flags" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->redirect_gateway_flags, val );
      /* PF */
      }else if( !strcmp( arg, "enable_pf" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        p->enable_pf = string_to_ternary( val );
      }else if( !strcmp( arg, "default_pf_rules" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->default_pf_rules, val );
#ifdef ENABLE_LDAPUSERCONF
      }else if( !strcmp( arg, "default_profiledn" ) ){
        CHECK_IF_IN_PROFILE( arg, in_profile );
        STRDUP_IFNOTSET(p->default_profiledn, val );
#endif
      }else{
        LOGWARNING("Unrecognized option *%s=%s*", arg, val);
      }

    }
		free( line );
	}
	close( fd );
	return rc;
}
Example #14
0
const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command)
{
    PROFILE_FUNC();
    
    // command and args
    const char *c = ptr;
    {
        PROFILE_BLOCK(command_and_args);
        // Skip the whitespaces.
        command.first = skip_whitespaces(c);
        // Skip the command.
        c = command.second = skip_word(command.first);
        // Up to the end of line or comment.
		while (! is_end_of_gcode_line(*c)) {
            // Skip whitespaces.
            c = skip_whitespaces(c);
			if (is_end_of_gcode_line(*c))
				break;
            // Check the name of the axis.
            Axis axis = NUM_AXES;
            switch (*c) {
            case 'X': axis = X; break;
            case 'Y': axis = Y; break;
            case 'Z': axis = Z; break;
            case 'F': axis = F; break;
            default:
                if (*c == m_extrusion_axis)
                    axis = E;
                break;
            }
            if (axis != NUM_AXES) {
                // Try to parse the numeric value.
                char   *pend = nullptr;
                double  v = strtod(++ c, &pend);
                if (pend != nullptr && is_end_of_word(*pend)) {
                    // The axis value has been parsed correctly.
                    gline.m_axis[int(axis)] = float(v);
                    gline.m_mask |= 1 << int(axis);
                    c = pend;
                } else
                    // Skip the rest of the word.
                    c = skip_word(c);
            } else
                // Skip the rest of the word.
                c = skip_word(c);
        }
    }
    
    if (gline.has(E) && m_config.use_relative_e_distances)
        m_position[E] = 0;

    // Skip the rest of the line.
    for (; ! is_end_of_line(*c); ++ c);

    // Copy the raw string including the comment, without the trailing newlines.
    if (c > ptr) {
        PROFILE_BLOCK(copy_raw_string);
        gline.m_raw.assign(ptr, c);
    }

    // Skip the trailing newlines.
	if (*c == '\r')
		++ c;
	if (*c == '\n')
		++ c;

    if (m_verbose)
        std::cout << gline.m_raw << std::endl;

    return c;
}
Example #15
0
/* Parse emacs modelines.
 * Emacs modelines looks like this: "-*- key1: value1; key2: value2 -*-"
 * They can happen on the first line, or on the second one if the first line is
 * a shebang (#!)
 * See http://www.delorie.com/gnu/docs/emacs/emacs_486.html
 */
static gchar *
parse_emacs_modeline (gchar           *s,
		      ModelineOptions *options)
{
	guint intval;
	GString *key, *value;

	key = g_string_sized_new (8);
	value = g_string_sized_new (8);

	while (*s != '\0')
	{
		while (*s != '\0' && (*s == ';' || g_ascii_isspace (*s)))
			s++;
		if (*s == '\0' || strncmp (s, "-*-", 3) == 0)
			break;

		g_string_assign (key, "");
		g_string_assign (value, "");

		while (*s != '\0' && *s != ':' && *s != ';' &&
		       !g_ascii_isspace (*s))
		{
			g_string_append_c (key, *s);
			s++;
		}

		if (!skip_whitespaces (&s))
			break;

		if (*s != ':')
			continue;
		s++;

		if (!skip_whitespaces (&s))
			break;

		while (*s != '\0' && *s != ';' && !g_ascii_isspace (*s))
		{
			g_string_append_c (value, *s);
			s++;
		}

		gedit_debug_message (DEBUG_PLUGINS,
				     "Emacs modeline bit: %s = %s",
				     key->str, value->str);

		/* "Mode" key is case insenstive */
		if (g_ascii_strcasecmp (key->str, "Mode") == 0)
		{
			g_free (options->language_id);
			options->language_id = get_language_id_emacs (value->str);
			
			options->set |= MODELINE_SET_LANGUAGE;
		}
		else if (strcmp (key->str, "tab-width") == 0)
		{
			intval = atoi (value->str);
			
			if (intval)
			{
				options->tab_width = intval;
				options->set |= MODELINE_SET_TAB_WIDTH;
			}
		}
		else if (strcmp (key->str, "indent-offset") == 0)
		{
			intval = atoi (value->str);
			
			if (intval)
			{
				options->indent_width = intval;
				options->set |= MODELINE_SET_INDENT_WIDTH;
			}
		}
		else if (strcmp (key->str, "indent-tabs-mode") == 0)
		{
			intval = strcmp (value->str, "nil") == 0;
			options->insert_spaces = intval;
			
			options->set |= MODELINE_SET_INSERT_SPACES;
		}
		else if (strcmp (key->str, "autowrap") == 0)
		{
			intval = strcmp (value->str, "nil") != 0;
			options->wrap_mode = intval ? GTK_WRAP_WORD : GTK_WRAP_NONE;
			
			options->set |= MODELINE_SET_WRAP_MODE;
		}
	}

	g_string_free (key, TRUE);
	g_string_free (value, TRUE);

	return *s == '\0' ? s : s + 2;
}
Example #16
0
	void get_protocol (void) {
		skip_whitespaces ();
		int ap = 0; area [0] = '\0';
		while (* command > 32) ap = area_cat (area, ap, * command++);
		skip_line ();
	}
Example #17
0
/*
 * Parse kate modelines.
 * Kate modelines are of the form "kate: key1 value1; key2 value2;"
 * These can happen on the 10 first or 10 last lines of the buffer.
 * See http://wiki.kate-editor.org/index.php/Modelines
 */
static gchar *
parse_kate_modeline (gchar           *s,
		     ModelineOptions *options)
{
	guint intval;
	GString *key, *value;

	key = g_string_sized_new (8);
	value = g_string_sized_new (8);

	while (*s != '\0')
	{
		while (*s != '\0' && (*s == ';' || g_ascii_isspace (*s)))
			s++;
		if (*s == '\0')
			break;

		g_string_assign (key, "");
		g_string_assign (value, "");

		while (*s != '\0' && *s != ';' && !g_ascii_isspace (*s))
		{
			g_string_append_c (key, *s);
			s++;
		}

		if (!skip_whitespaces (&s))
			break;
		if (*s == ';')
			continue;

		while (*s != '\0' && *s != ';' &&
		       !g_ascii_isspace (*s))
		{
			g_string_append_c (value, *s);
			s++;
		}

		gedit_debug_message (DEBUG_PLUGINS,
				     "Kate modeline bit: %s = %s",
				     key->str, value->str);

		if (strcmp (key->str, "hl") == 0 ||
		    strcmp (key->str, "syntax") == 0)
		{
			g_free (options->language_id);
			options->language_id = get_language_id_kate (value->str);
			
			options->set |= MODELINE_SET_LANGUAGE;
		}
		else if (strcmp (key->str, "tab-width") == 0)
		{
			intval = atoi (value->str);
			
			if (intval)
			{
				options->tab_width = intval;
				options->set |= MODELINE_SET_TAB_WIDTH;
			}
		}
		else if (strcmp (key->str, "indent-width") == 0)
		{
			intval = atoi (value->str);
			if (intval) options->indent_width = intval;
		}
		else if (strcmp (key->str, "space-indent") == 0)
		{
			intval = strcmp (value->str, "on") == 0 ||
			         strcmp (value->str, "true") == 0 ||
			         strcmp (value->str, "1") == 0;

			options->insert_spaces = intval;
			options->set |= MODELINE_SET_INSERT_SPACES;
		}
		else if (strcmp (key->str, "word-wrap") == 0)
		{
			intval = strcmp (value->str, "on") == 0 ||
			         strcmp (value->str, "true") == 0 ||
			         strcmp (value->str, "1") == 0;

			options->wrap_mode = intval ? GTK_WRAP_WORD : GTK_WRAP_NONE;

			options->set |= MODELINE_SET_WRAP_MODE;			
		}
		else if (strcmp (key->str, "word-wrap-column") == 0)
		{
			intval = atoi (value->str);
			
			if (intval)
			{
				options->right_margin_position = intval;
				options->display_right_margin = TRUE;
				
				options->set |= MODELINE_SET_RIGHT_MARGIN_POSITION |
				                MODELINE_SET_SHOW_RIGHT_MARGIN;
			}
		}
	}

	g_string_free (key, TRUE);
	g_string_free (value, TRUE);

	return s;
}