Beispiel #1
0
static void	go_to(char *path)
{
	static char buf[4096];
	t_hash		*pwd;

	if (ft_strequ(path, "-"))
		return (go_to(hash_getset(&g_env, "OLDPWD", "/", 2)->value));
	ft_memset(buf, 0, 4096);
	if (path[0] == '~')
	{
		ft_strcat(buf, hash_getset(&g_env, "HOME", "/", 2)->value);
		ft_strcat(buf, path + 1);
		path = ft_strdup(buf);
		go_to(path);
		return (free(path));
	}
	if (access(path, F_OK) == -1)
		return (print_error("cd: ", FNOT_FOUND, path));
	if (!isdir(path))
		return (print_error("cd: ", "not a directory: ", path));
	if (access(path, R_OK) == -1)
		return (print_error("cd: ", FORBIDDEN, path));
	pwd = hash_getset(&g_env, "PWD", getcwd(buf, 4096), ft_strlen(buf) + 1);
	hash_set(&g_env, "OLDPWD", pwd->value, pwd->size);
	chdir(path);
	hash_set(&g_env, "PWD", getcwd(buf, 4096), ft_strlen(buf) + 1);
}
Beispiel #2
0
/** execute_FOR  Executes for statement.
 *          initialize   condition     increment
 *      for(<statement>; <expression>; <expression>)
 *              <statement>;
 *
 * @param p_function_id
 */
void cx_executor::execute_FOR(cx_symtab_node * p_function_id) {

    bool condition = false;

    get_token(); // for
    // get the location of where to go to if <expr> is false.
    int break_point = get_location_marker();
    get_token();
    int statement_location = get_location_marker();
    get_token();
    int condition_marker = get_location_marker();
    get_token();
    int increment_marker = get_location_marker();


    get_token();

    // (
    get_token();

    if (token != tc_semicolon) {
        // declaration would go here //
        execute_assignment(p_node);
    }

    do {
        get_token(); //  ;
        if (token != tc_semicolon) {

            // expr 2
            execute_expression();
            get_token(); //  ;
        } else get_token();

        condition = top()->basic_types.bool__;
        pop();
        if (condition) {
            go_to(statement_location);
            get_token();
            execute_statement(p_function_id);
            if (break_loop) go_to(break_point);
        } else {
            go_to(break_point);
            get_token();
            break;
        }

        go_to(increment_marker);
        get_token();
        // expr 3
        execute_expression();

        go_to(condition_marker);
    } while (current_location() == condition_marker);

    break_loop = false;
}
Beispiel #3
0
void		bi_cd(char **args)
{
	int i;

	if (!args[0])
		return (go_to(hash_getset(&g_env, "HOME", "/", 2)->value));
	i = 0;
	while (args[i])
	{
		go_to(args[i]);
		++i;
	}
}
Beispiel #4
0
/** execute_IF   Executes if statements.
 *
 *      if(<boolean expression>)
 *              <statement>;
 *      else if (<boolean expression>)
 *              <statement>;
 *      else
 *              <statement>;
 *
 * @param p_function_id : routine ID this statement is apart of.
 */
