Example #1
0
static char *copy_and_expand_variables(const char *path, int len)
{
    char *dst, *result;
    const char *src;
    int length = 0;
    int backslash;

    /* first determine the length of the expanded string */
    backslash = 0;
    for (src = path; src < path + len; src++)
    {
        if (!backslash && *src == '\\' && src + 1 < path + len)
        {
            backslash = 1;
            continue;
        }
        if (!backslash && *src == '$')
        {
            src++;
            length += strlen(parse_variable(&src, path + len));
            src--;
        }
        else
            length++;
        backslash = 0;
    }

    /* allocate a string of the appropriate length */
    result = malloc(length + 1);
    assert_always(result != NULL, "Out of memory in variable expansion!");

    /* now actually generate the string */
    backslash = 0;
    for (src = path, dst = result; src < path + len; src++)
    {
        if (!backslash && *src == '\\' && src + 1 < path + len)
        {
            backslash = 1;
            continue;
        }
        if (!backslash && *src == '$')
        {
            src++;
            dst += sprintf(dst, "%s", parse_variable(&src, path + len));
            src--;
        }
        else
            *dst++ = *src;
        backslash = 0;
    }

    /* NULL terminate and return */
    *dst = 0;
    return result;
}
/**
 * Parse the string expression 's' (that contains only string values) and return its
 * resulting value in 'value'.
 * Return a pointer behind the last character of the expression.
 * Return NULL if a syntax error occurred.
 */
char *parse_string_expression(char *s, char **value) {
  unsigned int var_name;
  variable *var;
  unsigned char var_type;
  unsigned char token;

  s = skip_whitespace(s);
  token = next_token(s);

  if (token == TOKEN_STRING) {
    if (s = parse_string(s, parsebuf)) {
      *value = parsebuf;
      return s;
    } else {
      syntax_error_invalid_string();
    }
  } else if (token == TOKEN_VAR_STRING) {
    s = parse_variable(s, &var_name, &var_type);
    var = find_variable(var_name, VAR_TYPE_STRING, NULL);
    if (var) {
      *value = get_string_variable_value(var);
      return s;
    } else {
      syntax_error_msg("Variable not found");
    }
  } else {
    syntax_error();
  }

  return NULL;
}
Example #3
0
/** строка с подстановками
*/
int
parse_subst(char *text,char **endptr,Tag *toptag) {
	char *p;
	char *s;
	Tag *tag;
	tag=NULL;
	if (text[0]!='\"') return 1;
	s=text;
	if (toptag) tag=mark(STRING,text,s,toptag);
	mark_len(NULL,1,s,&s,tag);	// открывающая кавычка
	while(*s) {
		p=s;
		s+=strcspn(s,"\\$[{\"");
		if (p!=s) mark(CHARS,p,s,tag);
		switch (*s) {
			case '\\' : parse_escape(s,&s,tag);break;
			case '$'  : parse_variable(s,&s,tag);break;
			case '['  : parse_command(s,&s,tag);break;
		}
		if (s[0]=='\"') {
			mark_len(NULL,1,s,&s,tag);	// закрывающая кавычка
			break;
		}
		if (p==s) break;
	}
	if (endptr) (*endptr)=s;
	return 0;
}
Example #4
0
/**
	слово:
		список в скобках {}
		подстановка выражения в скобках []
*/
int
parse_word(char *text,char **endptr,Tag *toptag) {
	char *p,*s;
	Tag *tag;
	tag=NULL;
	s=text;

	if (s==NULL || isblank(*s)||strchr(EXPTERM,*s)) return 1;
	if (toptag) tag=mark(WORD,text,text,toptag);

	while(*s) {
		p=s;
		switch(*s) {
			case '{' : parse_list(s,&s,tag);break;
			case '[' : parse_command(s,&s,tag);break;
			case '\'': parse_string(s,&s,tag);break;
			case '\"': parse_subst(s,&s,tag);break;
			case '$' : parse_variable(s,&s,tag);break;
			default:
				if (s[0]=='#' && s[1]!='#' && s[1]!='!') {
					parse_macro(s,&s,tag);
				} else if (s[0]=='#' && s[1]=='?' && s[2]=='>') {
					parse_print(s,&s,tag);
				} else if ((s[0]=='-' && isdigit(s[1])) || isdigit(*s))
					parse_numeric(s,&s,tag);
				else
					mark_cspn(CHARS,BLANK EXPTERM "(",s,&s,tag);
		}
		if (strchr(BLANK EXPTERM,*s)) break;
		if (p==s) break;
	}
	if (endptr) *endptr=s;
	return 0;
}
Example #5
0
/** текст выводимый на консоль
**/
int
parse_print(char *text,char **endptr,Tag *toptag) {
	char *s,*p;
	Tag *tag;
	TRACE("");
	tag=NULL;
	if (text[0]!='#'||text[1]!='?'||text[2]!='>') return 1;
	s=text;
	if (toptag) tag=mark(PRINT,text,text,toptag);
	mark_len(NULL,3,s,&s,tag);	// открывающая группа #?>
	while(*s) {
		p=s;
		mark_cspn(CHARS,"<$[\\",s,&s,tag);		// фрагмент до кавычки ' или esc
		if (s[0]=='\\') parse_escape(s,&s,tag);	// esc
		if (s[0]=='$') parse_variable(s,&s,tag);// подстановка переменных
		if (s[0]=='[') parse_command(s,&s,tag); // полстановка команд
		if (s[0]=='<') {
			if (s[1]=='?' && s[2]=='#') {
				mark_len(NULL,3,s,&s,tag);	// закрывающая группа <?#
				break;
			} else {
				mark_len(NULL,1,s,&s,tag);
			}
		}
		if (p==s) break;
	}
	if (endptr) (*endptr)=s;
	return 0;
}
/**
 * Parse the number term 's' and return its resulting value in 'value'.
 * Return a pointer behind the last character of the expression.
 * Return NULL if a syntax error occurred.
 */
char *parse_number_term(char *s, int *value) {
  unsigned char token;
  s = skip_whitespace(s);
  token = next_token(s);
  if (token == TOKEN_DIGITS || token == TOKEN_PLUS || token == TOKEN_MINUS) {
    if (s = parse_integer(s, value)) {
      return s;
    } else {
      syntax_error_invalid_number();
    }
  } else if (token == TOKEN_VAR_NUMBER) {
    unsigned int var_name;
    unsigned char var_type;
    variable *var;
    s = parse_variable(s, &var_name, &var_type);
    var = find_variable(var_name, VAR_TYPE_INTEGER, NULL);
    if (var) {
      *value = get_integer_variable_value(var);
      return s;
    } else {
      syntax_error_msg("Variable not found");
    }
  } else {
    syntax_error();
  }

  return NULL;
}
Example #7
0
void task4_6::solution::process_line( std::string line )
{
	int eq_pos = line.find("=");
	const std::string& value_name = line.substr( 0, eq_pos-1 );
	line = line.substr( eq_pos + 2 );

	if( value.count( value_name ) )
		throw std::logic_error( "such variable '"+value_name+"' already exists ("+boost::lexical_cast< std::string >( line_index )+")" );

	std::stack< char > operations;
	std::stack< double > numbers;
	double result = 0;

	for( size_t i = 0; i < line.length(); i++)
		if( line[i] != ' ' )
			if( line[i] == '(' )
				operations.push('(');
			else if( line[i] ==')' )
			{
				while( !operations.empty() && operations.top() != '(' )
				{
					process_operation( numbers, operations.top() );
					operations.pop();
				}

				if( operations.empty() )
					throw std::logic_error("not correct expression at "+boost::lexical_cast< std::string >( line_index )+" line");
				
				operations.pop();
			}
			else if( is_operation( line[i] ) )
			{
				while( !operations.empty() && get_priority( operations.top() ) >= get_priority( line[i] ) )
				{
					process_operation( numbers, operations.top() );
					operations.pop();
				}
				operations.push( line[i] ); 
			}
			else
			{
				std::string operand;
				while (i < line.length() && line[i]!=' ' && !is_operation(line[i]) && line[i]!='(' && line[i]!=')')
					operand += line[i++];
				--i;
				double to_push;
				parse_variable ( operand, to_push );
				numbers.push ( to_push );
			}

	while ( !operations.empty() )
	{
		process_operation( numbers, operations.top() );
		operations.pop();
	}

	result = numbers.top();
	value[ value_name ] = result;
}
Example #8
0
File: v7.c Project: di3online/v7
//  factor  =   number | string_literal | "(" expression ")" |
//              variable | "this" | "null" | "true" | "false" |
//              "{" object_literal "}" |
//              "[" array_literal "]" |
//              function_definition |
//              function_call
static enum v7_err parse_factor(struct v7 *v7) {
  int old_sp = v7_sp(v7);

