/* Mouse callback */ static int event_callback (Gpm_Event *event, void *data) { WTree *tree = data; if (!(event->type & GPM_UP)) return MOU_NORMAL; if (tree->is_panel) event->y--; event->y--; if (!tree->active) change_panel (); if (event->y < 0){ tree_move_backward (tree, tlines (tree) - 1); show_tree (tree); } else if (event->y >= tlines (tree)){ tree_move_forward (tree, tlines (tree) - 1); show_tree (tree); } else { tree_event (tree, event->y); if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){ chdir_sel (tree); } } return MOU_NORMAL; }
/* this is very haphazzard */ void show_tree(rtn_t * root, struct trunk *prev, int is_left) { char *prev_str = NULL; struct trunk this_disp; if (root == NULL) return; this_disp.prev = prev; this_disp.str = " "; prev_str = this_disp.str; /* */ show_tree(root->next[0], &this_disp, 1); if (!prev) this_disp.str = "---"; else if (is_left) { this_disp.str = ".--"; prev_str = " |"; } else { this_disp.str = "`--"; prev->str = prev_str; } /* */ show_trunks(&this_disp); printf("%d\n", *(int *)root->data); if (prev) prev->str = prev_str; this_disp.str = " |"; show_tree(root->next[1], &this_disp, 0); if (!prev) puts(""); }
void show_tree(node *start) { if(start->lptr != NULL) show_tree(start->lptr); if(start->rptr != NULL) show_tree(start->rptr); printf("%c \n",start->data); }
static cb_ret_t tree_callback (Widget *w, widget_msg_t msg, int parm) { WTree *tree = (WTree *) w; Dlg_head *h = tree->widget.parent; switch (msg) { case WIDGET_DRAW: tree_frame (h, tree); show_tree (tree); return MSG_HANDLED; case WIDGET_KEY: return tree_key (tree, parm); case WIDGET_FOCUS: tree->active = 1; buttonbar_set_label (h, 1, _("Help"), tree_help_cmd); buttonbar_set_label_data (h, 2, _("Rescan"), tree_rescan_command, tree); buttonbar_set_label_data (h, 3, _("Forget"), tree_forget_cmd, tree); buttonbar_set_label_data (h, 5, _("Copy"), tree_copy_cmd, tree); buttonbar_set_label_data (h, 6, _("RenMov"), tree_move_cmd, tree); #if 0 /* FIXME: mkdir is currently defunct */ buttonbar_set_label_data (h, 7, _("Mkdir"), tree_mkdir_cmd, tree); #else buttonbar_clear_label (h, 7); #endif buttonbar_set_label_data (h, 8, _("Rmdir"), tree_rmdir_command, tree); set_navig_label (tree); buttonbar_redraw (h); /* FIXME: Should find a better way of only displaying the currently selected item */ show_tree (tree); return MSG_HANDLED; /* FIXME: Should find a better way of changing the color of the selected item */ case WIDGET_UNFOCUS: tree->active = 0; show_tree (tree); return MSG_HANDLED; case WIDGET_DESTROY: tree_destroy (tree); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static inline cb_ret_t tree_key (WTree *tree, int key) { int i; for (i = 0; tree_keymap [i].key_code; i++){ if (key == tree_keymap [i].key_code){ if (tree_keymap [i].fn != tree_start_search) tree->searching = 0; (*tree_keymap [i].fn)(tree); show_tree (tree); return MSG_HANDLED; } } /* We do not want to use them if we do not need to */ /* Input line may want to take the motion key event */ if (key == KEY_LEFT) return move_left (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; if (key == KEY_RIGHT) return move_right (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; if (is_abort_char (key)) { if (tree->is_panel) { tree->searching = 0; show_tree (tree); return MSG_HANDLED; /* eat abort char */ } /* modal tree dialog: let upper layer see the abort character and close the dialog */ return MSG_NOT_HANDLED; } /* Do not eat characters not meant for the tree below ' ' (e.g. C-l). */ if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) { if (tree->searching){ tree_do_search (tree, key); show_tree (tree); return MSG_HANDLED; } if (!command_prompt) { tree_start_search (tree); tree_do_search (tree, key); return MSG_HANDLED; } return tree->is_panel ? MSG_HANDLED : MSG_NOT_HANDLED; } return MSG_NOT_HANDLED; }
static int tree_event (Gpm_Event * event, void *data) { WTree *tree = (WTree *) data; Widget *w = WIDGET (data); Gpm_Event local; if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; /* rest of the upper frame - call menu */ if (tree->is_panel && (event->type & GPM_DOWN) != 0 && event->y == WIDGET (w->owner)->y + 1) return MOU_UNHANDLED; local = mouse_get_local (event, w); if ((local.type & GPM_UP) == 0) return MOU_NORMAL; if (tree->is_panel) local.y--; local.y--; if (!tree->active) change_panel (); if (local.y < 0) { tree_move_backward (tree, tlines (tree) - 1); show_tree (tree); } else if (local.y >= tlines (tree)) { tree_move_forward (tree, tlines (tree) - 1); show_tree (tree); } else if ((local.type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) { if (tree->tree_shown[local.y] != NULL) { tree->selected_ptr = tree->tree_shown[local.y]; tree->topdiff = local.y; } tree_chdir_sel (tree); } return MOU_NORMAL; }
int C_try_binary_search_tree::show_tree(Tree_node* tr) { printf("%d", tr->data); if (tr->left != 0 || tr->right != 0) { printf("("); if (tr->left != 0) show_tree(tr->left); printf(","); if (tr->right != 0) show_tree(tr->right); printf(")"); } return 0; }
static cb_ret_t tree_key (WTree * tree, int key) { size_t i; if (is_abort_char (key)) { if (tree->is_panel) { tree->searching = 0; show_tree (tree); return MSG_HANDLED; /* eat abort char */ } /* modal tree dialog: let upper layer see the abort character and close the dialog */ return MSG_NOT_HANDLED; } if (tree->searching && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE)) { tree_do_search (tree, key); show_tree (tree); return MSG_HANDLED; } for (i = 0; tree_map[i].key != 0; i++) if (key == tree_map[i].key) switch (tree_map[i].command) { case CK_Left: return tree_move_left (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; case CK_Right: return tree_move_right (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; default: tree_execute_cmd (tree, tree_map[i].command); return MSG_HANDLED; } /* Do not eat characters not meant for the tree below ' ' (e.g. C-l). */ if (!command_prompt && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE)) { tree_start_search (tree); tree_do_search (tree, key); return MSG_HANDLED; } return MSG_NOT_HANDLED; }
/** * 木の内容を表示する関数(帰りがけ順) * @param TREE *p 表示したい部分木 * for Debug */ void show_tree(TREE *p) { // 要素が登録されていない if (p->left == p || p->right == p) return ; // 左へ if(p->left != NULL) show_tree(p->left); printf("id: %d\n", p->id); // 右へ if(p->right != NULL) show_tree(p->right); }
/* A file entry went away or appeared */ static void show_entry(struct diff_options *opt, const char *prefix, struct tree_desc *desc, struct strbuf *base) { unsigned mode; const char *path; const unsigned char *sha1 = tree_entry_extract(desc, &path, &mode); int pathlen = tree_entry_len(path, sha1); int old_baselen = base->len; strbuf_add(base, path, pathlen); if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode)) { enum object_type type; struct tree_desc inner; void *tree; unsigned long size; tree = read_sha1_file(sha1, &type, &size); if (!tree || type != OBJ_TREE) die("corrupt tree sha %s", sha1_to_hex(sha1)); if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) opt->add_remove(opt, *prefix, mode, sha1, base->buf, 0); strbuf_addch(base, '/'); init_tree_desc(&inner, tree, size); show_tree(opt, prefix, &inner, base); free(tree); } else opt->add_remove(opt, prefix[0], mode, sha1, base->buf, 0); strbuf_setlen(base, old_baselen); }
int main() { ptree root = NULL; create_tree(&root); show_tree(root); return 0; }
static inline void tree_move_up (WTree * tree) { tree_move_backward (tree, 1); show_tree (tree); maybe_chdir (tree); }
/* A file entry went away or appeared */ static int show_entry(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base) { unsigned mode; const char *path; const unsigned char *sha1 = extract(desc, &path, &mode); if (opt->recursive && S_ISDIR(mode)) { char type[20]; char *newbase = malloc_base(base, path, strlen(path)); struct tree_desc inner; void *tree; tree = read_sha1_file(sha1, type, &inner.size); if (!tree || strcmp(type, "tree")) die("corrupt tree sha %s", sha1_to_hex(sha1)); inner.buf = tree; show_tree(opt, prefix, &inner, newbase); free(tree); free(newbase); return 0; } opt->add_remove(opt, prefix[0], mode, sha1, base, path); return 0; }
static void tree_move_pgup (WTree * tree) { tree_move_backward (tree, tlines (tree) - 1); show_tree (tree); maybe_chdir (tree); }
static inline void tree_move_home (WTree * tree) { tree_move_to_top (tree); show_tree (tree); maybe_chdir (tree); }
static inline void tree_move_end (WTree * tree) { tree_move_to_bottom (tree); show_tree (tree); maybe_chdir (tree); }
void MainWindow::on_actionRemove_triggered() { if(ui->treeWidget->selectedItems().count() == 0) { QErrorMessage error_mes; error_mes.showMessage("Node was not selected"); error_mes.exec(); return; } int lvl = selected_lvl(); space * wp = (space*)getRoot(); if(lvl == 0){ remove_space(); }else if(lvl == 1){ int index_star = selected_index(0); remove_star(index_star); }else if(lvl == 2){ int index_star = selected_index(1); star * p_star = (star*)wp->sublvl[index_star]; int index_planet = selected_index(0); remove_planet(p_star,index_planet); }else if(lvl == 3){ int index_star = selected_index(2); star * p_star = (star*)wp->sublvl[index_star]; int index_planet = selected_index(1); planet * p_planet = (planet*)p_star->sublvl[index_planet]; int index_sat = selected_index(0); remove_satellite(p_planet,index_sat); } show_tree(); }
static void tree_chdir_sel (WTree * tree) { if (tree->is_panel) { change_panel (); if (do_cd (tree->selected_ptr->name, cd_exact)) select_item (current_panel); else message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), vfs_path_as_str (tree->selected_ptr->name), unix_error_string (errno)); widget_redraw (WIDGET (current_panel)); change_panel (); show_tree (tree); } else { WDialog *h = WIDGET (tree)->owner; h->ret_value = B_ENTER; dlg_stop (h); } }
/* A file entry went away or appeared */ static void show_entry(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base, int baselen) { unsigned mode; const char *path; const unsigned char *sha1 = tree_entry_extract(desc, &path, &mode); int pathlen = tree_entry_len(path, sha1); if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode)) { enum object_type type; char *newbase = malloc_base(base, baselen, path, pathlen); struct tree_desc inner; void *tree; unsigned long size; tree = read_sha1_file(sha1, &type, &size); if (!tree || type != OBJ_TREE) die("corrupt tree sha %s", sha1_to_hex(sha1)); init_tree_desc(&inner, tree, size); show_tree(opt, prefix, &inner, newbase, baselen + 1 + pathlen); free(tree); free(newbase); } else { char *fullname = malloc_fullname(base, baselen, path, pathlen); opt->add_remove(opt, prefix[0], mode, sha1, fullname); free(fullname); } }
int cmd_ilist(string str) { object ob; string file, *files; int deep_list, i, s; notify_fail(SYNTAX); if(!str) return 0; seteuid(geteuid(previous_object())); if(sscanf(str, "-R %s", file)) deep_list = 1; else if(sscanf(str, "-T %s", file)) deep_list = 2; else file = str; ob = ref_ob(file); if(!ob || !objectp(ob)) { notify_fail("Couldn't find object.\n"); return 0; } write(wrap("Files inherited by " + dump_variable(ob))); if(!deep_list) files = inherit_list(ob); else if(deep_list == 1) files = deep_inherit_list(ob); else if(deep_list == 2) return show_tree(ob, 1); for(i = 0, s = sizeof(files); i < s; i ++) printf(" %d: %s\n", i + 1, files[i]); return 1; } // do_cmd
static void tree_move_pgdn (WTree * tree) { tree_move_forward (tree, tlines (tree) - 1); show_tree (tree); maybe_chdir (tree); }
static inline void tree_move_down (WTree * tree) { tree_move_forward (tree, 1); show_tree (tree); maybe_chdir (tree); }
int main() { struct tree *phead = NULL; init_node_head(&phead, sizeof(struct tree)); create_tree(phead); show_tree(phead); return 0; }
static int tree_event (Gpm_Event * event, void *data) { WTree *tree = (WTree *) data; Widget *w = (Widget *) data; Gpm_Event local; if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; local = mouse_get_local (event, w); /* rest of the upper frame, the menu is invisible - call menu */ if (tree->is_panel && (local.type & GPM_DOWN) != 0 && local.y == 1 && !menubar_visible) return the_menubar->widget.mouse (event, the_menubar); if ((local.type & GPM_UP) == 0) return MOU_NORMAL; if (tree->is_panel) local.y--; local.y--; if (!tree->active) change_panel (); if (local.y < 0) { tree_move_backward (tree, tlines (tree) - 1); show_tree (tree); } else if (local.y >= tlines (tree)) { tree_move_forward (tree, tlines (tree) - 1); show_tree (tree); } else { tree_mouse_click (tree, local.y); if ((local.type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) tree_chdir_sel (tree); } return MOU_NORMAL; }
static cb_ret_t tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WTree *tree = (WTree *) w; WDialog *h = w->owner; WButtonBar *b; switch (msg) { case MSG_DRAW: tree_frame (h, tree); show_tree (tree); if (widget_get_state (w, WST_FOCUSED)) { b = find_buttonbar (h); widget_redraw (WIDGET (b)); } return MSG_HANDLED; case MSG_FOCUS: b = find_buttonbar (h); buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), tree_map, w); buttonbar_set_label (b, 2, Q_ ("ButtonBar|Rescan"), tree_map, w); buttonbar_set_label (b, 3, Q_ ("ButtonBar|Forget"), tree_map, w); buttonbar_set_label (b, 4, tree_navigation_flag ? Q_ ("ButtonBar|Static") : Q_ ("ButtonBar|Dynamc"), tree_map, w); buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), tree_map, w); buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), tree_map, w); #if 0 /* FIXME: mkdir is currently defunct */ buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), tree_map, w); #else buttonbar_clear_label (b, 7, w); #endif buttonbar_set_label (b, 8, Q_ ("ButtonBar|Rmdir"), tree_map, w); return MSG_HANDLED; case MSG_UNFOCUS: tree->searching = 0; return MSG_HANDLED; case MSG_KEY: return tree_key (tree, parm); case MSG_ACTION: /* command from buttonbar */ return tree_execute_cmd (tree, parm); case MSG_DESTROY: tree_destroy (tree); return MSG_HANDLED; default: return widget_default_callback (w, sender, msg, parm, data); } }
/* Handle mouse click */ static void tree_event (WTree *tree, int y) { if (tree->tree_shown [y]){ tree->selected_ptr = tree->tree_shown [y]; tree->topdiff = y; } show_tree (tree); }
/** * 配列の中身を表示する関数 * for Debug */ void show_array() { int i; for (i = 0; i < n_words; i++) { printf("%s ->", words[i]->word); show_tree(&(words[i]->second_words)); putchar('\n'); } }
static int move_right (WTree *tree) { if (tree_navigation_flag){ tree_move_to_child (tree); show_tree (tree); maybe_chdir (tree); return 1; } return 0; }
void MainWindow::on_actionClear_tree_triggered() { if(ui->treeWidget->selectedItems().count() == 0) { QErrorMessage error_mes; error_mes.showMessage("Tree doesn`t exist"); error_mes.exec(); return; } remove_space(); show_tree(); }
static int move_left (WTree *tree) { int v; if (tree_navigation_flag){ v = tree_move_to_parent (tree); show_tree (tree); maybe_chdir (tree); return v; } return 0; }