void cx_executor::execute_IF(cx_symtab_node * p_function_id) {
    //  if
    get_token();

    // get the location of where to go to if <expr> is false.
    int at_false = get_location_marker();
    get_token();

    // (
    //get_token();

    execute_expression();
    bool condition = top()->basic_types.bool__;

    // )
    //get_token();

    if (condition) {

        // True: { or single statement
        execute_statement(p_function_id);
        while (token == tc_semicolon)get_token();

        // If there is an ELSE part, jump around it.
        if (token == tc_ELSE) {
            get_token();
            go_to(get_location_marker());
            get_token(); // token following the IF statement
        }
    } else {

        // False: Go to the false location.
        go_to(at_false);
        get_token();

        if (token == tc_ELSE) {

            // ELSE <stmt-2>
            get_token();
            get_location_marker(); // skip over location marker
            // { or single statement
            get_token();
            execute_statement(p_function_id);

            while (token == tc_semicolon)get_token();
        }
    }
}
Beispiel #5
0
void	b_cd(int i, char **tab, char ***penv)
{
    struct stat sb;

    printf("in cd\n");
    if (!tab [i + 1] || (ft_strcmp(tab[i + 1], "~") == 0))
        home(penv);
    else if ((ft_strcmp(tab[i + 1], "-") == 0))
        back(penv);
    else
    {
        if (stat(tab[i + 1], &sb) == -1)
            return (ft_putstr("PB stat.\n"));
        if((sb.st_mode & S_IFMT) == S_IFDIR)
        {
            if (S_IXUSR & sb.st_mode)
                go_to(i, tab, penv);
            else
            {
                ft_putstr(tab[i + 1]);
                ft_putstr(": Permission denied.\n");
            }
        }
        else
        {
            ft_putstr(tab[i + 1]);
            ft_putstr(": No such file or directory.\n");
        }
    }
}
Beispiel #6
0
void
edit_select_rep::selection_cut (string key) {
  if (inside_active_graphics ()) {
    if (key != "none") {
      tree t= as_tree (eval ("(graphics-cut)"));
      selection_set (key, t);
    }
  }
  else if (selection_active_any ()) {
    path p1, p2;
    if (selection_active_table ()) {
      p1= start_p; p2= end_p;
      if(key != "none") {
        tree sel= selection_get ();
        selection_set (key, sel);
      }
    }
    else {
      selection_get (p1, p2);
      go_to (p2);
      if (p2 == p1) return;
      if (key != "none") {
        tree sel= selection_compute (et, p1, p2);
        selection_set (key, simplify_correct (sel));
      }
    }
    cut (p1, p2);
  }
}
Beispiel #7
0
void
edit_select_rep::selection_move () {
  observer pos= position_new (tp);
  tree t= selection_get_cut ();
  go_to (position_get (pos));
  insert_tree (t);
  position_delete (pos);
}
Beispiel #8
0
void
edit_select_rep::selection_copy (string key) {
  if (inside_active_graphics ()) {
    tree t= as_tree (eval ("(graphics-copy)"));
    selection_set (key, t);
    return;
  }
  if (selection_active_any ()) {
    path old_tp= tp;
    selection sel; selection_get (sel);
    go_to (sel->end);
    tree t= selection_get ();
    go_to (sel->start);
    selection_set (key, t);
    go_to (old_tp);
  }
}
Beispiel #9
0
void Path_button::menu_action_triggered() {
  QAction* a = dynamic_cast<QAction*>(sender());
  if (!a) {
    qWarning("Path_button::menu_action_triggered: bad sender");
    return;
  }
  emit go_to(a->data().toString());
}
Beispiel #10
0
 size_t skip_to(CHAR_T ch)
 {
   size_t pos = _pos;
   size_t length = len();
   while (pos < length && _text[pos] != ch)
     ++pos;
   go_to(pos);
   return pos;
 }
Beispiel #11
0
 /// move to the position defined by xpath in XML tree
bool const_XMLPos::go(const XPath& xpath)
{
	const XMLNode* node = xpath._absolute? _root: _cur;

	node = node->find_relative(xpath);

	if (node) {
		go_to(node);
		return true;
	} else
		return false;
}
void
edit_process_rep::generate_aux_recursively (string which, tree st, path p) {
  int i, n= N(st);
  for (i=0; i<n; i++)
    if (!is_aux (st[i])) {
      if (is_compound (st[i]))
	generate_aux_recursively (which, st[i], p * i);
    }
    else {
      tree t= st[i];
      path doc_p= p * path (i, N(t)-1);
      assign (doc_p, tree (DOCUMENT, ""));
      go_to (doc_p * path (0, 0));

      /*
	cout << "et= " << et << "\n";
	cout << "tp= " << tp << "\n";
	cout << "------------------------------------------------------\n";
      */
      if (arity (t) >= 1) {
	if ((arity(t) >= 3) &&
	    (is_compound (t, "bibliography") ||
	     is_compound (t, "bibliography*")) &&
	    ((which == "") || (which == "bibliography")))
	  generate_bibliography (as_string (t[0]), as_string (t[1]),
				 as_string (t[2]));
	if ((is_compound (t, "table-of-contents") ||
	     is_compound (t, "table-of-contents*")) &&
	    ((which == "") || (which == "table-of-contents")))
	  generate_table_of_contents (as_string (t[0]));
	if ((is_compound (t, "the-index") || is_compound (t, "the-index*")) &&
	    ((which == "") || (which == "the-index")))
	  generate_index (as_string (t[0]));
	if ((is_compound (t, "the-glossary") ||
	     is_compound (t, "the-glossary*")) &&
	    ((which == "") || (which == "the-glossary")))
	  generate_glossary (as_string (t[0]));
	if (is_compound (t, "list-of-figures") &&
	    ((which == "") || (which == "list-of-figures")))
	  generate_glossary (as_string (t[0]));
	if (is_compound (t, "list-of-tables") &&
	    ((which == "") || (which == "list-of-tables")))
	  generate_glossary (as_string (t[0]));
      }
      /*
	cout << "et= " << et << "\n";
	cout << "tp= " << tp << "\n";
	cout << "------------------------------------------------------\n\n\n";
      */
    }
}
Beispiel #13
0
bool MstcOnline::go_with(VectorPtr direction, double distance) {
  PointPtr last_position = *(--path.end());
  PointPtr new_position = last_position + direction * distance;

  //  CellPtr new_cell = IdentifiableCellPtr(
  //        new IdentifiableCell(
  //            PointPtr(
  //                new Point(new_position->x - tool_size / 2,
  //                    new_position->y + tool_size / 2)), 2 * tool_size,
  //            communicator->get_robot_name()));
  //  communicator->set_current_cell(new_cell);

  bool succeed = go_to(new_position);
  std::cout << "\n";
  return succeed;
}
Beispiel #14
0
	void PanicActor::act()
	{
		//Panicking: running from room to room, screaming.

		std::vector<Environment *> possible_moves = currentroom().neighbours();

		Environment * next_room = nullptr;
		while (true) {
			unsigned int i = std::rand() % 8;
			next_room = possible_moves[i];
			if (next_room != nullptr) {
				go_to(next_room);
				break;
			}
		}

		talk();
				

	}