  if (*v7->cursor == '(') {
    TRY(match(v7, '('));
    TRY(parse_expression(v7));
    TRY(match(v7, ')'));
  } else if (*v7->cursor == '\'' || *v7->cursor == '"') {
    TRY(parse_string_literal(v7));
  } else if (*v7->cursor == '{') {
    TRY(parse_object_literal(v7));
  } else if (is_alpha(*v7->cursor) || *v7->cursor == '_') {
    TRY(parse_identifier(v7));
    if (test_token(v7, "this", 4)) {
      inc_stack(v7, 1);
      v7_top(v7)[-1] = &v7->scopes[v7->current_scope];
    } else if (test_token(v7, "null", 4)) {
      TRY(v7_make_and_push(v7, V7_NULL));
    } else if (test_token(v7, "true", 4)) {
      TRY(v7_make_and_push(v7, V7_BOOL));
      v7_top(v7)[-1]->v.num = 1;
    } else if (test_token(v7, "false", 5)) {
      TRY(v7_make_and_push(v7, V7_BOOL));
      v7_top(v7)[-1]->v.num = 0;
    } else if (test_token(v7, "function", 8)) {
      TRY(parse_function_definition(v7, NULL, 0));
    } else if (test_token(v7, "delete", 6)) {
      TRY(parse_delete(v7));
    } else {
      TRY(parse_variable(v7));
    }
  } else {
    TRY(parse_num(v7));
  }

  if (*v7->cursor == '(') {
    TRY(parse_function_call(v7));
  }

  // Don't leave anything on stack if no execution flag is set
  if (v7->no_exec) {
    inc_stack(v7, old_sp - v7->sp);
  }

  return V7_OK;
}
Example #9
0
exparser::return_type exparser::loop(const std::string& s) {
    if (s.empty()) return return_false;
    
    if (debug) std::cout << "PARSING : " << s << std::endl;

    if (debug) std::cerr << "Try parenthesis" << std::endl;
    return_type parenthesis = parse_parenthesis(s);
    if (parenthesis) return parenthesis;
    
    if (debug) std::cerr << "Try constant" << std::endl;
    return_type constant = parse_constant(s);
    if (constant) return constant;
    
    if (debug) std::cerr << "Try variable" << std::endl;
    return_type variable = parse_variable(s);
    if (variable) return variable;
    
    if (debug) std::cerr << "Try plus" << std::endl;
    return_type plus = parse_plus(s);
    if (plus) return plus;
    
    if (debug) std::cerr << "Try minus" << std::endl;
    return_type minus = parse_minus(s);
    if (minus) return minus;

    if (debug) std::cerr << "Try multiply" << std::endl;
    return_type multiply = parse_multiply(s);
    if (multiply) return multiply;
    
    if (debug) std::cerr << "Try divide" << std::endl;
    return_type divide = parse_divide(s);
    if (divide) return divide;
    
    if (debug) std::cerr << "Try poewr" << std::endl;
    return_type power = parse_power(s);
    if (power) return power;
    
    if (debug) std::cerr << "Try function" << std::endl;
    return_type function = parse_function(s);
    if (function) return function;

    return return_false;
}
Example #10
0
core_option_manager_t *core_option_new(const char *conf_path,
      const struct retro_variable *vars)
{
   const struct retro_variable *var;
   core_option_manager_t *opt = (core_option_manager_t*)
      calloc(1, sizeof(*opt));
   if (!opt)
      return NULL;

   size_t size = 0;

   if (*conf_path)
      opt->conf = config_file_new(conf_path);
   if (!opt->conf)
      opt->conf = config_file_new(NULL);

   strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));

   if (!opt->conf)
      goto error;

   for (var = vars; var->key && var->value; var++)
      size++;

   opt->opts = (struct core_option*)calloc(size, sizeof(*opt->opts));
   if (!opt->opts)
      goto error;

   opt->size = size;

   size = 0;
   for (var = vars; var->key && var->value; size++, var++)
   {
      if (!parse_variable(opt, size, var))
         goto error;
   }

   return opt;

error:
   core_option_free(opt);
   return NULL;
}
/**
 * Assign a value to a variable or delete the variable if no assignment is given.
 * List all variables if no arguments are given.
 */
void cmd_let(char *args) {
  unsigned char token;
  unsigned int var_name;
  unsigned char var_type;

  skip_whitespace(args);

  if (*args == '\0') {
    print_all_variables();
    print_ready();
    return;
  }

  if (args = parse_variable(args, &var_name, &var_type)) {
    if (next_token(args) == TOKEN_ASSIGN) {
      token = next_token(args);
      args = consume_token(args, token);
      switch (var_type) {
        case VAR_TYPE_INTEGER: {
          int value;
          if (parse_number_expression(args, &value)) {
            create_variable(var_name, var_type, &value);
          }
          break;
        }
        case VAR_TYPE_STRING: {
          char *value;
          if (parse_string_expression(args, &value)) {
            create_variable(var_name, var_type, value);
          }
          break;
        }
      }
    } else {
      if (*args == '\0') {
        delete_variable(var_name, var_type);
      }
    }
  } else {
    syntax_error();
  }
}
Example #12
0
    object& parse()
    {
        line_ = column_ = 0;
        if (parsed) delete parsed;
        parsed = 0;
        
        while (iss_.good())
        {
            skipws();

            char_type c = iss_.peek();
            if (c == '{')
            {
                parsed = parse_object();
                break;
            }
            else if (isalpha(c))
            {
                parsed = new object();

                while (iss_.good())
                {
                    parsed->add<shaun>(parse_variable());
                    skipws();
                }

                break;
            }
            else
            {
                PARSE_ERROR(root must be an object);
            }

            forward();
        }

        PARSE_ASSERT(parsed, what ?);

        return *parsed;
    }
Example #13
0
File: parse.c Project: jkdewar/rook
/*----------------------------------------------------------------------*/
static ast_expression_t *parse_value(parse_state_t *p) {
    token_t *token = peek_token(p);

    if (token == NULL) {
    } else if (token->type == TK_INT_LITERAL ||
               token->type == TK_FLOAT_LITERAL ||
               token->type == TK_DOUBLE_LITERAL ||
               token->type == TK_STRING_LITERAL) {
        return parse_literal(p);
    } else if (token->type == TK_IDENTIFIER) {
        next_token(p);
        if (test_token(peek_token(p), TK_LBRACKET)) {
            rewind_token(p);
            return parse_function_call(p);
        } else {
            rewind_token(p);
            return parse_variable(p);
        }
    }
    error(p, "value expected");
    return NULL; /* unreachable */
}
/**
 * Set the cursor to a specific screen position.
 * AT <x>,<y>
 */
void cmd_at(char *args) {
  int x;
  int y;
  unsigned char token;

  args = parse_number_expression(args, &x);
  if (!args || x < 0 || x > 39) {
    syntax_error_invalid_argument();
    return;
  }

  args = consume_token(args, TOKEN_COMMA);
  if (! args) {
    return;
  }

  args = parse_number_expression(args, &y);
  if (!args || y < 0 || y > 3) {
    syntax_error_invalid_argument();
    return;
  }

  if (next_token(args) == TOKEN_COMMA) {
    args = consume_token(args, TOKEN_COMMA);
    if ((token = next_token(args)) == TOKEN_VAR_STRING) {
      unsigned int var_name;
      unsigned char var_type;
      if (args = parse_variable(args, &var_name, &var_type)) {
        char c = lcd_getc(x, y);
        sprintf (print_buffer, "%c", c);
        create_variable(var_name, VAR_TYPE_STRING, print_buffer);
      }
    } else {
      syntax_error_invalid_token(token);
    }
  } else {
    lcd_goto(x, y);
  }
}
/**
 * Input a variable from the keyboard.
 * INPUT <variable> [ONERROR <command]
 */
