void shelm_clock_dialog(const char *window_title, const char *window_text, int window_width, int window_height, const char *window_background, Eina_Bool show_seconds, Eina_Bool show_am_pm, const char *time, Eina_Bool is_editable) { Evas_Object *window, *background, *frame, *box, *clock, *buttonbar, *button_cancel, *button_ok; char buf[PATH_MAX]; if (window_title) window = create_window("shellementary-clockdialog", window_title, cancel_callback); else window = create_window("shellementary-clockdialog", _("Set the time"), cancel_callback); background = create_background(window, window_background, EINA_TRUE); elm_win_resize_object_add(window, background); evas_object_show(background); frame = create_frame(window, EINA_TRUE); elm_win_resize_object_add(window, frame); evas_object_show(frame); box = create_box(window, EINA_FALSE); elm_object_content_set(frame, box); evas_object_show(box); if (window_text) { Evas_Object *label; label = create_label(window, window_text); elm_box_pack_end(box, label); evas_object_show(label); } clock = create_clock(window, show_seconds, show_am_pm, time, is_editable); elm_box_pack_end(box, clock); evas_object_show(clock); buttonbar = create_box(window, EINA_TRUE); elm_box_pack_end(box, buttonbar); evas_object_show(buttonbar); snprintf(buf, sizeof(buf), "%s/icon-cancel.png", PACKAGE_DATA_DIR); button_cancel = create_button(window, buf, _("Cancel")); evas_object_smart_callback_add(button_cancel, "clicked", cancel_callback, NULL); elm_box_pack_start(buttonbar, button_cancel); evas_object_show(button_cancel); snprintf(buf, sizeof(buf), "%s/icon-ok.png", PACKAGE_DATA_DIR); button_ok = create_button(window, buf, _("OK")); evas_object_smart_callback_add(button_ok, "clicked", clock_callback, clock); elm_box_pack_end(buttonbar, button_ok); evas_object_show(button_ok); if (!window_width) evas_object_geometry_get(window, NULL, NULL, &window_width, NULL); if (!window_height) evas_object_geometry_get(window, NULL, NULL, NULL, &window_height); evas_object_resize(window, window_width, window_height); evas_object_show(window); }
static void terminal_create (TerminalPlugin *term_plugin) { GtkWidget *frame; g_return_if_fail(term_plugin != NULL); term_plugin->child_pid = 0; /* Create the terminals. */ term_plugin->shell = create_terminal (term_plugin); term_plugin->shell_box = create_box (term_plugin->shell); term_plugin->term = create_terminal (term_plugin); term_plugin->term_box = create_box (term_plugin->term); /* key-press handler for ctrl-d "kill" */ g_signal_connect (G_OBJECT (term_plugin->term), "key-press-event", G_CALLBACK (terminal_keypress_cb), term_plugin); frame = gtk_frame_new (NULL); gtk_widget_show (frame); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (frame), term_plugin->shell_box); gtk_widget_show_all (frame); term_plugin->frame = frame; g_signal_connect (vte_reaper_get(), "child-exited", G_CALLBACK (terminal_child_exited_cb), term_plugin); init_shell (term_plugin, NULL); }
void shelm_simple_dialog(const char *window_title, const char *window_text, int window_width, int window_height, const char *window_background, const char *window_icccm_name, const char *window_default_title, const char *window_default_icon) { Evas_Object *window, *background, *frame, *box, *hbox, *icon, *button_ok; char buf[PATH_MAX]; snprintf(buf, sizeof(buf), "shellementary-%s", window_icccm_name); if (window_title) window = create_window(buf, window_title, destroy); else window = create_window(buf, window_default_title, destroy); background = create_background(window, window_background, EINA_FALSE); elm_win_resize_object_add(window, background); evas_object_show(background); frame = create_frame(window, EINA_FALSE); elm_win_resize_object_add(window, frame); evas_object_show(frame); box = create_box(window, EINA_FALSE); elm_object_content_set(frame, box); evas_object_show(box); hbox = create_box(window, EINA_TRUE); elm_box_pack_end(box, hbox); evas_object_show(hbox); icon = create_icon(window, window_default_icon); elm_box_pack_start(hbox, icon); evas_object_show(icon); if (window_text) { Evas_Object *label; label = create_label(window, window_text); elm_box_pack_end(hbox, label); evas_object_show(label); } snprintf(buf, sizeof(buf), "%s/icon-ok.png", PACKAGE_DATA_DIR); button_ok = create_button(window, buf, _("OK")); evas_object_smart_callback_add(button_ok, "clicked", destroy, NULL); elm_box_pack_end(box, button_ok); evas_object_show(button_ok); if (!window_width) evas_object_geometry_get(window, NULL, NULL, &window_width, NULL); if (!window_height) evas_object_geometry_get(window, NULL, NULL, NULL, &window_height); evas_object_resize(window, window_width, window_height); evas_object_show(window); }
void windowing02( ) { WIN win; int ch; init_pair( 5, COLOR_CYAN, COLOR_BLACK ); // erase the text on the window erase( ); move( 0, 0 ); // Assign border characters and starting width/height/position init_win_params( &win ); print_win_params( &win ); // Draw bold backgrounded text at the top of the screen attron( COLOR_PAIR(5) | A_BOLD ); printw( "Press X to exit" ); refresh( ); attroff( COLOR_PAIR(5) | A_BOLD ); attrset( A_NORMAL ); // Draw the box onto the screen create_box( &win ); // While the input character isn't an x, perform some actions while( (ch = getch()) != 'x' ) { // Use the keyboard keys to "move" the box (destroy and recreate it) switch ( ch ) { case KEY_LEFT: destroy_box( &win ); win.startx--; create_box( &win ); break; case KEY_RIGHT: destroy_box( &win ); win.startx++; create_box( &win ); break; case KEY_UP: destroy_box( &win ); win.starty--; create_box( &win ); break; case KEY_DOWN: destroy_box( &win ); win.starty++; create_box( &win ); break; default: break; } } return; }
int main( int argc, char *argv[] ) { WIN win; int ch; initscr(); // start CURSES mode start_color(); // start color functionality cbreak(); // disable line buffering keypad( stdscr, TRUE ); // enable Fx notify noecho(); init_pair( 1, COLOR_CYAN, COLOR_BLACK ); init_win_params( &win ); // initialize window parameter print_win_params( &win ); attron( COLOR_PAIR( 1 ) ); printw( "Press F12 to exit" ); refresh(); attroff( COLOR_PAIR( 1 ) ); create_box( &win, TRUE ); while( ( ch = getch() ) != KEY_F( 12 ) ) { switch( ch ) { case KEY_LEFT: create_box( &win, FALSE ); --win.startx; create_box( &win, TRUE ); break; case KEY_RIGHT: create_box( &win, FALSE ); ++win.startx; create_box( &win, TRUE ); break; case KEY_UP: create_box( &win, FALSE ); --win.starty; create_box( &win, TRUE ); break; case KEY_DOWN: create_box( &win, FALSE ); ++win.starty; create_box( &win, TRUE ); break; } } endwin(); // end CURSES mode return 0; }
int main(int argc, char const *argv[]) { WIN win; int ch; initscr(); start_color(); cbreak(); keypad(stdscr, TRUE); noecho(); init_pair(1, COLOR_CYAN, COLOR_BLACK); init_win_params(&win); print_win_params(&win); attron(COLOR_PAIR(1)); printw("Press F1 to exit"); refresh(); attroff(COLOR_PAIR(1)); create_box(&win, TRUE); while ((ch = getch()) != KEY_F(1)) { switch (ch) { case KEY_LEFT: create_box(&win, FALSE); --win.startx; create_box(&win, TRUE); break; case KEY_RIGHT: create_box(&win, FALSE); ++win.startx; create_box(&win, TRUE); break; case KEY_UP: create_box(&win, FALSE); --win.starty; create_box(&win, TRUE); break; case KEY_DOWN: create_box(&win, FALSE); ++win.starty; create_box(&win, TRUE); break; } } endwin(); return 0; }
int main(int argc, char *argv[]) { WIN win; int ch; initscr(); /* Start curses mode */ start_color(); /* Start the color functionality */ cbreak(); /* Line buffering disabled, Pass on * everty thing to me */ keypad(stdscr, TRUE); /* I need that nifty F1 */ noecho(); init_pair(1, COLOR_CYAN, COLOR_BLACK); /* Initialize the window parameters */ init_win_params(&win); print_win_params(&win); attron(COLOR_PAIR(1)); printw("Press F1 to exit"); refresh(); attroff(COLOR_PAIR(1)); create_box(&win, TRUE); while((ch = getch()) != KEY_F(1)) { switch(ch) { case KEY_LEFT: create_box(&win, FALSE); --win.startx; create_box(&win, TRUE); break; case KEY_RIGHT: create_box(&win, FALSE); ++win.startx; create_box(&win, TRUE); break; case KEY_UP: create_box(&win, FALSE); --win.starty; create_box(&win, TRUE); break; case KEY_DOWN: create_box(&win, FALSE); ++win.starty; create_box(&win, TRUE); break; } } endwin(); /* End curses mode */ return 0; }
int init_gui() { WIN win; int ch; int i; char ** files; initscr(); /* Start curses mode */ start_color(); /* Start the color functionality */ cbreak(); /* Line buffering disabled, Pass on * everty thing to me */ keypad(stdscr, TRUE); /* I need that nifty F1 */ noecho(); init_pair(1, COLOR_CYAN, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); /* Initialize the window parameters */ init_win_params(&win); print_win_params(&win); attron(COLOR_PAIR(1)); printw("F2: Ouvrir un fichier"); printw("\t F3: Lancer l'émulation"); printw("\t F5: Quitter"); attron(A_BOLD); attron(COLOR_PAIR(2)); char chaine[]="Welcome to ProcSI emulator"; mvprintw((LINES/2) -3,(COLS-strlen(chaine))/2,chaine); attroff(A_BOLD); refresh(); attroff(COLOR_PAIR(1)); create_box(&win, TRUE); draw_menu(choices, execute_main_menu, "", 3); while((ch = getch()) != KEY_F(5)) { switch(ch) { case KEY_F(5): mvprintw(LINES-2, 0, "Exiting..."); endwin(); /* End curses mode */ exit(0); case KEY_F(2): files = list_file("", &i); draw_menu(files, execute_file_menu, "", i); } } endwin(); /* End curses mode */ return 0; }
int main(int ac, char **av) { GtkWidget *ptr_window; GtkWidget *ptr_vbox; g_list = xmalloc(sizeof(t_object)); gtk_init(&ac, &av); create_window(&ptr_window); create_box(&ptr_window, &ptr_vbox); create_menu(&ptr_vbox, ptr_window); gtk_widget_show_all(ptr_window); gtk_main(); return (1); }
void printWin(int arr[HIGHT][WIDTH]) { init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_WHITE, COLOR_BLACK); init_pair(8, COLOR_WHITE, COLOR_YELLOW); WIN win[HIGHT][WIDTH]; int i, j; for(i = 0; i < HIGHT; i++) { for(j = 0; j < WIDTH; j++) { int offset; WIN *thewin = &win[i][j]; init_win_params(&win[i][j], j-3, i-3); print_win_params(&win[i][j]); attron(COLOR_PAIR(7)); create_box(&win[i][j], TRUE); attroff(COLOR_PAIR(7)); mvprintw(thewin->starty + WINY/2 , thewin->startx + WINX/2-4,"%s", " "); if(arr[i][j] == 0){ attron(COLOR_PAIR(1)); offset = 0; } else { attron(COLOR_PAIR((int)log2((double)arr[i][j])%7 + 1)); offset = (int)(log10((double)arr[i][j])/2); } mvprintw(thewin->starty + WINY/2 , thewin->startx + WINX/2-offset,"%d", arr[i][j]); if(arr[i][j] == 0){ attroff(COLOR_PAIR(1)); } else { attroff(COLOR_PAIR((int)log2((double)arr[i][j])%7 + 1)); } mvprintw(10,10,"%s%d","Your Score: ", SCORE); move(1000,10000); } } refresh(); }
int main(int argc, char** argv) { In in; in.datafile = NULL; int me = 0; //local MPI rank int nprocs = 1; //number of MPI ranks int num_threads = 1; //number of OpenMP threads int num_steps = -1; //number of timesteps (if -1 use value from lj.in) int system_size = -1; //size of the system (if -1 use value from lj.in) int nx = -1; int ny = -1; int nz = -1; int check_safeexchange = 0; //if 1 complain if atom moves further than 1 subdomain length between exchanges int do_safeexchange = 0; //if 1 use safe exchange mode [allows exchange over multiple subdomains] int use_sse = 0; //setting for SSE variant of miniMD only int screen_yaml = 0; //print yaml output to screen also int yaml_output = 0; //print yaml output int halfneigh = 1; //1: use half neighborlist; 0: use full neighborlist; -1: use original miniMD version half neighborlist force int teams = 1; int device = 0; int neighbor_size = -1; char* input_file = NULL; int ghost_newton = 1; int sort = -1; for(int i = 0; i < argc; i++) { if((strcmp(argv[i], "-i") == 0) || (strcmp(argv[i], "--input_file") == 0)) { input_file = argv[++i]; continue; } } MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &me); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); int error = 0; if(input_file == NULL) error = input(in, "in.lj.miniMD"); else error = input(in, input_file); if(error) { MPI_Finalize(); exit(0); } for(int i = 0; i < argc; i++) { if((strcmp(argv[i], "-t") == 0) || (strcmp(argv[i], "--num_threads") == 0)) { num_threads = atoi(argv[++i]); continue; } if((strcmp(argv[i], "--teams") == 0)) { teams = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-n") == 0) || (strcmp(argv[i], "--nsteps") == 0)) { num_steps = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--size") == 0)) { system_size = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-nx") == 0)) { nx = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-ny") == 0)) { ny = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-nz") == 0)) { nz = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-b") == 0) || (strcmp(argv[i], "--neigh_bins") == 0)) { neighbor_size = atoi(argv[++i]); continue; } if((strcmp(argv[i], "--half_neigh") == 0)) { halfneigh = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-sse") == 0)) { use_sse = atoi(argv[++i]); continue; } if((strcmp(argv[i], "--check_exchange") == 0)) { check_safeexchange = 1; continue; } if((strcmp(argv[i], "--sort") == 0)) { sort = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-o") == 0) || (strcmp(argv[i], "--yaml_output") == 0)) { yaml_output = atoi(argv[++i]); continue; } if((strcmp(argv[i], "--yaml_screen") == 0)) { screen_yaml = 1; continue; } if((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--data_file") == 0)) { if(in.datafile == NULL) in.datafile = new char[1000]; strcpy(in.datafile, argv[++i]); continue; } if((strcmp(argv[i], "-u") == 0) || (strcmp(argv[i], "--units") == 0)) { in.units = strcmp(argv[++i], "metal") == 0 ? 1 : 0; continue; } if((strcmp(argv[i], "-p") == 0) || (strcmp(argv[i], "--force") == 0)) { in.forcetype = strcmp(argv[++i], "eam") == 0 ? FORCEEAM : FORCELJ; continue; } if((strcmp(argv[i], "-gn") == 0) || (strcmp(argv[i], "--ghost_newton") == 0)) { ghost_newton = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) { printf("\n-----------------------------------------------------------------------------------------------------------\n"); printf("-------------" VARIANT_STRING "--------------------\n"); printf("-------------------------------------------------------------------------------------------------------------\n\n"); printf("miniMD is a simple, parallel molecular dynamics (MD) code,\n" "which is part of the Mantevo project at Sandia National\n" "Laboratories ( http://www.mantevo.org ).\n" "The original authors of miniMD are Steve Plimpton ([email protected]) ,\n" "Paul Crozier ([email protected]) with current\n" "versions written by Christian Trott ([email protected]).\n\n"); printf("Commandline Options:\n"); printf("\n Execution configuration:\n"); printf("\t--teams <nteams>: set number of thread-teams used per MPI rank (default 1)\n"); printf("\t-t / --num_threads <threads>: set number of threads per thread-team (default 1)\n"); printf("\t--half_neigh <int>: use half neighborlists (default 1)\n" "\t 0: full neighborlist\n" "\t 1: half neighborlist\n" "\t -1: original miniMD half neighborlist force (not OpenMP safe)\n"); printf("\t-d / --device <int>: choose device to use (only applicable for GPU execution)\n"); printf("\t-dm / --device_map: map devices to MPI ranks\n"); printf("\t-ng / --num_gpus <int>: give number of GPUs per Node (used in conjuction with -dm\n" "\t to determine device id: 'id=mpi_rank%%ng' (default 2)\n"); printf("\t--skip_gpu <int>: skip the specified gpu when assigning devices to MPI ranks\n" "\t used in conjunction with -dm (but must come first in arg list)\n"); printf("\t-sse <sse_version>: use explicit sse intrinsics (use miniMD-SSE variant)\n"); printf("\t-gn / --ghost_newton <int>: set usage of newtons third law for ghost atoms\n" "\t (only applicable with half neighborlists)\n"); printf("\n Simulation setup:\n"); printf("\t-i / --input_file <string>: set input file to be used (default: in.lj.miniMD)\n"); printf("\t-n / --nsteps <int>: set number of timesteps for simulation\n"); printf("\t-s / --size <int>: set linear dimension of systembox\n"); printf("\t-nx/-ny/-nz <int>: set linear dimension of systembox in x/y/z direction\n"); printf("\t-b / --neigh_bins <int>: set linear dimension of neighbor bin grid\n"); printf("\t-u / --units <string>: set units (lj or metal), see LAMMPS documentation\n"); printf("\t-p / --force <string>: set interaction model (lj or eam)\n"); printf("\t-f / --data_file <string>: read configuration from LAMMPS data file\n"); printf("\n Miscelaneous:\n"); printf("\t--check_exchange: check whether atoms moved further than subdomain width\n"); printf("\t--safe_exchange: perform exchange communication with all MPI processes\n" "\t within rcut_neighbor (outer force cutoff)\n"); printf("\t--sort <n>: resort atoms (simple bins) every <n> steps (default: use reneigh frequency; never=0)"); printf("\t-o / --yaml_output <int>: level of yaml output (default 1)\n"); printf("\t--yaml_screen: write yaml output also to screen\n"); printf("\t-h / --help: display this help message\n\n"); printf("---------------------------------------------------------\n\n"); exit(0); } } Atom atom; Neighbor neighbor; Integrate integrate; Thermo thermo; Comm comm; Timer timer; ThreadData threads; Force* force; if(in.forcetype == FORCEEAM) { force = (Force*) new ForceEAM(); if(ghost_newton == 1) { if(me == 0) printf("# EAM currently requires '--ghost_newton 0'; Changing setting now.\n"); ghost_newton = 0; } } if(in.forcetype == FORCELJ) force = (Force*) new ForceLJ(); threads.mpi_me = me; threads.mpi_num_threads = nprocs; threads.omp_me = 0; threads.omp_num_threads = num_threads; atom.threads = &threads; comm.threads = &threads; force->threads = &threads; integrate.threads = &threads; neighbor.threads = &threads; thermo.threads = &threads; force->epsilon = in.epsilon; force->sigma = in.sigma; force->sigma6 = in.sigma*in.sigma*in.sigma*in.sigma*in.sigma*in.sigma; neighbor.ghost_newton = ghost_newton; omp_set_num_threads(num_threads); neighbor.timer = &timer; force->timer = &timer; comm.check_safeexchange = check_safeexchange; comm.do_safeexchange = do_safeexchange; force->use_sse = use_sse; neighbor.halfneigh = halfneigh; if(halfneigh < 0) force->use_oldcompute = 1; if(use_sse) { #ifdef VARIANT_REFERENCE if(me == 0) printf("ERROR: Trying to run with -sse with miniMD reference version. Use SSE variant instead. Exiting.\n"); MPI_Finalize(); exit(0); #endif } if(num_steps > 0) in.ntimes = num_steps; if(system_size > 0) { in.nx = system_size; in.ny = system_size; in.nz = system_size; } if(nx > 0) { in.nx = nx; if(ny > 0) in.ny = ny; else if(system_size < 0) in.ny = nx; if(nz > 0) in.nz = nz; else if(system_size < 0) in.nz = nx; } if(neighbor_size > 0) { neighbor.nbinx = neighbor_size; neighbor.nbiny = neighbor_size; neighbor.nbinz = neighbor_size; } if(neighbor_size < 0 && in.datafile == NULL) { MMD_float neighscale = 5.0 / 6.0; neighbor.nbinx = neighscale * in.nx; neighbor.nbiny = neighscale * in.ny; neighbor.nbinz = neighscale * in.nz; } if(neighbor_size < 0 && in.datafile) neighbor.nbinx = -1; if(neighbor.nbinx == 0) neighbor.nbinx = 1; if(neighbor.nbiny == 0) neighbor.nbiny = 1; if(neighbor.nbinz == 0) neighbor.nbinz = 1; integrate.ntimes = in.ntimes; integrate.dt = in.dt; integrate.sort_every = sort>0?sort:(sort<0?in.neigh_every:0); neighbor.every = in.neigh_every; neighbor.cutneigh = in.neigh_cut; force->cutforce = in.force_cut; thermo.nstat = in.thermo_nstat; if(me == 0) printf("# Create System:\n"); if(in.datafile) { read_lammps_data(atom, comm, neighbor, integrate, thermo, in.datafile, in.units); MMD_float volume = atom.box.xprd * atom.box.yprd * atom.box.zprd; in.rho = 1.0 * atom.natoms / volume; force->setup(); if(in.forcetype == FORCEEAM) atom.mass = force->mass; } else { create_box(atom, in.nx, in.ny, in.nz, in.rho); comm.setup(neighbor.cutneigh, atom); neighbor.setup(atom); integrate.setup(); force->setup(); if(in.forcetype == FORCEEAM) atom.mass = force->mass; create_atoms(atom, in.nx, in.ny, in.nz, in.rho); thermo.setup(in.rho, integrate, atom, in.units); create_velocity(in.t_request, atom, thermo); } if(me == 0) printf("# Done .... \n"); if(me == 0) { fprintf(stdout, "# " VARIANT_STRING " output ...\n"); fprintf(stdout, "# Run Settings: \n"); fprintf(stdout, "\t# MPI processes: %i\n", neighbor.threads->mpi_num_threads); fprintf(stdout, "\t# OpenMP threads: %i\n", neighbor.threads->omp_num_threads); fprintf(stdout, "\t# Inputfile: %s\n", input_file == 0 ? "in.lj.miniMD" : input_file); fprintf(stdout, "\t# Datafile: %s\n", in.datafile ? in.datafile : "None"); fprintf(stdout, "# Physics Settings: \n"); fprintf(stdout, "\t# ForceStyle: %s\n", in.forcetype == FORCELJ ? "LJ" : "EAM"); fprintf(stdout, "\t# Force Parameters: %2.2lf %2.2lf\n",in.epsilon,in.sigma); fprintf(stdout, "\t# Units: %s\n", in.units == 0 ? "LJ" : "METAL"); fprintf(stdout, "\t# Atoms: %i\n", atom.natoms); fprintf(stdout, "\t# System size: %2.2lf %2.2lf %2.2lf (unit cells: %i %i %i)\n", atom.box.xprd, atom.box.yprd, atom.box.zprd, in.nx, in.ny, in.nz); fprintf(stdout, "\t# Density: %lf\n", in.rho); fprintf(stdout, "\t# Force cutoff: %lf\n", force->cutforce); fprintf(stdout, "\t# Timestep size: %lf\n", integrate.dt); fprintf(stdout, "# Technical Settings: \n"); fprintf(stdout, "\t# Neigh cutoff: %lf\n", neighbor.cutneigh); fprintf(stdout, "\t# Half neighborlists: %i\n", neighbor.halfneigh); fprintf(stdout, "\t# Neighbor bins: %i %i %i\n", neighbor.nbinx, neighbor.nbiny, neighbor.nbinz); fprintf(stdout, "\t# Neighbor frequency: %i\n", neighbor.every); fprintf(stdout, "\t# Sorting frequency: %i\n", integrate.sort_every); fprintf(stdout, "\t# Thermo frequency: %i\n", thermo.nstat); fprintf(stdout, "\t# Ghost Newton: %i\n", ghost_newton); fprintf(stdout, "\t# Use intrinsics: %i\n", force->use_sse); fprintf(stdout, "\t# Do safe exchange: %i\n", comm.do_safeexchange); fprintf(stdout, "\t# Size of float: %i\n\n", (int) sizeof(MMD_float)); } comm.exchange(atom); if(sort>0) atom.sort(neighbor); comm.borders(atom); force->evflag = 1; #pragma omp parallel { neighbor.build(atom); force->compute(atom, neighbor, comm, me); } if(neighbor.halfneigh && neighbor.ghost_newton) comm.reverse_communicate(atom); if(me == 0) printf("# Starting dynamics ...\n"); if(me == 0) printf("# Timestep T U P Time\n"); #pragma omp parallel { thermo.compute(0, atom, neighbor, force, timer, comm); } timer.barrier_start(TIME_TOTAL); integrate.run(atom, force, neighbor, comm, thermo, timer); timer.barrier_stop(TIME_TOTAL); int natoms; MPI_Allreduce(&atom.nlocal, &natoms, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); force->evflag = 1; force->compute(atom, neighbor, comm, me); if(neighbor.halfneigh && neighbor.ghost_newton) comm.reverse_communicate(atom); thermo.compute(-1, atom, neighbor, force, timer, comm); if(me == 0) { double time_other = timer.array[TIME_TOTAL] - timer.array[TIME_FORCE] - timer.array[TIME_NEIGH] - timer.array[TIME_COMM]; printf("\n\n"); printf("# Performance Summary:\n"); printf("# MPI_proc OMP_threads nsteps natoms t_total t_force t_neigh t_comm t_other performance perf/thread grep_string t_extra\n"); printf("%i %i %i %i %lf %lf %lf %lf %lf %lf %lf PERF_SUMMARY %lf\n\n\n", nprocs, num_threads, integrate.ntimes, natoms, timer.array[TIME_TOTAL], timer.array[TIME_FORCE], timer.array[TIME_NEIGH], timer.array[TIME_COMM], time_other, 1.0 * natoms * integrate.ntimes / timer.array[TIME_TOTAL], 1.0 * natoms * integrate.ntimes / timer.array[TIME_TOTAL] / nprocs / num_threads, timer.array[TIME_TEST]); } if(yaml_output) output(in, atom, force, neighbor, comm, thermo, integrate, timer, screen_yaml); delete force; MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return 0; }
int main(int argc, char **argv) { //Common miniMD settings In in; in.datafile = NULL; int me=0; //local MPI rank int nprocs=1; //number of MPI ranks int num_threads=32; //number of Threads per Block threads int num_steps=-1; //number of timesteps (if -1 use value from lj.in) int system_size=-1; //size of the system (if -1 use value from lj.in) int check_safeexchange=0; //if 1 complain if atom moves further than 1 subdomain length between exchanges int do_safeexchange=0; //if 1 use safe exchange mode [allows exchange over multiple subdomains] int use_sse=0; //setting for SSE variant of miniMD only int screen_yaml=0; //print yaml output to screen also int yaml_output=0; //print yaml output int halfneigh=0; //1: use half neighborlist; 0: use full neighborlist; -1: use original miniMD version half neighborlist force char* input_file = NULL; int ghost_newton = 0; int skip_gpu = 999; int neighbor_size = -1; //OpenCL specific int platform = 0; int device = 0; int subdevice = -1; int ppn = 2; int use_tex = 0; int threads_per_atom = 1; int map_device=0; for(int i = 0; i < argc; i++) { if((strcmp(argv[i], "-i") == 0) || (strcmp(argv[i], "--input_file") == 0)) { input_file = argv[++i]; continue; } if((strcmp(argv[i],"-p")==0)||(strcmp(argv[i],"--platform")==0)) {platform=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-d")==0)||(strcmp(argv[i],"--device")==0)) {device=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-sd")==0)||(strcmp(argv[i],"--subdevice")==0)) {subdevice=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-sd_map")==0)||(strcmp(argv[i],"--subdevice_mapping")==0)) {subdevice=1-me%ppn; continue;} if((strcmp(argv[i],"-ng")==0)||(strcmp(argv[i],"--num_gpus")==0)) {ppn=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-dm")==0)||(strcmp(argv[i],"--device_map")==0)) {map_device=1; continue;} } MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &me); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); if(map_device) {device = me%ppn; if(device>=skip_gpu) device++;} OpenCLWrapper* opencl = new OpenCLWrapper; if( me == 0) printf("# Platforms: %i\n",opencl->num_platforms); printf("# Proc: %i using device %i\n",me,device); opencl->Init(argc,argv,device,device+1,NULL,platform,subdevice); int error = 0; if(input_file == NULL) error = input(in, "in.lj.miniMD"); else error = input(in, input_file); if (error) { MPI_Finalize(); exit(0); } for(int i=0;i<argc;i++) { if((strcmp(argv[i],"-t")==0)||(strcmp(argv[i],"--num_threads")==0)) {num_threads=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-n")==0)||(strcmp(argv[i],"--nsteps")==0)) {num_steps=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-s")==0)||(strcmp(argv[i],"--size")==0)) {system_size=atoi(argv[++i]); continue;} if((strcmp(argv[i],"--half_neigh")==0)) {halfneigh=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-sse")==0)) {use_sse=atoi(argv[++i]); continue;} if((strcmp(argv[i],"--check_exchange")==0)) {check_safeexchange=1; continue;} if((strcmp(argv[i],"-o")==0)||(strcmp(argv[i],"--yaml_output")==0)) {yaml_output=atoi(argv[++i]); continue;} if((strcmp(argv[i],"--yaml_screen")==0)) {screen_yaml=1; continue;} if((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--data_file") == 0)) { if(in.datafile == NULL) in.datafile = new char[1000]; strcpy(in.datafile, argv[++i]); continue; } if((strcmp(argv[i], "-u") == 0) || (strcmp(argv[i], "--units") == 0)) { in.units = strcmp(argv[++i], "metal") == 0 ? 1 : 0; continue; } if((strcmp(argv[i], "-p") == 0) || (strcmp(argv[i], "--force") == 0)) { in.forcetype = strcmp(argv[++i], "eam") == 0 ? FORCEEAM : FORCELJ; continue; } if((strcmp(argv[i], "-gn") == 0) || (strcmp(argv[i], "--ghost_newton") == 0)) { ghost_newton = atoi(argv[++i]); continue; } if((strcmp(argv[i], "--skip_gpu") == 0)) { skip_gpu = atoi(argv[++i]); continue; } if((strcmp(argv[i], "-b") == 0) || (strcmp(argv[i], "--neigh_bins") == 0)) { neighbor_size = atoi(argv[++i]); continue; } if((strcmp(argv[i],"-tex")==0)||(strcmp(argv[i],"--texture")==0)) {use_tex=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-tpa")==0)) {threads_per_atom=atoi(argv[++i]); continue;} if((strcmp(argv[i],"-h")==0)||(strcmp(argv[i],"--help")==0)) { printf("\n---------------------------------------------------------\n"); printf("-------------" VARIANT_STRING "------------\n"); printf("---------------------------------------------------------\n\n"); printf("miniMD is a simple, parallel molecular dynamics (MD) code,\n" "which is part of the Mantevo project at Sandia National\n" "Laboratories ( http://www.mantevo.org ).\n" "The original authors of MPI based miniMD are Steve Plimpton ([email protected]) ,\n" "Paul Crozier ([email protected]) with current versions \n" "written by Christian Trott ([email protected]).\n\n"); printf("Commandline Options:\n"); printf("\n Execution configuration:\n"); printf("\t-t / --num_threads <threads>: set number of threads per block (default 32)\n"); printf("\t--half_neigh <int>: use half neighborlists (default 0)\n" "\t 0: full neighborlist\n" "\t 1: half neighborlist (not supported in OpenCL variant)\n" "\t -1: original miniMD half neighborlist force \n" "\t (not supported in OpenCL variant)\n"); printf("\t-d / --device <int>: select device (default 0)\n"); printf("\t-dm / --device_map: map devices to MPI ranks\n"); printf("\t-ng / --num_gpus <int>: give number of GPUs per Node (used in conjuction with -dm\n" "\t to determine device id: 'id=mpi_rank%%ng' (default 2)\n"); printf("\t--skip_gpu <int>: skip the specified gpu when assigning devices to MPI ranks\n" "\t used in conjunction with -dm (but must come first in arg list)\n"); printf("\t-p / --platform <int>: select platform (default 0)\n"); printf("\t-sse <sse_version>: use explicit sse intrinsics (use miniMD-SSE variant)\n"); printf("\t-gn / --ghost_newton <int>: set usage of newtons third law for ghost atoms\n" "\t (only applicable with half neighborlists)\n"); printf("\n Simulation setup:\n"); printf("\t-i / --input_file <string>: set input file to be used (default: in.lj.miniMD)\n"); printf("\t-n / --nsteps <nsteps>: set number of timesteps for simulation\n"); printf("\t-s / --size <size>: set linear dimension of systembox and neighbor bins\n"); printf("\t-b / --neigh_bins <int>: set linear dimension of neighbor bin grid\n"); printf("\t-u / --units <string>: set units (lj or metal), see LAMMPS documentation\n"); printf("\t-p / --force <string>: set interaction model (lj or eam)\n"); printf("\t-f / --data_file <string>: read configuration from LAMMPS data file\n"); printf("\n Miscelaneous:\n"); printf("\t--check_exchange: check whether atoms moved further than subdomain width\n"); printf("\t--safe_exchange: perform exchange communication with all MPI processes\n" "\t within rcut_neighbor (outer force cutoff)\n"); printf("\t--yaml_output <int>: level of yaml output (default 0)\n"); printf("\t--yaml_screen: write yaml output also to screen\n"); printf("\t-tex / --texture <int>: use texture cache in force kernel (default 0)\n"); printf("\t-h / --help: display this help message\n\n"); printf("---------------------------------------------------------\n\n"); exit(0); } } Atom atom; Force force; Neighbor neighbor; Integrate integrate; Thermo thermo; Comm comm; Timer timer; ThreadData threads; if(in.forcetype == FORCEEAM) { printf("ERROR: " VARIANT_STRING " does not yet support EAM simulations. Exiting.\n"); MPI_Finalize(); exit(0); } if(ghost_newton!=0) { if(me ==0 ) printf("ERROR: -ghost_newton %i is not supported in " VARIANT_STRING ". Exiting.\n",ghost_newton); MPI_Finalize(); exit(0); } if(halfneigh!=0) { if(me ==0 ) printf("ERROR: -half_neigh %i is not supported in " VARIANT_STRING ". Exiting.\n",halfneigh); MPI_Finalize(); exit(0); } if(halfneigh!=0) { if(me ==0 ) printf("ERROR: -half_neigh %i is not supported in " VARIANT_STRING ". Exiting.\n",halfneigh); MPI_Finalize(); exit(0); } if(use_tex!=0) { if(me ==0 ) printf("ERROR: -tex %i is currently broken. Exiting.\n",use_tex); MPI_Finalize(); exit(0); } if(use_sse) { #ifndef VARIANT_SSE if(me ==0 ) printf("ERROR: Trying to run with -sse with miniMD reference version. Use SSE variant instead. Exiting.\n"); MPI_Finalize(); exit(0); #endif } threads.mpi_me=me; threads.mpi_num_threads=nprocs; threads.omp_me=0; threads.omp_num_threads=num_threads; atom.threads = &threads; comm.threads = &threads; force.threads = &threads; integrate.threads = &threads; neighbor.threads = &threads; thermo.threads = &threads; opencl->blockdim = num_threads; atom.threads_per_atom = threads_per_atom; atom.use_tex = use_tex; comm.do_safeexchange=do_safeexchange; force.use_sse=use_sse; neighbor.halfneigh=halfneigh; compile_kernels(opencl); integrate.opencl = opencl; force.opencl = opencl; neighbor.opencl = opencl; atom.opencl = opencl; comm.opencl = opencl; if(num_steps > 0) in.ntimes = num_steps; if(system_size > 0) { in.nx = system_size; in.ny = system_size; in.nz = system_size; } if(neighbor_size > 0) { neighbor.nbinx = neighbor_size; neighbor.nbiny = neighbor_size; neighbor.nbinz = neighbor_size; } if(neighbor_size < 0 && in.datafile == NULL) { MMD_float neighscale = 5.0 / 6.0; neighbor.nbinx = neighscale * in.nx; neighbor.nbiny = neighscale * in.ny; neighbor.nbinz = neighscale * in.ny; } if(neighbor_size < 0 && in.datafile) neighbor.nbinx = -1; if(neighbor.nbinx == 0) neighbor.nbinx = 1; if(neighbor.nbiny == 0) neighbor.nbiny = 1; if(neighbor.nbinz == 0) neighbor.nbinz = 1; integrate.ntimes = in.ntimes; integrate.dt = in.dt; neighbor.every = in.neigh_every; neighbor.cutneigh = in.neigh_cut; force.cutforce = in.force_cut; thermo.nstat = in.thermo_nstat; if(me == 0) printf("# Create System:\n"); if(in.datafile) { read_lammps_data(atom, comm, neighbor, integrate, thermo, in.datafile, in.units); MMD_float volume = atom.box.xprd * atom.box.yprd * atom.box.zprd; in.rho = 1.0 * atom.natoms / volume; force.setup(); } else { create_box(atom, in.nx, in.ny, in.nz, in.rho); comm.setup(neighbor.cutneigh, atom); neighbor.setup(atom); integrate.setup(); force.setup(); create_atoms(atom, in.nx, in.ny, in.nz, in.rho); thermo.setup(in.rho, integrate, atom, in.units); create_velocity(in.t_request, atom, thermo); } if(me == 0) printf("# Done .... \n"); if(me == 0) { fprintf(stdout, "# " VARIANT_STRING " output ...\n"); fprintf(stdout, "# Systemparameters: \n"); fprintf(stdout, "\t# MPI processes: %i\n", neighbor.threads->mpi_num_threads); fprintf(stdout, "\t# OpenMP threads: %i\n", neighbor.threads->omp_num_threads); fprintf(stdout, "\t# Inputfile: %s\n", input_file == 0 ? "in.lj.miniMD" : input_file); fprintf(stdout, "\t# Datafile: %s\n", in.datafile ? in.datafile : "None"); fprintf(stdout, "\t# ForceStyle: %s\n", in.forcetype == FORCELJ ? "LJ" : "EAM"); fprintf(stdout, "\t# Units: %s\n", in.units == 0 ? "LJ" : "METAL"); fprintf(stdout, "\t# Atoms: %i\n", atom.natoms); fprintf(stdout, "\t# System size: %2.2lf %2.2lf %2.2lf (unit cells: %i %i %i)\n", atom.box.xprd, atom.box.yprd, atom.box.zprd, in.nx, in.ny, in.nz); fprintf(stdout, "\t# Density: %lf\n", in.rho); fprintf(stdout, "\t# Force cutoff: %lf\n", force.cutforce); fprintf(stdout, "\t# Neigh cutoff: %lf\n", neighbor.cutneigh); fprintf(stdout, "\t# Half neighborlists: %i\n", neighbor.halfneigh); fprintf(stdout, "\t# Neighbor bins: %i %i %i\n", neighbor.nbinx, neighbor.nbiny, neighbor.nbinz); fprintf(stdout, "\t# Neighbor frequency: %i\n", neighbor.every); fprintf(stdout, "\t# Timestep size: %lf\n", integrate.dt); fprintf(stdout, "\t# Thermo frequency: %i\n", thermo.nstat); fprintf(stdout, "\t# Ghost Newton: %i\n", ghost_newton); fprintf(stdout, "\t# Use SSE intrinsics: %i\n", force.use_sse); fprintf(stdout, "\t# Do safe exchange: %i\n", comm.do_safeexchange); fprintf(stdout, "\t# Size of float: %i\n\n",sizeof(MMD_float)); } comm.exchange(atom); comm.borders(atom); atom.d_x->upload(); atom.d_v->upload(); //atom.d_vold->upload(); neighbor.build(atom); if (me == 0) printf("# Starting dynamics ...\n"); if (me == 0) printf("# Timestep T U P Time\n"); thermo.compute(0,atom,neighbor,force,timer,comm); force.compute(atom,neighbor,comm.me); timer.barrier_start(TIME_TOTAL); integrate.run(atom,force,neighbor,comm,thermo,timer); timer.barrier_stop(TIME_TOTAL); int natoms; MPI_Allreduce(&atom.nlocal,&natoms,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD); thermo.compute(-1,atom,neighbor,force,timer,comm); if(me == 0) { double time_other=timer.array[TIME_TOTAL]-timer.array[TIME_FORCE]-timer.array[TIME_NEIGH]-timer.array[TIME_COMM]; printf("\n\n"); printf("# Performance Summary:\n"); printf("# MPI_proc OMP_threads nsteps natoms t_total t_force t_neigh t_comm t_other performance perf/thread grep_string t_extra\n"); printf("%i %i %i %i %lf %lf %lf %lf %lf %lf %lf PERF_SUMMARY %lf\n\n\n", nprocs,num_threads,integrate.ntimes,natoms, timer.array[TIME_TOTAL],timer.array[TIME_FORCE],timer.array[TIME_NEIGH],timer.array[TIME_COMM],time_other, 1.0*natoms*integrate.ntimes/timer.array[TIME_TOTAL],1.0*natoms*integrate.ntimes/timer.array[TIME_TOTAL]/nprocs/num_threads,timer.array[TIME_TEST]); } if(yaml_output) output(in,atom,force,neighbor,comm,thermo,integrate,timer,screen_yaml); MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); delete opencl; return 0; }
int run_main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("XtMotifReactor_Test")); XtAppContext app_context; Widget topLevel, goodbye, PressMe, lbl, digits_rc; Widget children[5]; #if defined (HummingBird_X) HCLXmInit (); #endif /* HummingBird_X */ topLevel = XtVaAppInitialize (&app_context, "XTReactor_Test", 0, 0, &argc, argv, 0, static_cast<void *>(0)); digits_rc = create_box(topLevel, "digits_rc"); //"Stop Test" button. goodbye = XtCreateWidget ( (char *) "goodbye", BUTTON_WIDGET, digits_rc, 0, 0); set_label(goodbye, "Stop Test"); //"Press Me" button PressMe = XtCreateWidget ((char *) "PressMe", BUTTON_WIDGET, digits_rc, 0, 0); //Display for event counter lbl = XtCreateWidget ((char *) "label_for_event_one", LABEL_WIDGET, digits_rc, 0, 0); set_label(lbl, "label_for_all_events"); int ac = 0; children[ac++] = goodbye; children[ac++] = PressMe; children[ac++] = lbl; XtManageChildren (children, ac); XtManageChild (digits_rc); //Register callback for "Stop Test" button XtAddCallback (goodbye, PRESS_ME_CALLBACK, Quit, 0); //Register callback for "Press Me" button XtAddCallback (PressMe, PRESS_ME_CALLBACK, inc_count, (XtPointer) lbl); // Register callback for X Timer (void) XtAppAddTimeOut (app_context, 1000, inc_tmo, (XtPointer) lbl); XtRealizeWidget (topLevel); // It will perform X Main Loop ACE_XtReactor reactor (app_context); ACE_Reactor r (&reactor); //Event Handler for ACE Timer. EV_handler evh; ACE_Acceptor <Connection_Handler, ACE_SOCK_ACCEPTOR> acceptor; if (acceptor.open (ACE_INET_Addr ((u_short) SERV_TCP_PORT), &r) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); if (reactor.schedule_timer (&evh, (const void *) lbl, ACE_Time_Value (2), ACE_Time_Value (2))==-1) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) can't register with reactor\n"), -1); ACE_Thread_Manager::instance ()->spawn ((ACE_THR_FUNC) client, 0, THR_NEW_LWP | THR_DETACHED); XtAppMainLoop (XtWidgetToApplicationContext (topLevel)); ACE_END_TEST; return 0; }
/** to initialize the scene with the default one. */ void make_test_scene (int xsize, int ysize) { //camera set_camera (0.f, 4.f, -4.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 90.f, xsize, ysize); //objects Material * plastic = create_plastic_mat (0.6f, 0.5f, 0.5f, 0.6f, 0.5f, 0.5f, 100.f); // ground plane Geometry * plane = create_plane (0.f, -1.f, 0.f, 0.f, 1.f, 0.f); add_object (plane, plastic); // Up row // base objects Geometry *boxLeft = create_box (-2.f, 3.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.25f, 1.f, 1.f, 1.f, 1.f); Geometry *sphereLeft = create_sphere (-2.f, 3.f, 0.f, 0.65f); Geometry *boxCenter = create_box (0.f, 3.25f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.25f, 1.f, 1.f, 1.f, 1.f); Geometry *sphereCenter = create_sphere (0.f, 3.25f, 0.f, 0.65f); Geometry *boxRight = create_box (2.f, 3.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.25f, 1.f, 1.f, 1.f, 1.f); Geometry *sphereRight = create_sphere (2.f, 3.f, 0.f, 0.65f); // CSG objects Geometry *unionUp = create_csg_union (boxLeft, sphereLeft); Geometry *intersectionUp = create_csg_intersection(boxCenter, sphereCenter); Geometry *differenceUp = create_csg_difference(boxRight, sphereRight); add_object (unionUp, plastic); add_object (intersectionUp, plastic); add_object (differenceUp, plastic); // Middle row // base objects Geometry *coneLeft = create_cone(-2.25f, 1.f, -1.25f, -2.25f, 3.f, -1.25f, 0.5f); Geometry *cylinderLeft = create_cylinder(-2.25f, 1.75f, -1.25f, 0.5f, 0.f, 1.f, 0.25f, 1.5f); Geometry *coneCenter = create_cone(0.f, 1.5f, -0.75f, 0.f, 3.5f, -0.75f, 0.5f); Geometry *cylinderCenter = create_cylinder(0.f, 2.25f, -0.75f, 0.5f, 0.f, 1.f, 0.25f, 1.5f); Geometry *coneRight = create_cone(2.25f, 1.f, -1.25f, 2.25f, 3.f, -1.25f, 0.5f); Geometry *cylinderRight = create_cylinder(2.25f, 1.75f, -1.25f, 0.5f, 0.f, 1.f, 0.25f, 1.5f); // CSG objects Geometry * unionDown = create_csg_union (coneLeft, cylinderLeft); Geometry * intersectionDown = create_csg_intersection(coneCenter, cylinderCenter); Geometry * differenceDown = create_csg_difference(coneRight, cylinderRight); add_object (unionDown, plastic); add_object (intersectionDown, plastic); add_object (differenceDown, plastic); // front object char complex_tree[] = "(- (* (bo 0. 2.5 -3.25 1. 0. 0. 0. 0. 1. 1.0 1.0 1.0) (sp 0. 2.5 -3.25 0.65) ) (+ (cy 0. 2.5 -3.25 1.0 0.0 0.0 0.3 1.75) (+ (cy 0. 2.5 -3.25 0.0 1.0 0.0 0.3 1.75) (cy 0. 2.5 -3.25 0.0 0.0 1.0 0.3 1.75) ) ) )"; Geometry *tree = csg_parse(complex_tree); if (tree) add_object (tree, plastic); //lights // Front light -- white add_light (0.f, 5.f, -1.5f, 1.5f, 1.5f, 1.5f); // Back light -- blue add_light (4.f, 2.f, 10.f, 0.1f, 0.1f, 0.9f); // Left light -- red add_light (-4.f, 5.f, -2.f, 0.9f, 0.1f, 0.1f); }
void shelm_about_dialog() { Evas_Object *window, *background, *frame, *box, *icon, *label, *sublabel, *scroller, *textinfo, *buttonbar, *button_close; char buf[PATH_MAX]; window = create_window("shellementary-about", _("About Shellementary"), destroy); background = create_background(window, NULL, EINA_TRUE); elm_win_resize_object_add(window, background); evas_object_show(background); frame = create_frame(window, EINA_FALSE); elm_win_resize_object_add(window, frame); evas_object_show(frame); box = create_box(window, EINA_FALSE); elm_object_content_set(frame, box); evas_object_show(box); snprintf(buf, sizeof(buf), "%s/logo.png", PACKAGE_DATA_DIR); icon = create_icon(window, buf); elm_box_pack_start(box, icon); evas_object_show(icon); snprintf(buf, sizeof(buf), "<b>Shellementary %s</>", PACKAGE_VERSION); label = create_label(window, buf); elm_object_scale_set(label, 1.6); elm_box_pack_end(box, label); evas_object_show(label); sublabel = create_label(window, _("<b>Display dialogs from shell scripts</><br>Written as a zenity replacement, supports the same arguments<br><b>http://svn.enlightenment.org/svn/e/trunk/PROTO/shellementary</><br>Based on great Elementary toolkit by <b>raster</> and C programming language.<br><b>License:</> MIT")); elm_box_pack_end(box, sublabel); evas_object_show(sublabel); scroller = create_scroller(window, EINA_TRUE); elm_box_pack_end(box, scroller); evas_object_show(scroller); textinfo = create_entry(window, EINA_TRUE, NULL, EINA_FALSE, EINA_FALSE, EINA_FALSE); elm_entry_entry_set(textinfo, _("<b>Author:</> quaker ([email protected])<br>" "<br>" "<b>Credits:</><br>" "<b>Carsten Haitzler (raster)</> " "for Enlightenment DR17, great Elementary toolkit and help with developenment<br>" "<b>Christopher Michael (devilhorns)</> " "for help with developenment<br>")); elm_object_content_set(scroller, textinfo); evas_object_show(textinfo); buttonbar = create_box(window, EINA_TRUE); elm_box_pack_end(box, buttonbar); evas_object_show(buttonbar); snprintf(buf, sizeof(buf), "%s/icon-cancel.png", PACKAGE_DATA_DIR); button_close = create_button(window, buf, _("Close")); evas_object_smart_callback_add(button_close, "clicked", destroy, NULL); elm_box_pack_end(buttonbar, button_close); evas_object_show(button_close); evas_object_show(window); }
void shelm_entry_dialog(const char *window_title, const char *window_text, int window_width, int window_height, const char *window_background, const char *entry_text, Eina_Bool entry_hide_text) { Evas_Object *window, *background, *frame, *box, *scroller, *entry, *buttonbar, *button_cancel, *button_ok; char buf[PATH_MAX]; if (window_title) window = create_window("shellementary-entrydialog", window_title, cancel_callback); else window = create_window("shellementary-entrydialog", _("Enter something here"), cancel_callback); background = create_background(window, window_background, EINA_TRUE); elm_win_resize_object_add(window, background); evas_object_show(background); frame = create_frame(window, EINA_TRUE); elm_win_resize_object_add(window, frame); evas_object_show(frame); box = create_box(window, EINA_FALSE); elm_object_content_set(frame, box); evas_object_show(box); if (window_text) { Evas_Object *label; label = create_label(window, window_text); elm_box_pack_end(box, label); evas_object_show(label); } scroller = create_scroller(window, EINA_TRUE); elm_box_pack_end(box, scroller); evas_object_show(scroller); entry = create_entry(window, EINA_TRUE, entry_text, entry_hide_text, EINA_FALSE, EINA_TRUE); elm_object_content_set(scroller, entry); evas_object_show(entry); buttonbar = create_box(window, EINA_TRUE); elm_box_pack_end(box, buttonbar); evas_object_show(buttonbar); snprintf(buf, sizeof(buf), "%s/icon-cancel.png", PACKAGE_DATA_DIR); button_cancel = create_button(window, buf, _("Cancel")); evas_object_smart_callback_add(button_cancel, "clicked", cancel_callback, NULL); elm_box_pack_start(buttonbar, button_cancel); evas_object_show(button_cancel); snprintf(buf, sizeof(buf), "%s/icon-ok.png", PACKAGE_DATA_DIR); button_ok = create_button(window, buf, _("OK")); evas_object_smart_callback_add(button_ok, "clicked", entry_callback, entry); elm_box_pack_end(buttonbar, button_ok); evas_object_show(button_ok); if (!window_width) evas_object_geometry_get(window, NULL, NULL, &window_width, NULL); if (!window_height) evas_object_geometry_get(window, NULL, NULL, NULL, &window_height); evas_object_resize(window, window_width, window_height); evas_object_show(window); }
/* Takes a signature along with positional and named arguments and binds them * into the provided lexpad (actually, anything that has a Hash interface will * do). Returns BIND_RESULT_OK if binding works out, BIND_RESULT_FAIL if there * is a failure and BIND_RESULT_JUNCTION if the failure was because of a * Junction being passed (meaning we need to auto-thread). */ INTVAL Rakudo_binding_bind(PARROT_INTERP, PMC *lexpad, PMC *sig_pmc, PMC *capture, INTVAL no_nom_type_check, STRING **error) { INTVAL i, num_pos_args; INTVAL bind_fail = 0; INTVAL cur_pos_arg = 0; Rakudo_Signature *sig = (Rakudo_Signature *)PMC_data(sig_pmc); PMC *params = sig->params; INTVAL num_params = VTABLE_elements(interp, params); Rakudo_BindVal cur_bv; /* If we do have some named args, we want to make a clone of the hash * to work on. We'll delete stuff from it as we bind, and what we have * left over can become the slurpy hash or - if we aren't meant to be * taking one - tell us we have a problem. */ PMC *named_args_copy = PMCNULL; /* If we have a |$foo that's followed by slurpies, then we can suppress * any future arity checks. */ INTVAL suppress_arity_fail = 0; /* If it's a Parrot capture, it may contain natively typed arguments. * NOTE: This is a really an encapsulation breakage; if Parrot folks * change stuff and this breaks, it's not Parrot's fault. */ struct Pcc_cell * pc_positionals = NULL; /* Set up statics. */ if (!smo_id) setup_binder_statics(interp); /* If we've got a CallContext, just has an attribute with list of named * parameter names. Otherwise, it's probably a Perl 6 Capture and we need * to extract its parts. */ if (capture->vtable->base_type == enum_class_CallContext) { PMC *named_names = VTABLE_get_attr_str(interp, capture, NAMED_str); if (!PMC_IS_NULL(named_names)) { PMC *iter = VTABLE_get_iter(interp, named_names); named_args_copy = Parrot_pmc_new(interp, enum_class_Hash); while (VTABLE_get_bool(interp, iter)) { STRING *name = VTABLE_shift_string(interp, iter); VTABLE_set_pmc_keyed_str(interp, named_args_copy, name, VTABLE_get_pmc_keyed_str(interp, capture, name)); } } GETATTR_CallContext_positionals(interp, capture, pc_positionals); } else if (capture->vtable->base_type == smo_id && STABLE(capture)->type_check(interp, capture, Rakudo_types_capture_get())) { PMC *captype = Rakudo_types_capture_get(); PMC *list_part = VTABLE_get_attr_keyed(interp, capture, captype, LIST_str); PMC *hash_part = VTABLE_get_attr_keyed(interp, capture, captype, HASH_str); capture = Rakudo_isnqplist(list_part) ? list_part : Parrot_pmc_new(interp, enum_class_ResizablePMCArray); if (hash_part->vtable->base_type == enum_class_Hash) { PMC *iter = VTABLE_get_iter(interp, hash_part); named_args_copy = Parrot_pmc_new(interp, enum_class_Hash); while (VTABLE_get_bool(interp, iter)) { STRING *arg_copy_name = VTABLE_shift_string(interp, iter); VTABLE_set_pmc_keyed_str(interp, named_args_copy, arg_copy_name, VTABLE_get_pmc_keyed_str(interp, hash_part, arg_copy_name)); } } } else { Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, "Internal Error: Rakudo_binding_bind passed invalid Capture"); } /* Now we'll walk through the signature and go about binding things. */ num_pos_args = VTABLE_elements(interp, capture); for (i = 0; i < num_params; i++) { Rakudo_Parameter *param = (Rakudo_Parameter *)PMC_data( VTABLE_get_pmc_keyed_int(interp, params, i)); /* Is it looking for us to bind a capture here? */ if (param->flags & SIG_ELEM_IS_CAPTURE) { /* Capture the arguments from this point forwards into a Capture. * Of course, if there's no variable name we can (cheaply) do pretty * much nothing. */ if (STRING_IS_NULL(param->variable_name)) { bind_fail = BIND_RESULT_OK; } else { PMC *captype = Rakudo_types_capture_get(); PMC *capsnap = REPR(captype)->allocate(interp, STABLE(captype)); PMC *pos_args = Parrot_pmc_new(interp, enum_class_ResizablePMCArray); PMC *named_args = Parrot_pmc_new(interp, enum_class_Hash); INTVAL k; VTABLE_set_attr_keyed(interp, capsnap, captype, LIST_str, pos_args); VTABLE_set_attr_keyed(interp, capsnap, captype, HASH_str, named_args); for (k = cur_pos_arg; k < num_pos_args; k++) { cur_bv = get_positional_bind_val(interp, pc_positionals, capture, k); VTABLE_push_pmc(interp, pos_args, cur_bv.type == BIND_VAL_OBJ ? cur_bv.val.o : create_box(interp, cur_bv)); } if (!PMC_IS_NULL(named_args_copy)) { PMC *iter = VTABLE_get_iter(interp, named_args_copy); while (VTABLE_get_bool(interp, iter)) { STRING *name = VTABLE_shift_string(interp, iter); VTABLE_set_pmc_keyed_str(interp, named_args, name, VTABLE_get_pmc_keyed_str(interp, named_args_copy, name)); } } cur_bv.type = BIND_VAL_OBJ; cur_bv.val.o = capsnap; bind_fail = Rakudo_binding_bind_one_param(interp, lexpad, sig, param, cur_bv, no_nom_type_check, error); } if (bind_fail) { return bind_fail; } else if (i + 1 == num_params) { /* Since a capture acts as "the ultimate slurpy" in a sense, if * this is the last parameter in the signature we can return * success right off the bat. */ return BIND_RESULT_OK; } else { Rakudo_Parameter *next_param = (Rakudo_Parameter *)PMC_data( VTABLE_get_pmc_keyed_int(interp, params, i + 1)); if (next_param->flags & (SIG_ELEM_SLURPY_POS | SIG_ELEM_SLURPY_NAMED)) suppress_arity_fail = 1; } } /* Could it be a named slurpy? */ else if (param->flags & SIG_ELEM_SLURPY_NAMED) { /* Can cheat a bit if it's the default method %_. * We give the hash to the lexpad. */ if (param->flags & SIG_ELEM_METHOD_SLURPY_NAMED && lexpad->vtable->base_type == p6l_id) { SETATTR_Perl6LexPad_default_named_slurpy(interp, lexpad, named_args_copy); PARROT_GC_WRITE_BARRIER(interp, lexpad); } else { /* We'll either take the current named arguments copy hash which * will by definition contain all unbound named parameters and use * that, or just create an empty one. */ PMC *slurpy = PMC_IS_NULL(named_args_copy) ? Parrot_pmc_new(interp, enum_class_Hash) : named_args_copy; cur_bv.type = BIND_VAL_OBJ; cur_bv.val.o = Rakudo_binding_create_hash(interp, slurpy); bind_fail = Rakudo_binding_bind_one_param(interp, lexpad, sig, param, cur_bv, no_nom_type_check, error); if (bind_fail) return bind_fail; } /* Nullify named arguments hash now we've consumed it, to mark all * is well. */ named_args_copy = PMCNULL; } /* Otherwise, maybe it's a positional. */ else if (PMC_IS_NULL(param->named_names)) { /* Slurpy or LoL-slurpy? */ if (param->flags & (SIG_ELEM_SLURPY_POS | SIG_ELEM_SLURPY_LOL)) { /* Create Perl 6 array, create RPA of all remaining things, then * store it. */ PMC *temp = Parrot_pmc_new(interp, enum_class_ResizablePMCArray); while (cur_pos_arg < num_pos_args) { cur_bv = get_positional_bind_val(interp, pc_positionals, capture, cur_pos_arg); VTABLE_push_pmc(interp, temp, cur_bv.type == BIND_VAL_OBJ ? cur_bv.val.o : create_box(interp, cur_bv)); cur_pos_arg++; } cur_bv.type = BIND_VAL_OBJ; cur_bv.val.o = param->flags & SIG_ELEM_SLURPY_POS ? Rakudo_binding_create_positional(interp, temp) : Rakudo_binding_create_lol(interp, temp); bind_fail = Rakudo_binding_bind_one_param(interp, lexpad, sig, param, cur_bv, no_nom_type_check, error); if (bind_fail) return bind_fail; } /* Otherwise, a positional. */ else { /* Do we have a value?. */ if (cur_pos_arg < num_pos_args) { /* Easy - just bind that. */ cur_bv = get_positional_bind_val(interp, pc_positionals, capture, cur_pos_arg); bind_fail = Rakudo_binding_bind_one_param(interp, lexpad, sig, param, cur_bv, no_nom_type_check, error); if (bind_fail) return bind_fail; cur_pos_arg++; } else { /* No value. If it's optional, fetch a default and bind that; * if not, we're screwed. Note that we never nominal type check * an optional with no value passed. */ if (param->flags & SIG_ELEM_IS_OPTIONAL) { cur_bv.type = BIND_VAL_OBJ; cur_bv.val.o = Rakudo_binding_handle_optional(interp, param, lexpad); bind_fail = Rakudo_binding_bind_one_param(interp, lexpad, sig, param, cur_bv, 0, error); if (bind_fail) return bind_fail; } else { if (error) *error = Rakudo_binding_arity_fail(interp, params, num_params, num_pos_args, 0); return BIND_RESULT_FAIL; } } } } /* Else, it's a non-slurpy named. */ else { /* Try and get hold of value. */ PMC *value = PMCNULL; INTVAL num_names = VTABLE_elements(interp, param->named_names); INTVAL j; if (!PMC_IS_NULL(named_args_copy)) { for (j = 0; j < num_names; j++) { STRING *name = VTABLE_get_string_keyed_int(interp, param->named_names, j); value = VTABLE_get_pmc_keyed_str(interp, named_args_copy, name); if (!PMC_IS_NULL(value)) { /* Found a value. Delete entry from to-bind args and stop looking. */ VTABLE_delete_keyed_str(interp, named_args_copy, name); break; } } } /* Did we get one? */ if (PMC_IS_NULL(value)) { /* Nope. We'd better hope this param was optional... */ if (param->flags & SIG_ELEM_IS_OPTIONAL) { cur_bv.type = BIND_VAL_OBJ; cur_bv.val.o = Rakudo_binding_handle_optional(interp, param, lexpad); bind_fail = Rakudo_binding_bind_one_param(interp, lexpad, sig, param, cur_bv, 0, error); } else if (!suppress_arity_fail) { if (error) *error = Parrot_sprintf_c(interp, "Required named parameter '%S' not passed", VTABLE_get_string_keyed_int(interp, param->named_names, 0)); return BIND_RESULT_FAIL; } } else { cur_bv.type = BIND_VAL_OBJ; cur_bv.val.o = value; bind_fail = Rakudo_binding_bind_one_param(interp, lexpad, sig, param, cur_bv, 0, error); } /* If we got a binding failure, return it. */ if (bind_fail) return bind_fail; } } /* Do we have any left-over args? */ if (cur_pos_arg < num_pos_args && !suppress_arity_fail) { /* Oh noes, too many positionals passed. */ if (error) *error = Rakudo_binding_arity_fail(interp, params, num_params, num_pos_args, 1); return BIND_RESULT_FAIL; } if (!PMC_IS_NULL(named_args_copy) && VTABLE_elements(interp, named_args_copy)) { /* Oh noes, unexpected named args. */ if (error) { INTVAL num_extra = VTABLE_elements(interp, named_args_copy); PMC *iter = VTABLE_get_iter(interp, named_args_copy); if (num_extra == 1) { *error = Parrot_sprintf_c(interp, "Unexpected named parameter '%S' passed", VTABLE_shift_string(interp, iter)); } else { INTVAL first = 1; STRING *comma = Parrot_str_new(interp, ", ", 0); *error = Parrot_sprintf_c(interp, "%d unexpected named parameters passed (", num_extra); while (VTABLE_get_bool(interp, iter)) { STRING *name = VTABLE_shift_string(interp, iter); if (!first) *error = Parrot_str_concat(interp, *error, comma); else first = 0; *error = Parrot_str_concat(interp, *error, name); } *error = Parrot_str_concat(interp, *error, Parrot_str_new(interp, ")", 0)); } } return BIND_RESULT_FAIL; } /* If we get here, we're done. */ return BIND_RESULT_OK; }
/* Binds a single argument into the lexpad, after doing any checks that are * needed. Also handles any type captures. If there is a sub signature, then * re-enters the binder. Returns one of the BIND_RESULT_* codes. */ static INTVAL Rakudo_binding_bind_one_param(PARROT_INTERP, PMC *lexpad, Rakudo_Signature *signature, Rakudo_Parameter *param, Rakudo_BindVal orig_bv, INTVAL no_nom_type_check, STRING **error) { PMC *decont_value = NULL; INTVAL desired_native; Rakudo_BindVal bv; /* Check if boxed/unboxed expections are met. */ desired_native = param->flags & SIG_ELEM_NATIVE_VALUE; if (desired_native == 0 && orig_bv.type == BIND_VAL_OBJ || desired_native == SIG_ELEM_NATIVE_INT_VALUE && orig_bv.type == BIND_VAL_INT || desired_native == SIG_ELEM_NATIVE_NUM_VALUE && orig_bv.type == BIND_VAL_NUM || desired_native == SIG_ELEM_NATIVE_STR_VALUE && orig_bv.type == BIND_VAL_STR) { /* We have what we want. */ bv = orig_bv; } else if (desired_native == 0) { /* We need to do a boxing operation. */ bv.type = BIND_VAL_OBJ; bv.val.o = create_box(interp, orig_bv); } else { storage_spec spec; decont_value = Rakudo_cont_decontainerize(interp, orig_bv.val.o); spec = REPR(decont_value)->get_storage_spec(interp, STABLE(decont_value)); switch (desired_native) { case SIG_ELEM_NATIVE_INT_VALUE: if (spec.can_box & STORAGE_SPEC_CAN_BOX_INT) { bv.type = BIND_VAL_INT; bv.val.i = REPR(decont_value)->box_funcs->get_int(interp, STABLE(decont_value), OBJECT_BODY(decont_value)); } else { if (error) *error = Parrot_sprintf_c(interp, "Cannot unbox argument to '%S' as a native int", param->variable_name); return BIND_RESULT_FAIL; } break; case SIG_ELEM_NATIVE_NUM_VALUE: if (spec.can_box & STORAGE_SPEC_CAN_BOX_NUM) { bv.type = BIND_VAL_NUM; bv.val.n = REPR(decont_value)->box_funcs->get_num(interp, STABLE(decont_value), OBJECT_BODY(decont_value)); } else { if (error) *error = Parrot_sprintf_c(interp, "Cannot unbox argument to '%S' as a native num", param->variable_name); return BIND_RESULT_FAIL; } break; case SIG_ELEM_NATIVE_STR_VALUE: if (spec.can_box & STORAGE_SPEC_CAN_BOX_STR) { bv.type = BIND_VAL_STR; bv.val.s = REPR(decont_value)->box_funcs->get_str(interp, STABLE(decont_value), OBJECT_BODY(decont_value)); } else { if (error) *error = Parrot_sprintf_c(interp, "Cannot unbox argument to '%S' as a native str", param->variable_name); return BIND_RESULT_FAIL; } break; default: if (error) *error = Parrot_sprintf_c(interp, "Cannot unbox argument to '%S' as a native type", param->variable_name); return BIND_RESULT_FAIL; } decont_value = NULL; } /* By this point, we'll either have an object that we might be able to * bind if it passes the type check, or a native value that needs no * further checking. */ if (bv.type == BIND_VAL_OBJ) { /* Ensure the value is a 6model object; if not, marshall it to one. */ if (bv.val.o->vtable->base_type != smo_id) { bv.val.o = Rakudo_types_parrot_map(interp, bv.val.o); if (bv.val.o->vtable->base_type != smo_id) { *error = Parrot_sprintf_c(interp, "Unmarshallable foreign language value passed for parameter '%S'", param->variable_name); return BIND_RESULT_FAIL; } } /* We pretty much always need to de-containerized value, so get it * right off. */ decont_value = Rakudo_cont_decontainerize(interp, bv.val.o); /* Skip nominal type check if not needed. */ if (!no_nom_type_check) { PMC *nom_type; /* Is the nominal type generic and in need of instantiation? (This * can happen in (::T, T) where we didn't learn about the type until * during the signature bind). */ if (param->flags & SIG_ELEM_NOMINAL_GENERIC) { PMC *HOW = STABLE(param->nominal_type)->HOW; PMC *ig = VTABLE_find_method(interp, HOW, INSTANTIATE_GENERIC_str); Parrot_ext_call(interp, ig, "PiPP->P", HOW, param->nominal_type, lexpad, &nom_type); } else { nom_type = param->nominal_type; } /* If not, do the check. If the wanted nominal type is Mu, then * anything goes. */ if (nom_type != Rakudo_types_mu_get() && (decont_value->vtable->base_type != smo_id || !STABLE(decont_value)->type_check(interp, decont_value, nom_type))) { /* Type check failed; produce error if needed. */ if (error) { PMC * got_how = STABLE(decont_value)->HOW; PMC * exp_how = STABLE(nom_type)->HOW; PMC * got_name_meth = VTABLE_find_method(interp, got_how, NAME_str); PMC * exp_name_meth = VTABLE_find_method(interp, exp_how, NAME_str); STRING * expected, * got; Parrot_ext_call(interp, got_name_meth, "PiP->S", got_how, bv.val.o, &got); Parrot_ext_call(interp, exp_name_meth, "PiP->S", exp_how, nom_type, &expected); *error = Parrot_sprintf_c(interp, "Nominal type check failed for parameter '%S'; expected %S but got %S instead", param->variable_name, expected, got); } /* Report junction failure mode if it's a junction. */ return junc_or_fail(interp, decont_value); } /* Also enforce definedness constraints. */ if (param->flags & SIG_ELEM_DEFINEDNES_CHECK) { INTVAL defined = IS_CONCRETE(decont_value); if (defined && param->flags & SIG_ELEM_UNDEFINED_ONLY) { if (error) *error = Parrot_sprintf_c(interp, "Parameter '%S' requires a type object, but an object instance was passed", param->variable_name); return junc_or_fail(interp, decont_value); } if (!defined && param->flags & SIG_ELEM_DEFINED_ONLY) { if (error) *error = Parrot_sprintf_c(interp, "Parameter '%S' requires an instance, but a type object was passed", param->variable_name); return junc_or_fail(interp, decont_value); } } } } /* Do we have any type captures to bind? */ if (!PMC_IS_NULL(param->type_captures)) { Rakudo_binding_bind_type_captures(interp, lexpad, param, bv); } /* Do a coercion, if one is needed. */ if (!PMC_IS_NULL(param->coerce_type)) { /* Coercing natives not possible - nothing to call a method on. */ if (bv.type != BIND_VAL_OBJ) { *error = Parrot_sprintf_c(interp, "Unable to coerce natively typed parameter '%S'", param->variable_name); return BIND_RESULT_FAIL; } /* Only coerce if we don't already have the correct type. */ if (!STABLE(decont_value)->type_check(interp, decont_value, param->coerce_type)) { PMC *coerce_meth = VTABLE_find_method(interp, decont_value, param->coerce_method); if (!PMC_IS_NULL(coerce_meth)) { Parrot_ext_call(interp, coerce_meth, "Pi->P", decont_value, &decont_value); } else { /* No coercion method availale; whine and fail to bind. */ if (error) { PMC * got_how = STABLE(decont_value)->HOW; PMC * got_name_meth = VTABLE_find_method(interp, got_how, NAME_str); STRING * got; Parrot_ext_call(interp, got_name_meth, "PiP->S", got_how, decont_value, &got); *error = Parrot_sprintf_c(interp, "Unable to coerce value for '%S' from %S to %S; no coercion method defined", param->variable_name, got, param->coerce_method); } return BIND_RESULT_FAIL; } } } /* If it's not got attributive binding, we'll go about binding it into the * lex pad. */ if (!(param->flags & SIG_ELEM_BIND_ATTRIBUTIVE) && !STRING_IS_NULL(param->variable_name)) { /* Is it native? If so, just go ahead and bind it. */ if (bv.type != BIND_VAL_OBJ) { switch (bv.type) { case BIND_VAL_INT: VTABLE_set_integer_keyed_str(interp, lexpad, param->variable_name, bv.val.i); break; case BIND_VAL_NUM: VTABLE_set_number_keyed_str(interp, lexpad, param->variable_name, bv.val.n); break; case BIND_VAL_STR: VTABLE_set_string_keyed_str(interp, lexpad, param->variable_name, bv.val.s); break; } } /* Otherwise it's some objecty case. */ else if (param->flags & SIG_ELEM_IS_RW) { /* XXX TODO Check if rw flag is set; also need to have a * wrapper container that carries extra constraints. */ VTABLE_set_pmc_keyed_str(interp, lexpad, param->variable_name, bv.val.o); } else if (param->flags & SIG_ELEM_IS_PARCEL) { /* Just bind the thing as is into the lexpad. */ VTABLE_set_pmc_keyed_str(interp, lexpad, param->variable_name, bv.val.o); } else { /* If it's an array, copy means make a new one and store, * and a normal bind is a straightforward binding plus * adding a constraint. */ if (param->flags & SIG_ELEM_ARRAY_SIGIL) { PMC *bindee = decont_value; if (param->flags & SIG_ELEM_IS_COPY) { bindee = Rakudo_binding_create_positional(interp, Parrot_pmc_new(interp, enum_class_ResizablePMCArray)); Rakudo_cont_store(interp, bindee, decont_value, 0, 0); } VTABLE_set_pmc_keyed_str(interp, lexpad, param->variable_name, bindee); } /* If it's a hash, similar approach to array. */ else if (param->flags & SIG_ELEM_HASH_SIGIL) { PMC *bindee = decont_value; if (param->flags & SIG_ELEM_IS_COPY) { bindee = Rakudo_binding_create_hash(interp, Parrot_pmc_new(interp, enum_class_Hash)); Rakudo_cont_store(interp, bindee, decont_value, 0, 0); } VTABLE_set_pmc_keyed_str(interp, lexpad, param->variable_name, bindee); } /* If it's a scalar, we always need to wrap it into a new * container and store it, for copy or ro case (the rw bit * in the container descriptor takes care of the rest). */ else { PMC *new_cont = Rakudo_cont_scalar_from_descriptor(interp, param->container_descriptor); Rakudo_cont_store(interp, new_cont, decont_value, 0, 0); VTABLE_set_pmc_keyed_str(interp, lexpad, param->variable_name, new_cont); } } } /* Is it the invocant? If so, also have to bind to self lexical. */ if (param->flags & SIG_ELEM_INVOCANT) VTABLE_set_pmc_keyed_str(interp, lexpad, SELF_str, decont_value); /* Handle any constraint types (note that they may refer to the parameter by * name, so we need to have bound it already). */ if (!PMC_IS_NULL(param->post_constraints)) { PMC * code_type = Rakudo_types_code_get(); PMC * const constraints = param->post_constraints; INTVAL num_constraints = VTABLE_elements(interp, constraints); INTVAL i; for (i = 0; i < num_constraints; i++) { /* Check we meet the constraint. */ PMC *cons_type = VTABLE_get_pmc_keyed_int(interp, constraints, i); PMC *accepts_meth = VTABLE_find_method(interp, cons_type, ACCEPTS); PMC *old_ctx = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp)); PMC *cappy = Parrot_pmc_new(interp, enum_class_CallContext); if (STABLE(cons_type)->type_check(interp, cons_type, code_type)) Parrot_sub_capture_lex(interp, VTABLE_get_attr_keyed(interp, cons_type, code_type, DO_str)); VTABLE_push_pmc(interp, cappy, cons_type); switch (bv.type) { case BIND_VAL_OBJ: VTABLE_push_pmc(interp, cappy, bv.val.o); break; case BIND_VAL_INT: VTABLE_push_integer(interp, cappy, bv.val.i); break; case BIND_VAL_NUM: VTABLE_push_float(interp, cappy, bv.val.n); break; case BIND_VAL_STR: VTABLE_push_string(interp, cappy, bv.val.s); break; } Parrot_pcc_invoke_from_sig_object(interp, accepts_meth, cappy); cappy = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp)); Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), old_ctx); if (!VTABLE_get_bool(interp, VTABLE_get_pmc_keyed_int(interp, cappy, 0))) { if (error) *error = Parrot_sprintf_c(interp, "Constraint type check failed for parameter '%S'", param->variable_name); return BIND_RESULT_FAIL; } } } /* If it's attributive, now we assign it. */ if (param->flags & SIG_ELEM_BIND_ATTRIBUTIVE) { INTVAL result = Rakudo_binding_assign_attributive(interp, lexpad, param, bv, decont_value, error); if (result != BIND_RESULT_OK) return result; } /* If it has a sub-signature, bind that. */ if (!PMC_IS_NULL(param->sub_llsig) && bv.type == BIND_VAL_OBJ) { /* Turn value into a capture, unless we already have one. */ PMC *capture = PMCNULL; INTVAL result; if (param->flags & SIG_ELEM_IS_CAPTURE) { capture = decont_value; } else { PMC *meth = VTABLE_find_method(interp, decont_value, Parrot_str_new(interp, "Capture", 0)); if (PMC_IS_NULL(meth)) { if (error) *error = Parrot_sprintf_c(interp, "Could not turn argument into capture"); return BIND_RESULT_FAIL; } Parrot_ext_call(interp, meth, "Pi->P", decont_value, &capture); } /* Recurse into signature binder. */ result = Rakudo_binding_bind(interp, lexpad, param->sub_llsig, capture, no_nom_type_check, error); if (result != BIND_RESULT_OK) { if (error) { /* Note in the error message that we're in a sub-signature. */ *error = Parrot_str_concat(interp, *error, Parrot_str_new(interp, " in sub-signature", 0)); /* Have we a variable name? */ if (!STRING_IS_NULL(param->variable_name)) { *error = Parrot_str_concat(interp, *error, Parrot_str_new(interp, " of parameter ", 0)); *error = Parrot_str_concat(interp, *error, param->variable_name); } } return result; } } /* Binding of this parameter was thus successful - we're done. */ return BIND_RESULT_OK; }
int main(int argc, char *argv[]) { //initialize global variable index1=0; // index of movie list index2=0; // index of smi list index_inside_movie=TRUE; // initialize varables int ch; WIN win; WIN win2; WINDOW *popup_win; // init ncurses window initscr(); cbreak(); //raw(); keypad(stdscr, TRUE); noecho(); curs_set(0); if(has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); exit(1); } start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_BLACK, COLOR_YELLOW); // print headline int start_line_number = print_headline(); // load local files. loadFiles("."); // sorting std::sort(vMovieFiles.begin(), vMovieFiles.end(), sortOp); std::sort(vSmiFiles.begin(), vSmiFiles.end(), sortOp); // listFiles return 0 when no error if(listFiles() == 0) { init_win_params(&win, start_line_number+2, 0, 0, vMovieFiles.size() + 1); init_win_params(&win2, start_line_number+3+vMovieFiles.size()+3, 0, 0, vSmiFiles.size() + 1); create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); while( (ch = getch()) != 'q') { switch(ch) { case 'j': case KEY_DOWN: { create_box(&win, FALSE,1); create_box(&win2, FALSE,1); if(index_inside_movie == TRUE) { if(index1 == vMovieFiles.size()-1) { index1 = 0; } else { index1++; } } else { if(index2 == vSmiFiles.size()-1) { index2 =0; } else { index2++; } } create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); break; } case 'k': case KEY_UP: { create_box(&win, FALSE,1); create_box(&win2, FALSE,1); if(index_inside_movie == TRUE) { if(index1 == 0) { index1 = vMovieFiles.size()-1; } else { index1--; } } else { if(index2 == 0) { index2 = vSmiFiles.size()-1; } else { index2--; } } create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); break; } case '\t': case KEY_BTAB: { index_inside_movie = !index_inside_movie; create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); break; } case 'd': { std::string popup_msg = "delete?(d/esc)"; popup_win = create_win(3, popup_msg.length()+3, start_line_number+5,(int)COLS/2-popup_msg.length(),popup_msg); wrefresh(popup_win); int ch2; while( (ch2=getch()) != 'e') { switch(ch2) { case 'd': { if(index_inside_movie) { std::vector<std::string>::iterator iter1=vMovieFiles.begin(); if(vMovieFiles.size()!=1){ if(index1 == vMovieFiles.size()-1){ vMovieFiles.erase(iter1 + index1); index1--; } else vMovieFiles.erase(iter1 + index1); } start_line_number = print_headline(); init_win_params(&win, start_line_number+2, 0, 0, vMovieFiles.size() + 1); init_win_params(&win2, start_line_number+3+vMovieFiles.size()+3, 0, 0, vSmiFiles.size() + 1); } else { std::vector<std::string>::iterator iter2=vSmiFiles.begin(); if(vSmiFiles.size()!=1){ if(index2 == vSmiFiles.size()-1){ vSmiFiles.erase(iter2 + index2); index2--; } else vSmiFiles.erase(iter2 + index2); } start_line_number = print_headline(); init_win_params(&win, start_line_number+2, 0, 0, vMovieFiles.size() + 1); init_win_params(&win2, start_line_number+3+vMovieFiles.size()+3, 0, 0, vSmiFiles.size() + 1); } break; } case 'e': { delwin(popup_win); break; } } // switch if(ch2 == 'd') break; } //while clear(); int start_line_number = print_headline(); create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); break; } // case d case ' ': //case space for selection to move { create_box(&win, TRUE,2); create_box2(&win2, TRUE,2); wrefresh(stdscr); std::string popup_msg = "down/up/esc?(j/k/e)"; popup_win = create_win(3, popup_msg.length()+3, start_line_number+5,(int)COLS/2-popup_msg.length()/2,popup_msg); wrefresh(popup_win); int ch3; while( (ch3=getch()) != 'e') { switch(ch3) { case 'j': case KEY_DOWN: { swapVector(true); break; } case 'k': case KEY_UP: { swapVector(false); break; } case 'e': { delwin(popup_win); break; } } // end of switch if(ch3 == 'j' || ch3 == 'k' || ch3 == KEY_DOWN || ch3 == KEY_UP) break; } // while clear(); int start_line_number = print_headline(); create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); break; //end of case space } // case space case 'y': { // if counts are mismatched if(vMovieFiles.size() != vSmiFiles.size()) { std::string popup_msg = "Mismatch Error! (e)"; popup_win = create_win(3, popup_msg.length()+3, start_line_number+5,(int)COLS/2-popup_msg.length()/2,popup_msg); wrefresh(popup_win); int ch5; while ( (ch5=getch()) != 'e') { switch(ch5) { case 'e': { delwin(popup_win); break; } } if(ch5 == 'e') break; } clear(); int start_line_number = print_headline(); create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); break; } // end of if statement = counts are mismatched std::string popup_msg = "confirm?(m)ovies (s)ubtitle(m/s/e)"; popup_win = create_win(3, popup_msg.length()+3, start_line_number+5,(int)COLS/2-popup_msg.length()/2,popup_msg); wrefresh(popup_win); int ch4; while( (ch4=getch()) != 'e') { switch(ch4) { case 'm': { int err = renameSmiFiles(); std::cout << "err: " << err << std::endl; break; } case 's': { int err = renameAviFiles(); std::cout << "err: " << err << std::endl; break; } case 'e': { delwin(popup_win); break; } } // end of switch if(ch4 == 'm' || ch4 == 's') break; } // while // rename it then files reloading // load local files. loadFiles("."); // sorting std::sort(vMovieFiles.begin(), vMovieFiles.end(), sortOp); std::sort(vSmiFiles.begin(), vSmiFiles.end(), sortOp); clear(); init_win_params(&win, start_line_number+2, 0, 0, vMovieFiles.size() + 1); init_win_params(&win2, start_line_number+3+vMovieFiles.size()+3, 0, 0, vSmiFiles.size() + 1); int start_line_number = print_headline(); create_box(&win, TRUE,1); create_box2(&win2, TRUE,1); break; // end of case y } // case y } // switch } // while } else { endwin(); std::cout << "You don't have No relative files... Bye..." << std::endl; return 1; } // delete ncurses window endwin(); return 0; } //end of main