Beispiel #15
0
void do_gs()
{
  unsigned size;
  int I;

  gs_ptr++;

  if(gs_ptr == 0)
  {
    size = 1;
    gosub_stack = malloc(size * sizeof(int));
  }
  else
  {
    size = gs_ptr + 1;
    gosub_stack = realloc(gosub_stack, size * sizeof(int));
  }
  line_ndx++;
  gosub_stack[gs_ptr] = line_ndx;
  go_to();
}
void
NodeManager::restore_nodes( const ArrayDatum& node_list )
{
  Subnet* root = get_cwn();
  const index gid_offset = size() - 1;
  Token* first = node_list.begin();
  const Token* end = node_list.end();
  if ( first == end )
  {
    return;
  }

  // We need to know the first and hopefully smallest GID to identify
  // if a parent is in or outside the range of restored nodes.
  // So we retrieve it here, from the first element of the node_list, assuming
  // that the node GIDs are in ascending order.
  DictionaryDatum node_props = getValue< DictionaryDatum >( *first );
  const index min_gid = ( *node_props )[ names::global_id ];

  for ( Token* node_t = first; node_t != end; ++node_t )
  {
    DictionaryDatum node_props = getValue< DictionaryDatum >( *node_t );
    std::string model_name = ( *node_props )[ names::model ];
    index model_id = kernel().model_manager.get_model_id( model_name.c_str() );
    index parent_gid = ( *node_props )[ names::parent ];
    index local_parent_gid = parent_gid;
    if ( parent_gid >= min_gid ) // if the parent is one of the restored nodes
    {
      local_parent_gid += gid_offset; // we must add the gid_offset
    }
    go_to( local_parent_gid );
    index node_gid = add_node( model_id );
    Node* node_ptr = get_node( node_gid );
    // we call directly set_status on the node
    // to bypass checking of unused dictionary items.
    node_ptr->set_status_base( node_props );
  }
  current_ = root;
}
bool FullSpiralStc::visit(CellPtr cell, Quadrant quadrant, bool flexibility) {
  PartiallyOccupiableCellPtr c = boost::static_pointer_cast<PartiallyOccupiableCell>(cell);
  c->set_current_quadrant(quadrant);
  return go_to(c->get_current_position(), flexibility);
}
Beispiel #18
0
void Path_button::slot_clicked() {
  emit go_to(uri);
}
Beispiel #19
0
void write_char_at(math::point2d position, char c){
    go_to(position);
    putchar(c);
}
Beispiel #20
0
void parser()
{
  int ab_code=4, x=line_ndx;
  int I;

  switch(token)
  {
    case 0:
      break;

    case 1:
      parse_let();
      break;
	
    case 2:
      cls();
      break;
    
    case 3:
      locate();
      break;
	
    case 4:
      xstring_array(); 
      get_prnstring(); 
      break;

    case 5:
      go_to();
      break;
	
    case 6:
      beep();
      break;
	
    case 7:
      cls();
      break;
	
    case 8:
      line_ndx = nrows;
      break;

    case 9:
      do_gs();
      break;

    case 10:
      do_ret();
      break;

    case 11:
      do_loop();
      break;

    case 12:
      do_next();
      break;

    case 13:
      do_iloop();
      break;

    case 14:
      do_iloop();
      break;
    
    case 15:
      return;
      break;

    case 16:
      return;
      break;

    case -1:
      break;

    default:
      printf("parser Inside DEFAULT\n");
      printf("p_string = %s\n",p_string);
      a_bort(ab_code, x);
      break;
  }
}
Beispiel #21
0
void Path_button::action_go_parent_triggered() {
  Directory d(core, uri);
  emit go_to(d.get_parent_uri());
}
Beispiel #22
0
void
edit_select_rep::raw_cut (path p1, path p2) {
  if (p2 == p1) return;
  path p = common (p1, p2);
  tree t = subtree (et, p);
  int  n = N(p);
  int  i1= p1[n];
  int  i2= p2[n];

  if (is_document (t) || is_concat (t)) {
    path q1= copy (p); q1 << path (i1, end (t[i1]));
    path q2= copy (p); q2 << path (i2, start (t[i2]));
    raw_cut (q2, p2);
    if (i2>i1+1) remove (p * (i1+1), i2-i1-1);
    raw_cut (p1, q1);
    if (is_concat (t)) correct_concat (p);
    else remove_return (p * i1);
    return;
  }

  if (is_func (t, TFORMAT) || is_func (t, TABLE) || is_func (t, ROW)) {
    path fp= ::table_search_format (et, p);
    tree st= subtree (et, fp);
    int row1, col1, row2, col2;
    table_search_coordinates (st, tail (p1, N(fp)), row1, col1);
    table_search_coordinates (st, tail (p2, N(fp)), row2, col2);
    if (row1>row2) { int tmp= row1; row1= row2; row2= tmp; }
    if (col1>col2) { int tmp= col1; col1= col2; col2= tmp; }

    int i, j;
    for (i=row1; i<=row2; i++)
      for (j=col1; j<=col2; j++) {
        path cp= fp * ::table_search_cell (st, i, j);
        if (is_func (subtree (et, cp), CELL, 1)) cp= cp * 0;
        assign (cp, "");
      }
    path cp= fp * ::table_search_cell (st, row1, col1);
    go_to (cp * path (0, 0));

    if (is_func (st, TFORMAT))
      table_del_format (fp, row1+1, col1+1, row2+1, col2+1, "");
    return;
  }

  if (is_compound (t) && (!is_format (t))) {
    assign (p, "");
    return;
  }

  if ((N(p1) != (N(p)+1)) || (N(p2) != (N(p)+1))) {
    cerr << "t = " << t << "\n";
    cerr << "p = " << p << "\n";
    cerr << "p1= " << p1 << "\n";
    cerr << "p2= " << p2 << "\n";
    FAILED ("invalid cut");
  }

  if (is_atomic (t)) {
    int pos= last_item (p1);
    int nr = last_item (p2)-pos;
    if (nr>0) remove (p1, nr);
  }
  else {
    if ((last_item (p1) != 0) || (last_item (p2) != 1)) {
      cerr << "t = " << t << "\n";
      cerr << "p = " << p << "\n";
      cerr << "p1= " << p1 << "\n";
      cerr << "p2= " << p2 << "\n";
      FAILED ("invalid object cut");
    }
    assign (p, "");
  }
}
Beispiel #23
0
void ai::update(const world &w, int dt)
{
    if (m_plane.expired())
        return;

    const float kdt = dt * 0.001f;

    auto p = m_plane.lock();

    vec3 next_pos = p->phys->pos + p->phys->vel * kdt;

    p->controls.mgun = false;
    p->controls.brake = 0.0f;

    if (m_state == state_pursuit)
    {
        if ((m_target.expired() || m_target.lock()->hp <= 0) && m_state != state_follow)
            m_state = state_wander;
    }

    //if (m_state != state_pursuit)
        find_best_target();

    if (!m_target.expired())
    {
        p->select_target(std::static_pointer_cast<object>(m_target.lock()));

        auto t = m_target.lock();
        auto target_pos = t->phys->pos + t->phys->vel * (dt * 0.001f);

        if (m_state == state_pursuit)
            go_to(target_pos - 20.0 * vec3::normalize(t->phys->vel), dt); //6 o'clock
        else
            go_to(target_pos, dt);
    }

    if (m_state == state_wander)
    {
        if (fabsf(p->get_pos().x) > 4096 || fabsf(p->get_pos().z) > 4096 ) //ToDo: set operation area
        {
            auto dir = p->get_dir();
            dir.y = 0;
            dir.normalize();

            if (stabilize_course(dir))
                p->controls.rot = nya_math::vec3(0.0, 1.0, 0.0);

            p->controls.throttle = 1.0;
        }
    }

    //evade ground
    const float minimal_height = 600.0f + w.get_height(next_pos.x, next_pos.z);
    if (next_pos.y < minimal_height && p->get_dir().y < 0.0f)
    {
        if (p->phys->get_speed_kmh() > 700.0f)
            p->controls.brake = 1.0f;

        p->controls.rot.x = vec3::up().dot(p->phys->rot.rotate(vec3::up())) < 0.0f ? 1.0f : -1.0f;
    }

    if (!p->targets.empty() && p->targets.front().locked)
    {
        p->controls.missile = !p->controls.missile;
        p->controls.mgun = true; //ToDo
    }
    else
        p->controls.missile = false;
}
Beispiel #24
0
void TMemo::go_to_line(int line)
{
	int ofs = line_offset(line-1);
	go_to(ofs,-1,current_line() > line ? -10 : +10);
}
Beispiel #25
0
void WebkitBrowser::on_button_home ()
{
  if (!homepage.empty()) {
    go_to (homepage);
  }
}
Beispiel #26
0
 void move(size_t off)
 {
   go_to(_pos + off);
 }