void cmd_input(char *args) {
  unsigned int var_name;
  unsigned char var_type;

  args = parse_variable(args, &var_name, &var_type);
  if (args) {
    if (var_type == VAR_TYPE_STRING) {
      char *line = readline(INTERRUPTIBLE);
      create_variable(var_name, var_type, line);
    } else if (var_type == VAR_TYPE_INTEGER) {
      for (;;) {
        int value = 0;
        char *line = readline(INTERRUPTIBLE);
        if (is_interrupted()) {
          break;
        }
        if (parse_integer(line, &value)) {
          create_variable(var_name, var_type, &value);
          break;
        } else {
          if (next_token(args) == TOKEN_ONERROR) {
            args = consume_token(args, TOKEN_ONERROR);
            execute(args);
            break;
          } else {
            syntax_error_invalid_number();
            lcd_puts("Enter again: ");
          }
        }
      }
    } else {
      syntax_error_invalid_argument();
    }
  } else {
    syntax_error_invalid_argument();
  }
}
Example #16
0
static void
handle_variable (const char *pair)
{
  char *name;
  char *value;
  JBVariable *variable;
  GError *err = NULL;

  if (! parse_variable(pair, &name, &value))
    jb_error("invalid variable specification \"%s\"", pair);

  variable = jb_variable_get_variable(name);
  if (variable == NULL || (variable->flags & JB_VARIABLE_USER_SETTABLE) == 0)
    jb_error("unknown variable \"%s\"", name);

  if (! jb_variable_set_from_string(variable, value, &err))
    jb_error("invalid value \"%s\" for %s variable \"%s\": %s",
	     value,
	     variable->type->name,
	     name,
	     err->message);

  variable->user_set = TRUE;
}
Example #17
0
/* See SMTSolver::parse_evidence() */
void
YicesSolver::parse_evidence()
{
    /* Look for text like "(= v36 0b01101111111111111101011110110100)" or
     * "(= (m95 0b01000000000000011100111111110100) 0b00000000000000000100111100000100)".  The text is free-form, with any
     * white space appearing in place of the SPC characters shown. */
    evidence.clear();
    const char *s = output_text.c_str();
    char *rest = NULL;

    struct Error {
        Error(const char *at, const std::string &mesg): at(at), mesg(mesg) {}
        const char *at;
        std::string mesg;
    };

    try {
        while (*s) {
            // "(= "
            while (isspace(*s)) ++s;
            if (!*s)
                break;
            if ('('!=*s++)
                throw Error(s-1, "left paren expected (1)");
            while (isspace(*s)) ++s;
            if ('='!=*s++)
                throw Error(s-1, "'=' operator expected (2)");
            if (!isspace(*s++))
                throw Error(s-1, "'=' operator expected (3)");
        
            // variable or function-apply
            while (isspace(*s)) ++s;
            if ('('==*s) {
                ++s;

                // memory variable, like "m95"
                errno = 0;
                (void) parse_variable(s, &rest, 'm');
                if (errno || s==rest)
                    throw Error(s, "memory variable expected (5)");
                s = rest;

                // memory address, like 0b01000000000000011100111111110100
                uint64_t addr = rose_strtoull(s, &rest, 0);
                if (errno || s==rest)
                    throw Error(s, "memory address expected (6)");
                s = rest;

                // right paren
                while (isspace(*s)) ++s;
                if (')'!=*s++)
                    throw Error(s, "')' expected after memory address (7)");

                // memory value
                while (isspace(*s)) ++s;
                if (0!=strncmp(s, "0b", 2) || !strchr("01", s[2]))
                    throw Error(s, "binary constant expected for memory value (8)");
                s += 2;
                uint64_t val = rose_strtoull(s, &rest, 2);
                if (errno || s==rest)
                    throw Error(s, "memory value expected (9)");
                size_t nbits = rest-s;
                s = rest;

                std::string addr_name = StringUtility::addrToString(addr);
                if (evidence.find(addr_name) != evidence.end())
                    throw Error(s, addr_name + " appears more than once (10)");
                evidence[addr_name] = std::pair<size_t, uint64_t>(nbits, val);

            } else {
                // bitvector variable name
                errno = 0;
                uint64_t vnum = parse_variable(s, &rest, 'v');
                if (errno || s==rest)
                    throw Error(s, "bitvector variable expected (11)");
                s = rest;

                // bitvector value
                while (isspace(*s)) ++s;
                if (0!=strncmp(s, "0b", 2) || !strchr("01", s[2]))
                    throw Error(s, "binary constant expected for bitvector variable (12)");
                s += 2;
                uint64_t val = rose_strtoull(s, &rest, 2);
                if (errno || s==rest)
                    throw Error(s, "bitvector value expected (13)");
                size_t nbits = rest-s;
                s = rest;

                std::string vname = "v" + StringUtility::numberToString(vnum);
                ASSERT_require(evidence.find(vname)==evidence.end());
                evidence[vname] = std::pair<size_t, uint64_t>(nbits, val);
            }

            // ')' closing the '=' operator
            if (')'!=*s++)
                throw Error(s-1, "expected ')' to close '=' operator (14)");
        }
        
    } catch (const Error &err) {
        std::cerr <<"YicesSolver::parse_evidence: " <<err.mesg <<" at char position " <<(err.at-output_text.c_str()) <<"\n"
                  <<"YicesSolver::parse_evidence: before \"" <<std::string(err.at).substr(0, 20) <<"\"...\n"
                  <<"YicesSolver::parse_evidence: entire evidence string follows...\n"
                  <<output_text.c_str();
    }
}
Example #18
0
cgc_ssize_t
cgc_tokenize(char *str, struct token *tokens)
{
    int ret;
    char c;
    struct token *token = tokens;

    while ((c = *str++)) {
        if (c == '_' || cgc_islower(c)) {
            if ((ret = parse_variable(str - 1, token)) < 0)
                return ret;

            str += ret - 1;
            token++;
            continue;
        }

        if (cgc_isdigit(c)) {
            if ((ret = parse_constant(str - 1, token)) < 0)
                return ret;

            str += ret - 1;
            token++;
            continue;
        }

        switch (c) {
        case '=':
            token->type = TOK_ASSIGNMENT;
            break;
        case '+':
            token->type = TOK_ADD;
            break;
        case '-':
            token->type = TOK_SUBTRACT;
            break;
        case '*':
            token->type = TOK_MULTIPLY;
            break;
        case '/':
            token->type = TOK_DIVIDE;
            break;
        case '~':
            token->type = TOK_NEGATE;
            break;
        case '&':
            token->type = TOK_ADDRESS_OF;
            break;
        case '$':
            token->type = TOK_DEREFERENCE;
            break;
        case '(':
            token->type = TOK_LEFT_PARENTHESIS;
            break;
        case ')':
            token->type = TOK_RIGHT_PARENTHESIS;
            break;
        case ' ':
            continue;
        default:
            return EXIT_FAILURE;
        }

        token++;
    }

    return token - tokens;
}
static void
ide_source_snippet_parser_do_part (IdeSourceSnippetParser *parser,
                                   const gchar            *line)
{
  const gchar *dollar;
  gchar *str;
  gchar *inner;
  gchar *name;
  glong n;

  g_assert (line);
  g_assert (*line == '\t');

  line++;

again:
  if (!*line)
    return;

  if (!(dollar = strchr (line, '$')))
    {
      ide_source_snippet_parser_do_part_simple (parser, line);
      return;
    }

  /*
   * Parse up to the next $ as a simple.
   * If it is $N or ${N} then it is a linked chunk w/o tabstop.
   * If it is ${N:""} then it is a chunk w/ tabstop.
   * If it is ${blah|upper} then it is a non-tab stop chunk performing
   * some sort of of expansion.
   */

  g_assert (dollar >= line);

  if (dollar != line)
    {
      str = g_strndup (line, (dollar - line));
      ide_source_snippet_parser_do_part_simple (parser, str);
      g_free (str);
      line = dollar;
    }

parse_dollar:
  inner = NULL;

  if (!parse_variable (line, &n, &inner, &line, &name))
    {
      ide_source_snippet_parser_do_part_simple (parser, line);
      return;
    }

#if 0
  g_printerr ("Parse Variable: N=%d  inner=\"%s\"\n", n, inner);
  g_printerr ("  Left over: \"%s\"\n", line);
#endif

  ide_source_snippet_parser_flush_chunk (parser);

  if (inner)
    {
      ide_source_snippet_parser_do_part_n (parser, n, inner);
      g_free (inner);
      inner = NULL;
    }
  else if (n == -2 && name)
    ide_source_snippet_parser_do_part_named (parser, name);
  else
    ide_source_snippet_parser_do_part_linked (parser, n);

  g_free (name);

  if (line)
    {
      if (*line == '$')
        {
          goto parse_dollar;
        }
      else
        goto again;
    }
}
Example #20
0
/*
 *	DO statement
 *	Handles DO;, DO CASE, DO WHILE, and iterative DO
 */
