struct list_head * find_scope(node_t *node, node_t **pparent) { struct list_head *ret = &node->loc.first.pf->parsed; node_t *parent; while ( (parent = node->parent) ) { if (parent->type == nt_type && (parent->t.category == type_struct || parent->t.category == type_union) && is_child(node, parent, cht_body)) { ret = &parent->child[cht_body]; break; } else if (parent->type == nt_type && parent->t.category == type_func && is_child(node, parent, cht_param)) { parent = typed_parent(parent, nt_decl); ret = &parent->child[chd_body]; break; } else if (parent->type == nt_decl && (is_child(node, parent, chd_body) || is_child(node, parent, chd_decl)) ) { ret = &parent->child[chd_body]; break; } else if (parent->type == nt_expr && parent->e.op == BLOCK) { ret = &parent->child[che_arg1]; break; } node = parent; } if (pparent) *pparent = parent; return ret; }
/** * Gets the parent of a child window, or None if there is no such child. */ Window ClientModel::get_parent_of(Window child) { if (!is_child(child)) return None; return m_parents[child]; }
/** * Changes the current desktop to the desktop before the current. */ void ClientModel::prev_desktop() { // We have to add the maximum desktops back in, since C++ doesn't // guarantee what will happen with a negative modulus unsigned long long desktop_index = (m_current_desktop->desktop - 1 + m_max_desktops) % m_max_desktops; // We can't change while a window is being moved or resized if (m_desktops.count_members_of(MOVING_DESKTOP) > 0 || m_desktops.count_members_of(RESIZING_DESKTOP) > 0) return; UserDesktop* old_desktop = m_current_desktop; m_current_desktop = USER_DESKTOPS[desktop_index]; Window old_focus = m_focused; if (m_focused != None) { if (is_child(m_focused) && !is_visible(get_parent_of(m_focused))) unfocus(false); if (is_client(m_focused) && !is_visible(m_focused)) unfocus(false); } m_changes.push(new ChangeCurrentDesktop(old_desktop, m_current_desktop)); // If we can still focus the window we were focused on before, then do so // Otherwise, figure out the next logical window in the focus cycle if (m_focused != None && m_focused == old_focus) m_current_desktop->focus_cycle.set(m_focused); else sync_focus_to_cycle(); }
/** * Removes a child from the given client. */ void ClientModel::remove_child(Window child, bool focus_parent) { if (!is_child(child)) return; Window parent = m_parents[child]; m_children[parent]->erase(child); m_parents.erase(child); if (m_focused == child) { if (focus_parent) focus(parent); else unfocus(); } Desktop *desktop = find_desktop(parent); if (desktop->is_user_desktop()) { UserDesktop *user_desktop = dynamic_cast<UserDesktop*>(desktop); user_desktop->focus_cycle.remove(child, false); } else if (desktop->is_all_desktop()) dynamic_cast<AllDesktops*>(ALL_DESKTOPS)->focus_cycle.remove(child, false); m_changes.push(new ChildRemoveChange(parent, child)); }
QuadTree::iterator_base QuadTree::find_neighbor(const iterator_base & it, Location x) { std::stack<QuadTreeLocation> path; iterator_base q = it; while( !is_root(q) ) { QuadTreeLocation loc = q->get_location(); path.push(loc); q=parent(q); if( !loc.has_location(x) ) break; if( is_root(q) && loc.has_location(x) ) return iterator_base(0); }; while(!path.empty()) { QuadTreeLocation loc = path.top(); path.pop(); if(x==L || x==R) q = goto_quadtree_child(q, QuadTreeLocation::x_symmetry(loc)); if(x==T || x==B) q = goto_quadtree_child(q, QuadTreeLocation::y_symmetry(loc)); if(q.node==0 || is_child(q)) return q; } return q; }
void initialize() { // scan the matrix in bottom up order CYKTable< std::list<Pos> > ch(sz_); for (uint j=1; j!=sz_; ++j) { for (uint i=j-1; ; --i) { //std::cout << pf(i+1,j+1) << std::endl; if (bpm_(i+1,j+1)>=th_) { #if 0 std::back_insert_iterator< std::list<Pos> > ii(bp_(i,j)); std::copy(ch(i+1,j-1).begin(), ch(i+1,j-1).end(), ii); #else std::swap(bp_(i,j),ch(i+1,j-1)); #endif ch(i,j).push_back(Pos(i,j)); head_[i].push_back(Pos(i,j)); } else { std::back_insert_iterator< std::list<Pos> > ii(ch(i,j)); std::remove_copy_if(ch(i+1,j).begin(), ch(i+1,j).end(), ii, std::bind1st(is_child(), head_[i].back())); std::copy(head_[i].begin(), head_[i].end(), ii); } if (i==0) break; } } vt_.fill(static_cast<uint>(-1)); }
/* create duplis from every child in scene or group */ static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChildDuplisFunc make_child_duplis_cb) { Object *parent = ctx->object; Object *obedit = ctx->scene->obedit; if (ctx->group) { unsigned int lay = ctx->group->layer; GroupObject *go; for (go = ctx->group->gobject.first; go; go = go->next) { Object *ob = go->ob; if ((ob->lay & lay) && ob != obedit && is_child(ob, parent)) { /* mballs have a different dupli handling */ if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ make_child_duplis_cb(ctx, userdata, ob); } } } else { unsigned int lay = ctx->scene->lay; Base *base; for (base = ctx->scene->base.first; base; base = base->next) { Object *ob = base->object; if ((base->lay & lay) && ob != obedit && is_child(ob, parent)) { /* mballs have a different dupli handling */ if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ make_child_duplis_cb(ctx, userdata, ob); /* Set proper layer in case of scene looping, * in case of groups the object layer will be * changed when it's duplicated due to the * group duplication. */ ob->lay = ctx->object->lay; } } } }
// -------------------------------------------------------- // handle mouse leaving this window // -------------------------------------------------------- void t_button::mouse_leaving( t_window* old_window, t_window* new_window, t_mouse_event const& event ) { if (is_child( new_window )) return; if (m_pressed || m_highlighted) { m_pressed = false; m_highlighted = false; set_image(); } }
/* create duplis from every child in scene or group */ static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChildDuplisFunc make_child_duplis_cb) { Object *parent = ctx->object; Object *obedit = ctx->scene->obedit; if (ctx->group) { unsigned int lay = ctx->group->layer; GroupObject *go; for (go = ctx->group->gobject.first; go; go = go->next) { Object *ob = go->ob; if ((ob->lay & lay) && ob != obedit && is_child(ob, parent)) { /* mballs have a different dupli handling */ if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ make_child_duplis_cb(ctx, userdata, ob); } } } else { unsigned int lay = ctx->scene->lay; Base *base; for (base = ctx->scene->base.first; base; base = base->next) { Object *ob = base->object; if ((base->lay & lay) && ob != obedit && is_child(ob, parent)) { /* mballs have a different dupli handling */ if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ make_child_duplis_cb(ctx, userdata, ob); } } } }
/** * Forces a window to be focused, ignoring the nofocus policy. */ void ClientModel::force_focus(Window client) { Window parent = client; if (is_child(client)) parent = get_parent_of(client); if (!is_visible(parent)) return; Window old_focus = m_focused; m_focused = client; m_current_desktop->focus_cycle.set(client); m_changes.push(new ChangeFocus(old_focus, client)); }
/** * Adds a new child window to the given client. */ void ClientModel::add_child(Window client, Window child) { if (!is_client(client)) return; if (is_child(child)) return; m_children[client]->insert(child); m_parents[child] = client; m_changes.push(new ChildAddChange(client, child)); if (is_autofocusable(client)) { m_current_desktop->focus_cycle.add_after(child, client); focus(child); } }
bool is_parent() const { return !is_child(); }
/** * Moves a client between two desktops and fires the resulting event. */ void ClientModel::move_to_desktop(Window client, Desktop* new_desktop, bool should_unfocus) { Desktop* old_desktop = m_desktops.get_category_of(client); if (*old_desktop == *new_desktop) return; bool can_focus = m_autofocus[client]; m_desktops.move_member(client, new_desktop); if (can_focus && old_desktop->is_user_desktop()) { UserDesktop *user_desktop = dynamic_cast<UserDesktop*>(old_desktop); user_desktop->focus_cycle.remove(client, false); for (std::set<Window>::iterator child = m_children[client]->begin(); child != m_children[client]->end(); child++) user_desktop->focus_cycle.remove(*child, false); } else if (can_focus && old_desktop->is_all_desktop()) { dynamic_cast<AllDesktops*>(ALL_DESKTOPS)->focus_cycle.remove(client, false); for (std::set<Window>::iterator child = m_children[client]->begin(); child != m_children[client]->end(); child++) dynamic_cast<AllDesktops*>(ALL_DESKTOPS)->focus_cycle.remove(*child, false); } if (can_focus && new_desktop->is_user_desktop()) { UserDesktop *user_desktop = dynamic_cast<UserDesktop*>(new_desktop); user_desktop->focus_cycle.add(client); for (std::set<Window>::iterator child = m_children[client]->begin(); child != m_children[client]->end(); child++) user_desktop->focus_cycle.add_after(*child, client); } else if (can_focus && new_desktop->is_all_desktop()) { dynamic_cast<AllDesktops*>(ALL_DESKTOPS)->focus_cycle.add(client); for (std::set<Window>::iterator child = m_children[client]->begin(); child != m_children[client]->end(); child++) dynamic_cast<AllDesktops*>(ALL_DESKTOPS)->focus_cycle.add_after(*child, client); } if (should_unfocus) { if (m_focused == client) { unfocus(); } else if (is_child(m_focused) && get_parent_of(m_focused) == client) { unfocus(); } } // Make sure that the focus is transferred properly into the new cycle else if (can_focus && new_desktop->is_user_desktop()) { UserDesktop *user_desktop = dynamic_cast<UserDesktop*>(new_desktop); user_desktop->focus_cycle.set(client); } else if (can_focus && new_desktop->is_all_desktop()) dynamic_cast<AllDesktops*>(ALL_DESKTOPS)->focus_cycle.set(client); m_changes.push(new ChangeClientDesktop(client, old_desktop, new_desktop)); }
int main(int argc, char* argv[]) { int opt = 0, i = 0, id = 0; char err = '\0'; char help_msg[] = "Usage : -n print all number before n\n"; pid_t cld_pid = 0; messg msg = {}; key_t key = 0; pid_t my_pid = getpid(); while ((opt = getopt(argc, argv, "n:")) != -1) { switch (opt) { case 'n': sscanf(optarg, "%d%c", &n, &err); if (err != '\0') { fprintf(stderr, help_msg); return 0; } break; default: fprintf(stderr, help_msg); return 1; } } if (optind > argc) { fprintf(stderr, "No argument after -n %d"); return 2; } if (n <= 0) { fprintf(stderr, "Incorrect argument"); return 3; } if ((key = ftok(argv[0], getpid())) == -1) { perror("Can't generate id of message queue"); return 13; } if ((id = msgget(key, IPC_CREAT | /*IPC_EXCL |*/ 0666)) == -1) { perror("mq create error"); return 4; } for (i = 0; i < n; ++i) { cld_pid = fork(); if (cld_pid == -1) { perror("Too big number\n"); msgctl(id, IPC_RMID, NULL); return 12; } if (cld_pid == 0) { is_child(&msg, id); return 0; } counter++; } msg.mtype = 1; if (msgsnd(id, &msg, sizeof(messg) - sizeof(long), 0) == -1) { msgctl(id, IPC_RMID, NULL); perror("mq send error"); return 5; } if (msgrcv(id, &msg, sizeof(messg) - sizeof(long), n + 1, 0) == -1) { msgctl(id, IPC_RMID, NULL); perror("mq recieve error"); return 6; } msgctl(id, IPC_RMID, NULL); return 0; }