Ejemplo n.º 1
0
Archivo: main.c Proyecto: Dioxylin/shs
void program_loop()
{
	char *line = NULL;
	size_t line_size = 0;
	int start_from = 0;
	char *token = NULL;

	while(true) {
		printf("%d > ", num_stack_items());
		line_size = getline(&line, &line_size, stdin);
		if (line_size == -1) break;

		while (true) {
			token = get_next_token(line, line_size, &start_from);
			if (token == NULL) {
				break;
			}
			else if (strcmp(token, ".s") == 0) {
				stack_show();
				continue;
			}
			else if (strcmp(token, ".") == 0) {
				stack_dot();
				continue;
			}
			else if (strcmp(token, ".dropall") == 0) {
				stack_dropall();
				continue;
			}
			else if (strcmp(token, "+") == 0) {
				stack_plus();
				continue;
			}
			else if (strcmp(token, "-") == 0) {
				stack_minus();
				continue;
			}
			else if (strcmp(token, ".swap") == 0) {
				stack_swap();
				continue;
			}
			else if (strcmp(token, ".dup") == 0) {
				stack_dup();
				continue;
			}
			else if (strcmp(token, ".over") == 0) {
				stack_over();
				continue;
			}
			else if (strcmp(token, ".drop") == 0) {
				stack_pop();
				continue;
			}
			else if (strcmp(token, ".rot") == 0) {
				stack_rot();
				continue;
			}
			else if (strcmp(token, ".-rot") == 0) {
				stack_rot();
				stack_rot();
				continue;
			}
			else if (strcmp(token, "!") == 0) {
				set_variable();
				continue;
			}
			else if (strcmp(token, "$") == 0) {
				get_variable();
				continue;
			}
			else if (token[0] == '$' && token[1] == '$') {
				eprintf("error: variable name can't begin with $.\n");
				continue;
			}
			else if (token[0] == '$' && token[1] == '.') {
				/* Put literals in for stack operations. */
				/* shift everything after $ over one */
				for (int i = 0; i < BUFSIZE-1; ++i) {
					token[i] = token[i+1];
				}
				stack_push(token);
				continue;
			}
			else if (token[0] == '$') {
				/* shift everything after $ over one */
				for (int i = 0; i < BUFSIZE-1; ++i) {
					token[i] = token[i+1];
				}
				stack_push(token);
				get_variable();
				continue;
			}
			else if (strcmp(token, ";") == 0) {
				stack_execute();
				continue;
			}
			else if (strcmp(token, ".cd") == 0) {
				stack_cd();
				continue;
			}
			else if (token[0] == '.' && strlen(token) > 1) {
				/* shift everything after . over one */
				for (int i = 0; i < BUFSIZE-1; ++i) {
					token[i] = token[i+1];
				}
				stack_push(token);
				stack_execute();
				continue;
			}
			stack_push(token);
		}
		start_from = 0;
	}
}
Ejemplo n.º 2
0
static void
swap(void)
{

	stack_swap(&bmachine.stack);
}
Ejemplo n.º 3
0
Archivo: _xpm.c Proyecto: pikelang/Pike
static rgba_group decode_color( struct buffer *s )
{
  static struct svalue _parse_color;
  static struct svalue *parse_color;
  rgba_group res;
  res.alpha = 255;

  if(!s->len)
  {
    res.r=res.g=res.b = 0;
    return res;
  }
  if(s->str[0] == '#' && s->len>3)
  {
    switch(s->len)
    {
     default:
       res.r = hextoint(s->str[1])*0x10;
       res.g = hextoint(s->str[2])*0x10;
       res.b = hextoint(s->str[3])*0x10;
       break;
     case 7:
       res.r = hextoint(s->str[1])*0x10 + hextoint(s->str[2]);
       res.g = hextoint(s->str[3])*0x10 + hextoint(s->str[4]);
       res.b = hextoint(s->str[5])*0x10 + hextoint(s->str[6]);
       break;
     case 13:
       res.r = hextoint(s->str[1])*0x10 + hextoint(s->str[2]);
       res.g = hextoint(s->str[5])*0x10 + hextoint(s->str[6]);
       res.b = hextoint(s->str[9])*0x10 + hextoint(s->str[10]);
       break;
    }
    return res;
  }
  if(s->len==4&&(!strncmp(s->str,"None",4)||!strncmp(s->str,"none",4)))
  {
    res.r = res.g = res.b = 0;
    res.alpha = 0;
    return res;
  }
  if(!parse_color)
  {
    push_static_text("Image.Color");
    SAFE_APPLY_MASTER( "resolv_or_error", 1 );
    _parse_color = sp[-1];
    parse_color = &_parse_color;
    sp--;
  }
  push_svalue( parse_color );
  push_string(make_shared_binary_string(s->str,s->len));
  f_index( 2 );
  if(TYPEOF(sp[-1]) != T_OBJECT) {
    push_int(0);
    stack_swap();
  } else {
    ref_push_type_value(array_type_string);
    stack_swap();
    f_cast();
  }
  if(TYPEOF(sp[-1]) == T_ARRAY && sp[-1].u.array->size == 3)
  {
    res.r = sp[-1].u.array->item[0].u.integer;
    res.g = sp[-1].u.array->item[1].u.integer;
    res.b = sp[-1].u.array->item[2].u.integer;
  } else {
    res.r = res.g = res.b = 0;
  }
  pop_stack(); /* array */
  pop_stack(); /* object */
  return res;
}