void
parse_do(TOKEN *first_token)
{
    TOKEN		token;
    int		token_class;
    int		case_line;
    char		case_statement[MAX_TOKEN_LENGTH];
    char		case_output[MAX_CASE_STATEMENT_SIZE];
    char		var_string[MAX_TOKEN_LENGTH];
    char		*temp_out_string, *temp_out_string1;
    DECL_MEMBER	*var_decl;
    DECL_ID		*var_decl_id;

    /* Create new context */
    new_context(DO, (TOKEN *) NULL);

    out_white_space(first_token);

    /* Determine what kind of DO statement */
    token_class = get_token(&token);

    switch (token_class) {

    case END_OF_LINE :
        /* DO; */
        out_white_space(&token);
        out_char('{');			/* } for dumb vi */
        parse_to_end();
        break;

    case IDENTIFIER :
        /* DO counter = start TO limit BY step */
        out_str("for");
        out_must_white(&token);
        out_char('(');

        /* Put full variable in var_string */
        var_string[0] = '\0';
        temp_out_string = out_string;
        out_string = var_string;
        token_class = parse_variable(&token, &var_decl, &var_decl_id);
        out_string = temp_out_string;

        /* Check for '=' */
        if ((token_class != OPERATOR) ||
                (token.token_type != EQUAL)) {
            parse_error("Missing '='");
            pop_context();
            return;
        }
        /* Send <ident> '=' <expr> */
        out_str(var_string);
        out_token(&token);
        token_class = parse_expression(&token);
        if ((token_class != RESERVED) ||
                (token.token_type != TO)) {
            parse_error("Missing TO");
            pop_context();
            return;
        }

        /* Send <ident> <= <limit> */
        out_str("; ");
        out_str(var_string);
        out_str(" <=");
        token_class = parse_expression(&token);
        out_str("; ");

        /* Parse increment */
        if ((token_class == RESERVED) &&
                (token.token_type == BY)) {

            /* Send <ident> += <step> */
            out_str(var_string);
            out_str(" +=");
            token_class = parse_expression(&token);
        } else {
            /* Send <ident>++ */
            out_str(var_string);
            out_str("++");
        }

        out_str(") {");		/* } for dumb vi */
        out_white_space(&token);

        if (token_class != END_OF_LINE) {
            parse_error("BY or ';' expected");
            pop_context();
            return;
        }

        parse_to_end();
        break;

    case RESERVED :
        switch (token.token_type) {

        case CASE :
            /* DO CASE <expr>; */
            out_str("switch (");
            if (parse_expression(&token) != END_OF_LINE) {
                parse_error("';' expected");
                pop_context();
                return;
            }
            out_white_space(&token);
            out_str(") {");		/* } for dumb vi */

            case_line = 0;
            while (1) {
                /* Place case statement in out_string */
                temp_out_string1 = out_string;
                case_output[0] = '\0';
                out_string = case_output;

                (void) snprintf(case_statement, sizeof(case_statement), "case %d :",
                                case_line++);
                token_class = parse_new_statement();
                if (token_class == END_OF_FILE) {
                    parse_error("Premature end-of-file");
                    exit(1);
                }
                if (token_class == END) {
                    out_string = temp_out_string1;
                    out_str(case_output);
                    break;
                }
                out_string = temp_out_string1;
                out_white_space(first_token);
                out_str(case_statement);
                out_str(case_output);
                out_white_space(first_token);
                out_str("break;\n");
            }
            break;

        case WHILE :
            /* DO WHILE <expr>; */
            out_str("while (");
            if (parse_expression(&token) != END_OF_LINE) {
                parse_error("';' expected");
                pop_context();
                return;
            }
            out_white_space(&token);
            out_str(") {");		/* } for dumb vi */

            parse_to_end();
            break;

        default:
            parse_error("Illegal DO clause");
            pop_context();
            return;
        }
        break;
    }

    /* End of context */
    pop_context();
}
Example #21
0
/*
 *	Parse statement starting with an identifier.
 *	Possibilities include:
 *		Assignment
 *		Procedure statement
 */