Beispiel #27
0
void WebkitBrowser::on_entry_url ()
{
  const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry_url));
  g_assert (uri);
  go_to (uri);
}
Beispiel #28
0
int main(){
    Buzzer.write(0);
    mrf.SetChannel(com_channel); 
    clock_init();
    cam_init();
    pc.baud(115200);
    State = WAITING;
    Battery_Level = Battery_Time;
    t_battery.reset();
    int start_x, start_y, y_min, y_max, dest_x;
    active = 1;
    mrf.SetChannel(15);
    for (int i=0; i<3; i++){        //load the tile it is under;
        rxLen = rf_receive(rxBuffer, 128);
        while (rxLen <= 0){
            rxLen = rf_receive(rxBuffer, 128);
        }
        sscanf(rxBuffer,"active: %d\r\n", &active);
    }
    pc.printf("the active value is: %d\r\n", active);   
    mrf.SetChannel(com_channel);
    while(1){
        switch(State){      //use a state machine to control the behavior or a slave
            default:
                State = WAITING;
                break;
            
            case 1:     //Waiting
                sprintf(txBuffer, "Ready\r\n");
                rf_send(txBuffer, strlen(txBuffer) + 1);
                robot.stop();
                rxLen = rf_receive(rxBuffer, 128);
                if (rxLen > 0){
                    int res = sscanf(rxBuffer, "%d %d %d %d %d\r\n", &start_x, &start_y, &y_min, &y_max, &dest_x);
                    if (res){
                        sprintf(txBuffer, "Yes\r\n");
                        rf_send(txBuffer, strlen(txBuffer) + 1);
                        State = WORKING;
                    }
                }else{
                    State = WAITING;
                }
                break;
            
            case 2:     //Working
                Buzzer.write(1);
                wait(0.2);
                Buzzer.write(0);
                go_to(start_x, start_y);
                Buzzer.write(1);
                wait(0.6);
                Buzzer.write(0);
                if (zig_zag(y_max, y_min, dest_x) > 0){
                    robot.stop();
                    sprintf(txBuffer, "Finished\r\n");
                    rf_send(txBuffer, strlen(txBuffer) + 1);
                    State = WAITING;
                }else{
                    robot.stop();       
                    rotate(90);
                    Locate(position);
                    sprintf(txBuffer, "Died: %3.2f,%3.2f\r\n",position[0],position[1]);
                    rf_send(txBuffer, strlen(txBuffer) + 1);
                    for (int b=0; b<3; b++){
                        Buzzer.write(1);
                        wait(0.2);
                        Buzzer.write(0);
                        wait(0.2);
                    }
                    go_to(Charging_X, Charging_Y);
                    State = CHARGING;
                }
                break;
                
            case 3:     //charging
                sprintf(txBuffer, "Charging: %d\r\n",Battery_Level);
                rf_send(txBuffer, strlen(txBuffer) + 1);
                rxLen = rf_receive(rxBuffer, 128);
                if (rxLen > 0){
                    int res = sscanf(rxBuffer, "%d %d %d %d %d\r\n", &start_x, &start_y, &y_min, &y_max, &dest_x);
                    if (res){
                        State = WORKING;
                     }
                }else{
                    State = CHARGING;
                }
                wait(1);
                Battery_Level += 3;
                if (Battery_Level >= Battery_Time){
                    Battery_Level = Battery_Time;
                    State = WAITING;
                }
                break;
        }       
    }
}