void
parse_identifier(TOKEN *first_token)
{
    TOKEN		token, next_token;
    TOKEN		param_token, attrib_token, type_token;
    int		token_class, next_token_class;
    DECL		*decl_list, *extra_decl_list;
    PARAM_LIST	*param_list, *param_ptr;
    DECL_MEMBER	*decl_ptr;
    DECL_ID		*decl_id;
    BOOLEAN		extern_proc, got_type, interrupt_proc;
    char		*tmp_text_ptr;

    /* Check for label or procedure */
    tmp_text_ptr = text_ptr;
    token_class = get_token(&token);

    if (token_class == LABEL) {
        /* Determine if label or procedure definition */
        next_token_class = get_token(&next_token);
        if ((next_token_class == RESERVED) &&
                (next_token.token_type == PROCEDURE)) {
            /*
             *	Procedure - Check for parameter list
             */
            param_list = NULL;
            token_class = get_token(&param_token);
            if (token_class == LEFT_PAREN) {
                /* Yes - get parameter list */
                get_param_list(&param_list);

                /* Get token after parameter list */
                token_class = get_token(&attrib_token);
            } else
                /* No param list - save as attribute */
                token_copy(&param_token, &attrib_token);

            out_white_space(first_token);
            extern_proc = FALSE;
            interrupt_proc = FALSE;

            got_type = (token_class == RESERVED) &&
                       (attrib_token.token_type >= BYTE) &&
                       (attrib_token.token_type <= SELECTOR);
            if (got_type) {
                /*
                 *	Process [ <type> ]
                 */
                token_copy(&attrib_token, &type_token);
                token_class = get_token(&attrib_token);
            }

            while (token_class == RESERVED) {
                if (attrib_token.token_type == INTERRUPT) {
                    /*
                     *	Process [ <interrupt> ]
                     */
                    interrupt_proc = TRUE;
                    token_class = get_token(&attrib_token);
                    if (token_class == NUMERIC)
                        /* Interrupt number */
                        token_class = get_token(&attrib_token);
                } else

                    /*
                     *	Process [ EXTERNAL |  { [ PUBLIC ] [ REENTRANT ] } ]
                     */
                    if (attrib_token.token_type == EXTERNAL) {
                        out_str("extern");
                        out_must_white(&attrib_token);
                        extern_proc = TRUE;

                        token_class = get_token(&attrib_token);
                    } else

                        if ((attrib_token.token_type == PUBLIC) ||
                                (attrib_token.token_type == REENTRANT)) {
                            do {
                                if (attrib_token.token_type == PUBLIC) {
                                    /* Ignore for now */
                                    token_class = get_token(&attrib_token);
                                } else

                                    if (attrib_token.token_type == REENTRANT) {
                                        /* Ignore for now */
                                        token_class = get_token(&attrib_token);
                                    } else
                                        break;
                            } while (token_class == RESERVED);
                        } else
                            break;
            }

            if (token_class != END_OF_LINE) {
                parse_error("';' expected");
                return;
            }

            if (interrupt_proc && !extern_proc)
                parse_warning("INTERRUPT procedure declared");

            /* Create declaration for procedure */
            get_element_ptr(&decl_ptr);
            get_var_ptr(&decl_ptr->name_list);
            /* Type = PROCEDURE */
            get_token_ptr(&decl_ptr->type);
            token_copy(&next_token, decl_ptr->type);
            /* Name = procedure name */
            get_token_ptr(&decl_ptr->name_list->name);
            token_copy(first_token, decl_ptr->name_list->name);
            /* Flag if parameter list */
            if (param_list)
                decl_ptr->initialization = DATA;
            /* Add it to context */
            add_to_context(decl_ptr);

            if (got_type) {
                /* Output procedure type */
                out_token_name(&type_token);
                out_must_white(&type_token);
            }

            /* Output procedure name */
            out_token_name(first_token);

            if (extern_proc) {
                out_str("()");

                if (param_list)
                    /* Parse parameter declarations */
                    parse_param_list(param_list, &decl_list,
                                     &extra_decl_list);

                out_char(';');
                /* Eat closing 'END [<proc name>];' */
                token_class = get_token(&token);
                if ((token_class != RESERVED) ||
                        (token.token_type != END)) {
                    parse_error("END expected");
                    return;
                }

                out_white_space(&token);
                token_class = get_token(&token);
                if (token_class == IDENTIFIER) {
                    token_class = get_token(&token);
                }

                if (token_class != END_OF_LINE) {
                    parse_error("';' expected");
                }

                return;
            } else

                if (param_list) {
                    out_token(&param_token);
                    /* Output parameter list */
                    param_ptr = param_list;
                    while (param_ptr) {
                        out_token(&param_ptr->param);
                        param_ptr = param_ptr->next_param;
                        if (param_ptr)
                            out_char(',');
                    }
                    out_char(')');

                    /* Parse parameter declarations */
                    parse_param_list(param_list, &decl_list,
                                     &extra_decl_list);

                    /* Output declarations */
                    if (decl_list) {
                        out_decl(decl_list);
                        /* Add declarations to context */
                        add_decl_to_context(decl_list);
                    }

                    out_str("\n{");		/* } for dumb vi */

                    if (extra_decl_list) {
                        out_decl(extra_decl_list);
                        /* Add declarations to context */
                        add_decl_to_context(extra_decl_list);
                    }

                    /* Discard declarations */
                    free_decl(decl_list);
                    free_decl(extra_decl_list);
                } else
                    /* No parameter list */
                    out_str("()\n{");	/* } for dumb vi */

            /* Create new context */
            new_context(PROCEDURE, first_token);
            /* Parse statements to END */
            parse_to_end();
            /* Pop procedure context */
            pop_context();
        } else {
            /*
             *	Label - add label name
             */
            out_token(first_token);
            /* Add colon */
            out_token(&token);

            /* Is this a defined label or a module? */
            if (find_symbol(first_token, &decl_ptr, &decl_id)) {
                if (decl_ptr->type->token_class == LABEL) {
                    /* Label - new context */
                    new_context(MODULE, first_token);
                    parse_statement(&next_token);
                    pop_context();
                } else {
                    parse_error("Illegal label name");
                    return;
                }
            } else
                parse_statement(&next_token);
        }
        return;
    }

    /* Assignment statement */
    text_ptr = tmp_text_ptr;
    token_copy(first_token, &token);
    token_class = parse_variable(&token, &decl_ptr, &decl_id);

    /* Check for multiple assignments */
    while (token_class == COMMA) {
        /* Print ' =' instead of ',' */
        out_str(" =");
        out_white_space(&token);
        /* Get identifier part of next assignment variable */
        token_class = get_token(&token);
        if (token_class != IDENTIFIER) {
            parse_error("Illegal assignment");
            return;
        }

        /* Parse remainder of variable (if any) */
        token_class = parse_variable(&token, &decl_ptr, &decl_id);
    }

    if (token_class == OPERATOR) {
        if (token.token_type != EQUAL) {
            parse_error("Illegal use of identifier");
            return;
        }

        out_token(&token);

        /* Check for POINTER assignment */
        if (decl_ptr->type->token_type == POINTER) {
            /* Yes - cast it */
            out_str(" (");
            out_str(TYPE_POINTER);
            out_str(" *) ");
        }

        if (parse_expression(&token) != END_OF_LINE)
            parse_error("';' expected");
        else
            out_token(&token);
        return;
    } else

        if (token_class != LABEL) {
            parse_error("Illegal use of identifier");
            return;
        }

}
Example #22
0
static atom_p parse_list(parsebuf_p pb, expression_callback_t out, int indentation)
{
  int c, i, terminator;
  atom_p first, prev, curr;
  struct __operator * operator;
  parsebuf_t buf;
  DEBUG();

  // Grab the opening parenthesis, or whatever it is
  __consume_whitespace(pb);
  __parsebuf_snapshot(pb, &buf);
  if((c = __parsebuf_next(pb)) == '(') {
    terminator = ')';
  } else if(c == '[') {
    terminator = ']';
  } else if(c == '<') {
    terminator = '>';
  } else if(c == '{') {
    terminator = '}';
  } else {
    splinter_error_return(NULL, "%s invalid list opening @ %d:%d", buf.n, buf.l, buf.c);
  }

  __consume_whitespace(pb);
  if ((operator = __find_closest_token(pb, terminator)) == NULL)
    return NULL;

  __parse_out_indentation(out, indentation);
  __parse_out_char(out, c);
  __parse_out_string(out, operator->token, (int)strlen(operator->token));

  for(first = prev = curr = NULL; 1;) {
    __consume_whitespace(pb);
    i = pb->i;
    __parse_out_char(out, '\n');
    if((c = __parsebuf_next(pb)) <= 0) {
      splinter_error_set("%s missing list closing @ %d:%d", buf.n, pb->l, pb->c);
      return atom_free(first);
    } else if(c == terminator) {
      if ((curr = atom_alloc_list(operator->exec_call, first)) == NULL) {
        return atom_free(first);
      }
      __parse_out_indentation(out, indentation);
      __parse_out_char(out, terminator);
      return curr;
    } else if(c == '0' && (__parsebuf_peek(pb) == 'x' || __parsebuf_peek(pb) == 'X')) {
      __parsebuf_prev(pb);
      curr = parse_hex(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if('0' <= c && c <= '9') {
      __parsebuf_prev(pb);
      curr = (c == '0') ? parse_oct(pb, operator->mode) : parse_uint(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '-' && ('0' <= __parsebuf_peek(pb) && __parsebuf_peek(pb) <= '9')) {
      __parsebuf_prev(pb);
      curr = parse_int(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '(' || c == '[' || c == '<' || c == '{') {
      __parsebuf_prev(pb);
      curr = parse_list(pb, out, indentation + 2);
    } else if(c == '\'') {
      curr = parse_string(pb, '\'', operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '"') {
      curr = parse_string(pb, '"', operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if (c == '$') {
      __parsebuf_prev(pb);
      curr = parse_variable(pb, terminator, operator->mode);
      if (curr != NULL) __parse_out_line(out, (char *)curr->data, strlen((char *)curr->data), indentation + 2);
    } else if (c == '@') {
      __parsebuf_prev(pb);
      curr = parse_symbol(pb, terminator, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else {
      curr = NULL;
    }

    if(curr == NULL) {
      return atom_free(first);
    }

    if(first == NULL) {
      first = prev = curr;
    } else {
      prev->next = curr;
      prev = curr;
    }
  }
}
Example #23
0
int
cmd_t_test (struct lexer *lexer, struct dataset *ds)
{
  bool ok;
  const struct dictionary *dict = dataset_dict (ds);
  struct tt tt;
  int mode_count = 0;

  /* Variables pertaining to the paired mode */
  const struct variable **v1 = NULL;
  size_t n_v1;
  const struct variable **v2 = NULL;
  size_t n_v2;
	  
  size_t n_pairs = 0;
  vp *pairs = NULL;


  /* One sample mode */
  double testval = SYSMIS;

  /* Independent samples mode */
  const struct variable *gvar;
  union value gval0;
  union value gval1;
  bool cut = false;

  tt.wv = dict_get_weight (dict);
  tt.dict = dict;
  tt.confidence = 0.95;
  tt.exclude = MV_ANY;
  tt.missing_type = MISS_ANALYSIS;
  tt.n_vars = 0;
  tt.vars = NULL;
  tt.mode = MODE_undef;

  lex_match (lexer, T_EQUALS);

  for (; lex_token (lexer) != T_ENDCMD; )
    {
      lex_match (lexer, T_SLASH);
      if (lex_match_id (lexer, "TESTVAL"))
	{
	  mode_count++;
	  tt.mode = MODE_SINGLE;
	  lex_match (lexer, T_EQUALS);
	  lex_force_num (lexer);
	  testval = lex_number (lexer);
	  lex_get (lexer);
	}
      else if (lex_match_id (lexer, "GROUPS"))
	{
	  mode_count++;
	  cut = false;
	  tt.mode = MODE_INDEP;
	  lex_match (lexer, T_EQUALS);

	  if (NULL == (gvar = parse_variable (lexer, dict)))
	    goto parse_failed;
      
	  if (lex_match (lexer, T_LPAREN))
	    {

	      value_init (&gval0, var_get_width (gvar));
	      parse_value (lexer, &gval0, gvar);
	      cut = true;
	      if (lex_match (lexer, T_COMMA))
		{
		  value_init (&gval1, var_get_width (gvar));
		  parse_value (lexer, &gval1, gvar);
		  cut = false;
		}

	      lex_force_match (lexer, T_RPAREN);
	    }
	  else
	    {
	      value_init (&gval0, 0);
	      value_init (&gval1, 0);
	      gval0.f = 1.0;
	      gval1.f = 2.0;
	      cut = false;
	    }

	  if ( cut == true && var_is_alpha (gvar))
	    {
	      msg (SE, _("When applying GROUPS to a string variable, two "
			 "values must be specified."));
	      goto parse_failed;
	    }
	}
      else if (lex_match_id (lexer, "PAIRS"))
	{
	  bool with = false;
	  bool paired = false;

	  if (tt.n_vars > 0)
	    {
	      msg (SE, _("VARIABLES subcommand may not be used with PAIRS."));
	      goto parse_failed;
	    }

	  mode_count++;
	  tt.mode = MODE_PAIRED;
	  lex_match (lexer, T_EQUALS);

	  if (!parse_variables_const (lexer, dict,
				      &v1, &n_v1,
				      PV_NO_DUPLICATE | PV_NUMERIC))
	    goto parse_failed;

	  if ( lex_match (lexer, T_WITH))
	    {
	      with = true;
	      if (!parse_variables_const (lexer, dict,
					  &v2, &n_v2,
					  PV_NO_DUPLICATE | PV_NUMERIC))
		goto parse_failed;

	      if (lex_match (lexer, T_LPAREN)
		  && lex_match_id (lexer, "PAIRED")
		  && lex_match (lexer, T_RPAREN))
		{
		  paired = true;
		  if (n_v1 != n_v2)
		    {
		      msg (SE, _("PAIRED was specified but the number of variables "
				 "preceding WITH (%zu) did not match the number "
				 "following (%zu)."),
			   n_v1, n_v2);
		      goto parse_failed;
		    }
		}
	    }
	  {
	    int i;

	    if ( !with )
	      n_pairs = (n_v1 * (n_v1 - 1)) / 2.0;
	    else if ( paired )
	      n_pairs = n_v1;
	    else
	      n_pairs = n_v1 * n_v2;
	  
	    pairs = xcalloc (n_pairs, sizeof *pairs);

	    if ( with)
	      {
		int x = 0;
		if (paired)
		  {
		    for (i = 0 ; i < n_v1; ++i)
		      {
			vp *pair = &pairs[i];
			(*pair)[0] = v1[i];
			(*pair)[1] = v2[i];
		      }	
		  }
		else
		  {
		    for (i = 0 ; i < n_v1; ++i)
		      {
			int j;
			for (j = 0 ; j < n_v2; ++j)
			  {
			    vp *pair = &pairs[x++];
			    (*pair)[0] = v1[i];
			    (*pair)[1] = v2[j];
			  }
		      }
		  }
	      }
	    else
	      {
		int x = 0;
		for (i = 0 ; i < n_v1; ++i)
		  {
		    int j;

		    for (j = i + 1 ; j < n_v1; ++j)
		      {
			vp *pair = &pairs[x++];
			(*pair)[0] = v1[i];
			(*pair)[1] = v1[j];
		      }
		  }
	      }

	  }
	}
      else if (lex_match_id (lexer, "VARIABLES"))
	{
	  if ( tt.mode == MODE_PAIRED)
	    {
	      msg (SE, _("VARIABLES subcommand may not be used with PAIRS."));
	      goto parse_failed;
	    }

	  lex_match (lexer, T_EQUALS);

	  if (!parse_variables_const (lexer, dict,
				      &tt.vars,
				      &tt.n_vars,
				      PV_NO_DUPLICATE | PV_NUMERIC))
	    goto parse_failed;
	}
      else if ( lex_match_id (lexer, "MISSING"))
	{
          lex_match (lexer, T_EQUALS);
          while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH)
            {
	      if (lex_match_id (lexer, "INCLUDE"))
		{
		  tt.exclude = MV_SYSTEM;
		}
	      else if (lex_match_id (lexer, "EXCLUDE"))
		{
		  tt.exclude = MV_ANY;
		}
	      else if (lex_match_id (lexer, "LISTWISE"))
		{
		  tt.missing_type = MISS_LISTWISE;
		}
	      else if (lex_match_id (lexer, "ANALYSIS"))
		{
		  tt.missing_type = MISS_ANALYSIS;
		}
	      else
		{
                  lex_error (lexer, NULL);
		  goto parse_failed;
		}
	      lex_match (lexer, T_COMMA);
	    }
	}
      else if (lex_match_id (lexer, "CRITERIA"))
	{
          lex_match (lexer, T_EQUALS);
	  if ( lex_force_match_id (lexer, "CIN"))
	    if ( lex_force_match (lexer, T_LPAREN))
	      {
		lex_force_num (lexer);
		tt.confidence = lex_number (lexer);
		lex_get (lexer);
		lex_force_match (lexer, T_RPAREN);
	      }
	}
      else 
	{
	  lex_error (lexer, NULL);
	  goto parse_failed;
	}
    }

  if ( mode_count != 1)
    {
      msg (SE, _("Exactly one of TESTVAL, GROUPS and PAIRS subcommands "
		 "must be specified."));
      goto parse_failed;
    }

  if (tt.n_vars == 0 && tt.mode != MODE_PAIRED)
    {
      lex_sbc_missing ("VARIABLES");
      goto parse_failed;
    }



  /* Deal with splits etc */
  {
    struct casereader *group;
    struct casegrouper *grouper = casegrouper_create_splits (proc_open (ds), dict);

    while (casegrouper_get_next_group (grouper, &group))
      {
	if ( tt.mode == MODE_SINGLE)
	  {
	    if ( tt.missing_type == MISS_LISTWISE )
	      group  = casereader_create_filter_missing (group,
							 tt.vars, tt.n_vars,
							 tt.exclude,
							 NULL,  NULL);
	    one_sample_run (&tt, testval, group);
	  }
	else if ( tt.mode == MODE_PAIRED)
	  {
	    if ( tt.missing_type == MISS_LISTWISE )
	      {
		group  = casereader_create_filter_missing (group,
							   v1, n_v1,
							   tt.exclude,
							   NULL,  NULL);
		group  = casereader_create_filter_missing (group,
							   v2, n_v2,
							   tt.exclude,
							   NULL,  NULL);
	      }

	    paired_run (&tt, n_pairs, pairs, group);
	  }
	else /* tt.mode == MODE_INDEP */
	  {
	    if ( tt.missing_type == MISS_LISTWISE )
	      {
		group  = casereader_create_filter_missing (group,
							   tt.vars, tt.n_vars,
							   tt.exclude,
							   NULL,  NULL);

		group  = casereader_create_filter_missing (group,
							   &gvar, 1,
							   tt.exclude,
							   NULL,  NULL);

	      }

	    indep_run (&tt, gvar, cut, &gval0, &gval1, group);
	  }
      }

    ok = casegrouper_destroy (grouper);
    ok = proc_commit (ds) && ok;
  }

  free (pairs);
  free (v1);
  free (v2);

  free (tt.vars);

  return ok ? CMD_SUCCESS : CMD_FAILURE;

 parse_failed:
  return CMD_FAILURE;
}
Example #24
0
static xtk_widget_t*
create_skinned_list(xtk_widget_t *win, skin_t *skin, tcconf_section_t *sec,
                    tchash_table_t *parameters)
{
    int x, y;
    int width, height;
    int i=0;
    char *action = NULL;
    widget_data_t *wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free);
    xtk_widget_t *l;
    int disable = 0;
    int alpha = 0xff, calpha = 0xff;
    char *font, *color, *ccolor = NULL;
    tcconf_section_t *bfnt = NULL;
    tcconf_section_t *fig = NULL;
    int rows, spacing;
    int xs, ys;

    i += tcconf_getvalue(sec, "position", "%d %d", &x, &y);
    i += tcconf_getvalue(sec, "size", "%d %d", &width, &height);

    if((bfnt = tcconf_getsection(sec, "bitmap"))){
        tcconf_setvalue(bfnt, "path", "%s", skin->path);
        i++;
    } else if(tcconf_getvalue(sec, "font", "%s", &font) == 1){
        i++;
    }

    i += tcconf_getvalue(sec, "color", "%s %d", &color, &alpha) > 0;
    i += tcconf_getvalue(sec, "spacing", "%d", &spacing);
    i += tcconf_getvalue(sec, "rows", "%d", &rows);

    if(i != 8){
        return NULL;
    }

    tcconf_getvalue(sec, "current-color", "%s %d", &ccolor, &calpha);

    fig = tcconf_getsection(sec, "background_figure");

    tcconf_getvalue(sec, "action", "%s", &action);

    wd->action = action;
    wd->skin = tcref(skin);
    wd->values = calloc(1, sizeof(char *));

    l = xtk_widget_list_create(win, x, y, width, height);

    if(tcconf_getvalue(sec, "scroll", "%d %d", &xs, &ys) == 2) {
        xtk_widget_list_set_scroll(l, xs, ys);
    }

    if(fig != NULL) {
        tcconf_setvalue(fig, "position", "%d %d", 0, 0);
        tcconf_setvalue(fig, "size", "%d %d", width, height);

        image_t *img = draw_figure(fig);

        xtk_widget_list_set_image(l, img);

        tcfree(img);

        tcfree(fig);
    }

    xtk_widget_list_set_data(l, wd);
    xtk_widget_list_set_action(l, lookup_action);

    if(l) {
        void *c = NULL;
        char *value, *variable;

        if(bfnt){
            xtk_widget_list_set_bitmapfont(l, bfnt);
            tcfree(bfnt);
        } else {
            xtk_widget_list_set_font(l, font);
            free(font);
        }

        xtk_widget_list_set_color(l, color, alpha);
        free(color);

        if(ccolor) {
            xtk_widget_list_set_current_color(l, ccolor, calpha);
            free(ccolor);
        }

        xtk_widget_list_set_spacing(l, spacing);

        xtk_widget_list_set_rows(l, rows);

        while(i = tcconf_nextvalue(sec, "value", &c, "%s %s",
                                   &variable, &value), c) {
            if(i == 2) {
                if(strcmp(variable, "current_position") == 0) {
                    int *val = NULL, *def = NULL;
                    int p;

                    save_varcb(l, list_set_current, "integer", value);
                    register_varwidget(l, list_set_current, "integer",
                                       value);

                    parse_variable("integer", value, (void *)&val,
                                   (void *)&def);
                    if(!val) {
                        if(def) {
                            p = *def;
                            tcfree(def);
                        }
                        val = &p;
                    }

                    list_set_current(l, val);
                } else if(strcmp(variable, "number_of_entries") == 0) {
                    int *val = NULL, *def = NULL;
                    int p;

                    save_varcb(l, list_set_number_of_entries, "integer",
                               value);
                    register_varwidget(l, list_set_number_of_entries,
                                       "integer", value);

                    parse_variable("integer", value, (void *)&val,
                                   (void *)&def);
                    if(!val) {
                        if(def) {
                            p = *def;
                            tcfree(def);
                        }
                        val = &p;
                    }

                    list_set_number_of_entries(l, val);
                } else if(strcmp(variable, "entries") == 0) {
                    void *val = NULL;

                    save_varcb(l, list_set_entries, "string_array",
                               value);
                    register_varwidget(l, list_set_entries,
                                       "string_array", value);

                    parse_variable("string_array", value, &val, NULL);
                    if(val) {
                        list_set_entries(l, val);
                        tcfree(val);
                    }
                }
                free(value);
                free(variable);
            }
        }

        l->on_destroy = destroy_skinned_list;
        if(disable) xtk_widget_disable(l);
    }

    return l;
}
Example #25
0
int git_config_parse(
	git_config_parser *parser,
	git_config_parser_section_cb on_section,
	git_config_parser_variable_cb on_variable,
	git_config_parser_comment_cb on_comment,
	git_config_parser_eof_cb on_eof,
	void *data)
{
	git_parse_ctx *ctx;
	char *current_section = NULL, *var_name, *var_value;
	int result = 0;

	ctx = &parser->ctx;

	skip_bom(ctx);

	for (; ctx->remain_len > 0; git_parse_advance_line(ctx)) {
		const char *line_start = parser->ctx.line;
		size_t line_len = parser->ctx.line_len;
		char c;

		if (git_parse_peek(&c, ctx, GIT_PARSE_PEEK_SKIP_WHITESPACE) < 0 &&
		    git_parse_peek(&c, ctx, 0) < 0)
			continue;

		switch (c) {
		case '[': /* section header, new section begins */
			git__free(current_section);
			current_section = NULL;

			if ((result = parse_section_header(parser, &current_section)) == 0 && on_section) {
				result = on_section(parser, current_section, line_start, line_len, data);
			}
			break;

		case '\n': /* comment or whitespace-only */
		case ' ':
		case '\t':
		case ';':
		case '#':
			if (on_comment) {
				result = on_comment(parser, line_start, line_len, data);
			}
			break;

		default: /* assume variable declaration */
			if ((result = parse_variable(parser, &var_name, &var_value)) == 0 && on_variable) {
				result = on_variable(parser, current_section, var_name, var_value, line_start, line_len, data);
			}
			break;
		}

		if (result < 0)
			goto out;
	}

	if (on_eof)
		result = on_eof(parser, current_section, data);

out:
	git__free(current_section);
	return result;
}
Example #26
0
int process_POST(unsigned short data_index, unsigned short data_len) {
  int i=0;
  int j;

  char value[200];
  char to[50], subject[50], message[200];

  #if debug_web_processpost
    printf("POST: DataIndex %d - Data Len %d\r\n", data_index, data_len);
  #endif

  while(i < data_len) {
    if (rx_buf[data_index+i]=='\r') {
      if (rx_buf[data_index+i+1]=='\n' &&
	  rx_buf[data_index+i+2]=='\r' &&
	  rx_buf[data_index+i+3]=='\n') {

        i += 4;
	break;
      }else {
	i += 4;
      }
    }else {
      i++;
    }
  }

#if debug_web_processpost
  j = i;
  printf("POST data: ");
  while(j < data_len) {								
    printf("%c", rx_buf[data_index+j]);
    j++;
  }
  printf("\r\n");
#endif

  if (parse_variable(&rx_buf[data_index+i], "mail", data_len-i, value)) {
    if (!memcmp(value, "Send", 4)) {
      if (parse_variable(&rx_buf[data_index+i], "to", data_len-i, value)) {
	strcpy(to, value);
      }
      if (parse_variable(&rx_buf[data_index+i], "subject", data_len-i, value)) {
	strcpy(subject, value);
      }
      if (parse_variable(&rx_buf[data_index+i], "message", data_len-i, value)) {
        memcpy(message,value,200);
      }
     // smtp_sendmail(to, subject, message,0,0);
      return 1;
    }
  }
#if 1
  if (parse_variable(&rx_buf[data_index+i], "options", data_len-i, value)) {	
    if (!strcmp(value, "Start")) {
      if (state == STOP) {
        state = STARTED;
	app_process();
      }
    }
    cycle = 0;
    if (parse_variable(&rx_buf[data_index+i], "cycle", data_len-i, value)) {	
      if (!strcmp(value, "Cycle"))
        cycle = 1;			
    }
    autorefresh = 0;
    if (parse_variable(&rx_buf[data_index+i], "autorefresh", data_len-i, value)) {	
      if (!strcmp(value, "Autorefresh"))
	autorefresh = 1;			
    }
    if (parse_variable(&rx_buf[data_index+i], "refreshtime", data_len-i, value)) {	
      if (value[1]==0) {
	value[1] = value[0];
	value[0] = 0x30;
      }
      refreshtime = (value[0]-0x30)*10 + (value[1]-0x30);
    }
    return 1;
  }

  if (parse_variable(&rx_buf[data_index+i], "send", data_len-i, value)) {	
    if (!memcmp(value, "Cancel", 6))	
      return 0;	
  }
  led_enable = 0;
  if (parse_variable(&rx_buf[data_index+i], "led", data_len-i, value)) {
    if (!strcmp(value, "on"))
    {
      led_enable = 1;
	  ledappOn();
	  printf("jack lee led on\n");
    }
	else
		{
			ledappOff();
			printf("jack lee led off\n");
	}
  }
  if (parse_variable(&rx_buf[data_index+i], "dow", data_len-i, value)) {
    for(j=0;j<7;j++) {
      if (strcmp(dow[j],value)==0) {
        DOW = j;
	break;
      }
    }
  }
  if (parse_variable(&rx_buf[data_index+i], "month", data_len-i, value)) {
    for(j=0;j<12;j++) {
      if (strcmp(month[j],value)==0) {
        MONTH = j+1;
	break;
      }
    }
  }
  if (parse_variable(&rx_buf[data_index+i], "dom", data_len-i, value)) {
    DOM = (value[0]-0x30)*10 + (value[1]-0x30);
  }
  if (parse_variable(&rx_buf[data_index+i], "year", data_len-i, value)) {
    YEAR = (value[0]-0x30)*1000 + (value[1]-0x30)*100 + (value[2]-0x30)*10 + (value[3]-0x30);
  }
  if (parse_variable(&rx_buf[data_index+i], "hour", data_len-i, value)) {
    HOUR = (value[0]-0x30)*10 + (value[1]-0x30);
  }
  if (parse_variable(&rx_buf[data_index+i], "min", data_len-i, value)) {
    MIN = (value[0]-0x30)*10 + (value[1]-0x30);
  }
  if (parse_variable(&rx_buf[data_index+i], "sec", data_len-i, value)) {
    SEC = (value[0]-0x30)*10 + (value[1]-0x30);
  }

  #endif
  return 1;
}
Example #27
0
/** parse_assignment         parse an assignment statement.
 *
 * NOTE:
 *      Just calls parse_variable; This is because expressions are fully
 *      recursive.
 *
 * @param p_target_id : ptr to target id's symbol table node
 * @return ptr to the p_target_id type object.
 */
cx_type *cx_parser::parse_assignment(const cx_symtab_node *p_target_id) {

    cx_type *p_target_type = parse_variable(p_target_id);

    return p_target_type;
}
Example #28
0
main()
{
  char buf[256];
  while (gets(buf)) parse_variable(buf);
}
Example #29
0
static xtk_widget_t*
create_skinned_seek_bar(xtk_widget_t *win, skin_t *skin, tcconf_section_t *sec,
                        tchash_table_t *parameters)
{
    int x, y;
    int sp_x, sp_y;
    int ep_x, ep_y;
    int xd=0, yd=0, sx=0, sy=0;
    char *bg, *indicator, *value, *variable, *ind_over = NULL,
        *ind_down = NULL;
    int i=0;
    char *action = NULL;
    widget_data_t *wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free);
    double *position = NULL, *def = NULL, p=0, snap;
    xtk_widget_t *s;
    int disable = 0;
    image_t *img;

    i += tcconf_getvalue(sec, "position", "%d %d", &x, &y);
    i += tcconf_getvalue(sec, "start_position", "%d %d", &sp_x, &sp_y);
    i += tcconf_getvalue(sec, "end_position", "%d %d", &ep_x, &ep_y);
    i += tcconf_getvalue(sec, "background", "%s", &bg);
    i += tcconf_getvalue(sec, "indicator", "%s", &indicator);
    i += tcconf_getvalue(sec, "value", "%s %s", &variable, &value);

    if(i != 10){
        return NULL;
    }

    tcconf_getvalue(sec, "action", "%s", &action);
    tcconf_getvalue(sec, "mouse_over", "%s", &ind_over);
    tcconf_getvalue(sec, "pressed", "%s", &ind_down);
    tcconf_getvalue(sec, "scroll_direction", "%d %d %d %d", &xd, &yd,
                    &sx, &sy);
    parse_variable("double", value, (void *)&position, (void *)&def);
    if(!position) {
        if(def) {
            p = *def;
            tcfree(def);
        }
        position = &p;
    } else if(*position < 0 || *position > 1) {
        disable = 1;
    }

    wd->action = action;
    wd->value = value;
    wd->skin = tcref(skin);

    img = load_image(skin->path, bg);
    s = xtk_widget_slider_create(win, x, y, img->params.width[0],
                                 img->params.height[0]);
    xtk_widget_slider_set_image(s, img);
    tcfree(img);

    xtk_widget_slider_set_data(s, wd);
    xtk_widget_slider_set_action(s, lookup_action);
    xtk_widget_slider_set_position(s, *position);
    xtk_widget_slider_set_bounds(s, sp_x, sp_y, ep_x, ep_y);
    xtk_widget_slider_set_scroll_direction(s, xd, yd, sx, sy);

    if(tcconf_getvalue(sec, "snap", "%lf", &snap) == 1) {
        xtk_widget_slider_set_snap(s, snap);
    }

    img = load_image(skin->path, indicator);
    xtk_widget_slider_set_indicator_image(s, img);
    tcfree(img);

    img = load_image(skin->path, ind_over);
    xtk_widget_slider_set_indicator_image_hover(s, img);
    if(img)
        tcfree(img);

    img = load_image(skin->path, ind_down);
    xtk_widget_slider_set_indicator_image_pressed(s, img);
    if(img)
        tcfree(img);

    if(s) {
        if(strcmp(variable, "position") == 0) {
            register_varwidget((xtk_widget_t *)s, seek_bar_update,
                               "double", wd->value);
        }
        free(variable);
        s->on_destroy = destroy_skinned_seek_bar;
        if(disable) xtk_widget_disable(s);
    }

    free(ind_over);
    free(ind_down);
    free(indicator);
    free(bg);

    return s;
}
Example #30
0
/*
 *	CALL statement
 *	Handles CALL <procedure name> [ ( <parameter list> ) ] ;
 */
void
parse_call(TOKEN *first_token)
{
    TOKEN		token;
    int		token_class;
    DECL_MEMBER	*id_type;
    DECL_ID		*id_id;
    char		*new_func, *tmp_out_string;
    char		func_name[MAX_TOKEN_LENGTH];

    /* Get procedure name */
    token_class = get_token(&token);
    if (token_class != IDENTIFIER) {
        parse_error("Illegal procedure name");
        return;
    }

    out_white_space(first_token);

    /* Check for function conversion */
    if (check_cvt_id(&token, &cvt_functions[0], &new_func)) {
        out_str(new_func);
        token_class = get_token(&token);
    } else

        if (find_symbol(&token, &id_type, &id_id) &&
                (id_type->type->token_type != PROCEDURE)) {

            /* Skip white space */
            token.white_space_start = token.white_space_end;

            /* Check for call to pointer */
            func_name[0] = '\0';
            tmp_out_string = out_string;
            out_string = func_name;
            token_class = parse_variable(&token, &id_type, &id_id);
            out_string = tmp_out_string;

            if ((id_type->type->token_type == POINTER) ||
#ifdef OFFSET
                    (id_type->type->token_type == OFFSET) ||
#endif
                    (id_type->type->token_type == WORD)) {
                /* Yes - use pointer reference */
                out_str("(*");
                out_str(func_name);
                out_char(')');
            } else {
                parse_error("Illegal procedure reference");
                return;
            }
        } else {
            out_token_name(&token);
            token_class = get_token(&token);
        }

    /* Get parameter list (if any) */
    if (token_class == LEFT_PAREN) {
        out_token(&token);

        do {
            token_class = parse_expression(&token);
            out_token(&token);
        } while (token_class == COMMA);

        if (token_class == RIGHT_PAREN)
            /* Get end of line */
            check_eol();
        else
            parse_error("Illegal parameter list seperator");
    } else

        if (token_class == END_OF_LINE) {
            /* No parameter list */
            out_str("()");
            out_token(&token);
        } else
            parse_error("';' expected");
}