int test_point (int x, int y, int i, int j) { return test_line (x,y,i,j)& test_line (x,y,i+1,j)& test_line (x,y,i,j+1)& test_line (x,y,i+1,j+1); }
void parse(t_env *env) { char *line; char **tab; t_point *cur; cur = env->map; while (get_next_line(env->arg.fd, &line) > 0) { test_line(env, line); tab = ft_strsplit(line, ' '); ft_strdel(&line); env->map_x = 0; while (tab[env->map_x] != NULL) { cur->next = new_pt(env->map_x, env->map_y, atoi(tab[env->map_x])); cur = cur->next; env->map_x += 1; } destroy_tab(tab); env->map_y += 1; } ft_strdel(&line); (env->map_y == 0 ? error(env, 1) : 0); define_map(env); (close(env->arg.fd) == -1 ? error(env, 4) : 0); }
enum piglit_result piglit_display(void) { int i; bool pass = true; piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_LINE_STIPPLE); glPushMatrix(); glTranslatef(basex, basey, 0.0); for (i = 0; i < ARRAY_SIZE(Lines); ++i) { printf("Testing %s:\n", Lines[i].name); if (test_line(&Lines[i])) { piglit_report_subtest_result(PIGLIT_PASS, "%s", Lines[i].name); } else { piglit_report_subtest_result(PIGLIT_FAIL, "%s", Lines[i].name); pass = false; } } glPopMatrix(); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
int main ( const int argc, const char * const * const argv ) /*@globals errno, fileSystem, stderr, stdout@*/ /*@modifies errno, fileSystem, stderr, stdout@*/ { int verbose = 0, i; for (i = 1; i < argc; ++i) { const char * const arg = argv[i]; if (0 == strcmp("-v", arg)) { verbose = 1; } } if (test_line (verbose) && test_lines (verbose) && test_lineread (verbose) && test_lang (verbose)) { (void)puts("SUCCESS"); return EXIT_SUCCESS; } else { (void)fputs("FAILURE\n", stderr); return EXIT_FAILURE; } }
int main (int argc, char *argv[]) { // parameters int i1, i2, N; char *token = NULL; FILE *m_File; // command line args configuration i1 = (int) atoi(argv[1]); i2 = (int) atoi(argv[2]); N = (int) atoi(argv[3]); if (argc > 4) { token = (char *) calloc(4, sizeof(char)); token = "tmp"; } // test test_column m_File = fopen("files/test.txt","r"); test_column("files/test.txt",m_File, i1, 10, N, token); // test test_line test_line("files/test.txt", m_File, i2, N); return 0; }
int main(int argc, char* argv[]) { // check for lua debugger mode if(argc > 1 && strcmp(argv[1], "-d") == 0) _debug = 1; init(APP_TITLE); const char* ln = test_line(0); tfont_set_text_buf(0, 0, ln); // setup key input glfwSetKeyCallback(cb_glfw_key); // setup lua init_lua(); // main loop while(_run) { //printf("top of main loop: _run: %d\n", _run); // enter lua debugger mode if(_debug) { _debug = 0; debug_enter(L); if(!_run) break; } // do lua timer tick tick(); glClear(GL_COLOR_BUFFER_BIT); lua_draw(); draw_text(); report_fps(); glfwSwapBuffers(); // error check error_check(); // exit check // exit_check(&run); if(!glfwGetWindowParam(GLFW_OPENED)) tf_edit_quit(); fps_inc_frames_drawn(); } glfwTerminate(); return 0; }
void read_ancestrymap (char* input_file, int N, int M, int* data) { FILE *File = NULL; int i, j, allele; char tmp[512] = ""; char ref[512] = ""; int max_char_per_line = 1000; char szbuff[max_char_per_line]; int warning = 0; // open input file File = fopen_read(input_file); j = 0; i = 0; // while not the end of the file // or not too many SNPs (j < M-1) // or last SNP but not too many ind (j == (M-1) && i< N)) while (fgets(szbuff,max_char_per_line, File) && (j < M-1 || (j == (M-1) && i< N))) { // read line read_line_ancestrymap(szbuff, &allele, tmp, i+1, j+1, input_file, &warning); // first SNP, save SNP name if (j == 0 && i == 0) strcpy(ref, tmp); // new SNP if (strcmp(ref, tmp) != 0) { // test if the number indiviual for the line is ok test_column (input_file, File, i, j+1, N, NULL); // new line i = 0; j++; // save new SNP name strcpy(ref, tmp); } // write genotype data[i * M + j] = allele; i++; } test_column (input_file, File, i, j+1, N, NULL); // test the number of lines test_line(input_file, File, j+1, M); fclose(File); }
void test_map(t_en *en) { int i; int j; i = 0; j = 0; while (en->bufmap[i]) { j = test_line(en->bufmap[i]); if (ft_strlen(en->bufmap[i]) != (size_t)j) error_exit("Error : Wrong format"); i++; } }
void tetris::world(bool fall) { if (_l_object.get() == NULL) _l_object.add(_objects); if (touch_down() == false && fall) _l_object.get()->fall(_world); _l_object.actualise(_world); if (_fall == false) { game_over(); test_line(); _l_object.add(_objects); _fall = true; } }
void draw_text() { int ch_rows = 36; int ch_h = 16; float x = 0; float y = win_height(); int i; for(i = 0; i < ch_rows; ++i) { x = 0; y -= ch_h; glPushMatrix(); glTranslatef(x, y, 0); const char* ln = test_line(i); tfont_draw_string(ln); glPopMatrix(); } }
static void test(void) { int i; glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_LINE_STIPPLE); glPushMatrix(); glTranslatef(basex, basey, 0.0); for(i = 0; i < sizeof(Lines)/sizeof(Lines[0]); ++i) test_line(&Lines[i]); glPopMatrix(); glutSwapBuffers(); }
void read_data_int(char *file_data, int N, int M, int *dat) { FILE *m_File = NULL; int i = 0; int j = 0; int max_char_per_line = MAX_LENGTH_NB_INT * M + 20; char *szbuff; char *token; // allocate memory szbuff = (char *) malloc(max_char_per_line * sizeof(char)); // open file m_File = fopen_read(file_data); i = 0; while (fgets(szbuff, max_char_per_line, m_File) && (i < N)) { j = 0; // cut line with split character SEP (" ") token = strtok(szbuff, SEP); // read elements and register them in dat while (token && j < M) { //printf("%s\n",token); dat[i * M + j] = (int)atof(token); // next elements token = strtok(NULL, SEP); j++; } i++; // check the number of columns test_column(file_data, m_File, j, i, M, token); } // check the number of lines test_line(file_data, m_File, i, N); // close file fclose(m_File); // free memory free(szbuff); }
/* +----+----+----+ | | | | +----+----+----+ | | | | +----+----+----+ */ static void create_tcoords() { int num_cols = NCOLS; int num_rows = NROWS; int num_chars = num_cols * num_rows; _num_tcoords = num_chars * 4; int num_floats = _num_tcoords * 2; _tcoords = (float*) malloc(num_floats * sizeof(float)); int i, j, k; k = 0; float x; float y = win_height() + _ch_h; for(i = 0; i < num_rows; ++i) { const char* ln = test_line(i); x = 0; y -= _ch_h; for(j = 0; j < num_cols; ++j) { unsigned char ch = ln[j]; tfont_get_tex_idx(ch, _tcoords+k); k += 8; x += _ch_w; } } }
int main(int argc, char **argv) { printf("1..6\n"); test_line(test_eui64_line_id, &test_eui64_id, test_eui64_id_host); test_line(test_eui64_line_id_colon, &test_eui64_id, test_eui64_id_host); test_line(test_eui64_line_eui48, &test_eui64_eui48, test_eui64_eui48_host); test_line(test_eui64_line_mac48, &test_eui64_mac48, test_eui64_mac48_host); test_line(test_eui64_line_eui48_6byte, &test_eui64_eui48, test_eui64_eui48_host); test_line(test_eui64_line_eui48_6byte_c, &test_eui64_eui48, test_eui64_eui48_host); return (0); }
void user_menu_cmd (void) { char *menu, *p; int col, i, accept_entry = 1; int selected, old_patterns; Listbox *listbox; if (!vfs_current_is_local ()){ message (1, _(" Oops... "), _(" I can't run programs while logged on a non local directory ")); return; } menu = strdup (MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)){ free (menu); #ifdef OS2_NT menu = strdup("NC.MNU"); if (!exist_file (menu)) #endif { menu = concat_dir_and_file (home_dir, MC_HOME_MENU); if (!exist_file (menu)){ free (menu); menu = concat_dir_and_file (mc_home, MC_GLOBAL_MENU); } } } if ((data = load_file (menu)) == NULL){ message (1, MSG_ERROR, _(" Can't open file %s \n %s "), menu, unix_error_string (errno)); free (menu); return; } free (menu); max_cols = 0; for (i = 0; i < MAX_ENTRIES; i++) entries [i] = 0; selected = 0; /* Parse the menu file */ old_patterns = easy_patterns; p = check_patterns (data); for (menu_lines = col = 0; *p; p++){ if (col == 0 && !entries [menu_lines]){ if (*p == '#'){ /* A commented menu entry */ accept_entry = 1; } else if (*p == '+'){ if (*(p+1) == '='){ /* Combined adding and default */ char *q = p++; p = test_line (q, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ p = test_line (p, &accept_entry); } } else if (*p == '='){ if (*(p+1) == '+'){ char *q = p++; /* Combined adding and default */ p = test_line (q, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; p = test_line (p, &i); if (selected == 0 && i) selected = menu_lines; } } else if (*p > ' ' && *p < 127){ /* A menu entry title line */ if (accept_entry) entries [menu_lines] = p; else accept_entry = 1; } } if (menu_lines == MAX_ENTRIES) break; if (*p == '\t') *p = ' '; col++; if (*p == '\n'){ if (entries [menu_lines]){ menu_lines++; accept_entry = 1; } max_cols = max (max_cols, col); col = 0; } } max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) LISTBOX_APPEND_TEXT (listbox, entries [i][0], extract_line (entries [i], entries [i]+MAX_ENTRY_LEN), entries [i]); /* Select the default entry */ listbox_select_by_number (listbox->list, selected); selected = run_listbox (listbox); if (selected >= 0) execute_menu_command (entries [selected]); easy_patterns = old_patterns; do_refresh (); free (data); }
int TestGdiLine(int argc, char* argv[]) { int rc = -1; UINT32 x, i; gdiPalette g; const UINT32 RawFormat = PIXEL_FORMAT_RGB8; const UINT32 colorFormats[] = { PIXEL_FORMAT_RGB15, PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_RGB24, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_ABGR15, PIXEL_FORMAT_BGR16, PIXEL_FORMAT_BGR24, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; const UINT32 number_formats = sizeof(colorFormats) / sizeof(colorFormats[0]); for (i = 0; i < number_formats; i++) { HGDI_DC hdc = NULL; HGDI_PEN pen = NULL; HGDI_BITMAP hBmp = NULL; struct ropMap rop_map[] = { {GDI_R2_BLACK, NULL, line_to_R2_BLACK}, {GDI_R2_NOTMERGEPEN, NULL, line_to_R2_NOTMERGEPEN}, {GDI_R2_MASKNOTPEN, NULL, line_to_R2_MASKNOTPEN}, {GDI_R2_NOTCOPYPEN, NULL, line_to_R2_NOTCOPYPEN}, {GDI_R2_MASKPENNOT, NULL, line_to_R2_MASKPENNOT}, {GDI_R2_NOT, NULL, line_to_R2_NOT}, {GDI_R2_XORPEN, NULL, line_to_R2_XORPEN}, {GDI_R2_NOTMASKPEN, NULL, line_to_R2_NOTMASKPEN}, {GDI_R2_MASKPEN, NULL, line_to_R2_MASKPEN}, {GDI_R2_NOTXORPEN, NULL, line_to_R2_NOTXORPEN}, {GDI_R2_NOP, NULL, line_to_R2_NOP}, {GDI_R2_MERGENOTPEN, NULL, line_to_R2_MERGENOTPEN}, {GDI_R2_COPYPEN, NULL, line_to_R2_COPYPEN}, {GDI_R2_MERGEPENNOT, NULL, line_to_R2_MERGEPENNOT}, {GDI_R2_MERGEPEN, NULL, line_to_R2_MERGEPEN}, {GDI_R2_WHITE, NULL, line_to_R2_WHITE} }; const UINT32 map_size = sizeof(rop_map) / sizeof(rop_map[0]); HGDI_BITMAP hBmp_LineTo[LINTETO_NUMBER] = {NULL}; gdiPalette* hPalette = &g; UINT32 penColor; const UINT32 format = colorFormats[i]; g.format = format; for (i = 0; i < 256; i++) g.palette[i] = GetColor(format, i, i, i, 0xFF); rc = -1; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); goto fail; } hdc->format = format; gdi_SetNullClipRgn(hdc); penColor = GetColor(format, 0xFF, 0xFF, 0xFF, 0xFF); if (!(pen = gdi_CreatePen(1, 1, penColor, format, hPalette))) { printf("gdi_CreatePen failed\n"); goto fail; } gdi_SelectObject(hdc, (HGDIOBJECT) pen); hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16); gdi_SelectObject(hdc, (HGDIOBJECT) hBmp); for (x = 0; x < LINTETO_NUMBER; x++) { hBmp_LineTo[x] = test_convert_to_bitmap(line_to_case[x], RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!hBmp_LineTo[x]) goto fail; } for (x = 0; x < map_size; x++) { rop_map[x].bmp = test_convert_to_bitmap(rop_map[x].src, RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!rop_map[x].bmp) goto fail; } if (!test_line(hdc, hPalette, 0, 0, 15, 15, hBmp, hBmp_LineTo[0], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 15, 0, 0, hBmp, hBmp_LineTo[1], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 0, 0, 15, hBmp, hBmp_LineTo[2], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 15, 15, 0, hBmp, hBmp_LineTo[3], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 8, 15, 8, hBmp, hBmp_LineTo[4], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 8, 0, 8, hBmp, hBmp_LineTo[5], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 8, 0, 8, 15, hBmp, hBmp_LineTo[6], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 8, 15, 8, 0, hBmp, hBmp_LineTo[7], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 4, 4, 12, 12, hBmp, hBmp_LineTo[8], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 0, 16, 16, hBmp, hBmp_LineTo[9], 5, 5, 8, 8)) goto fail; if (!test_line(hdc, hPalette, 0, 0, 26, 26, hBmp, hBmp_LineTo[10], 0, 0, 16, 16)) goto fail; for (x = 0; x < map_size; x++) { char name[1024]; _snprintf(name, sizeof(name), "%s [%s]", gdi_rop_to_string(rop_map[x].rop), GetColorFormatName(hdc->format)); /* Test Case 13: (0,0) -> (16,16), R2_NOTMERGEPEN */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette)) { printf("gdi_BitBlt failed (line #%u)\n", __LINE__); goto fail; } gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, rop_map[x].rop); gdi_LineTo(hdc, 16, 16); if (!test_assert_bitmaps_equal(hBmp, rop_map[x].bmp, name, hPalette)) goto fail; } rc = 0; fail: for (x = 0; x < LINTETO_NUMBER; x++) gdi_DeleteObject((HGDIOBJECT) hBmp_LineTo[x]); for (x = 0; x < map_size; x++) gdi_DeleteObject((HGDIOBJECT) rop_map[x].bmp); gdi_DeleteObject((HGDIOBJECT) pen); gdi_DeleteDC(hdc); if (rc != 0) break; } return rc; }
static int proc_args(int argc, char *argv[]) { unsigned short mode, delay, x, y, size, initial_x, initial_y, final_x, final_y, horizontal, time; unsigned long color; short distance; if (strncmp(argv[1], "init", 4) == 0) { if (argc != 4) { printf("wrong no of arguments for test_init()\n"); return 1; } if ((mode = (unsigned short) parse_long(argv[2], 16)) == LONG_MAX) return 1; if ((delay = (unsigned short) parse_long(argv[3], 10)) == LONG_MAX) return 1; printf("test_init(0x%x, %d)\n", mode, delay); test_init(mode, delay); return 0; } else if (strncmp(argv[1], "square", 6) == 0) { if (argc != 6) { printf("wrong no of arguments for test_square()\n"); return 1; } if ((x = (unsigned short) parse_long(argv[2], 10)) == LONG_MAX) return 1; if ((y = (unsigned short) parse_long(argv[3], 10)) == LONG_MAX) return 1; if ((size = (unsigned short) parse_long(argv[4], 10)) == LONG_MAX) return 1; if ((color = (unsigned long) parse_long(argv[5], 10)) == LONG_MAX) return 1; printf("test_square(%d, %d, %d, %d)\n", x, y, size, color); return test_square(x, y, size, color); } else if (strncmp(argv[1], "line", 4) == 0) { if (argc != 7) { printf("wrong no of arguments for test_line()\n"); return 1; } if ((initial_x = (unsigned short) parse_long(argv[2], 10)) == LONG_MAX) return 1; if ((initial_y = (unsigned short) parse_long(argv[3], 10)) == LONG_MAX) return 1; if ((final_x = (unsigned short) parse_long(argv[4], 10)) == LONG_MAX) return 1; if ((final_y = (unsigned short) parse_long(argv[5], 10)) == LONG_MAX) return 1; if ((color = (unsigned long) parse_long(argv[6], 10)) == LONG_MAX) return 1; printf("test_linee(%d, %d, %d, %d, %d)\n", initial_x, initial_y, final_x, final_y, color); return test_line(initial_x, initial_y, final_x, final_y, color); } else if (strncmp(argv[1], "xpm", 3) == 0) { if (argc != 5) { printf("wrong no of arguments for test_xpm()\n"); return 1; } if ((initial_x = (unsigned short) parse_long(argv[2], 10)) == LONG_MAX) return 1; if ((initial_y = (unsigned short) parse_long(argv[3], 10)) == LONG_MAX) return 1; if (strncmp(argv[4], "pic1", 4) == 0) { printf("test_xpm(%d, %d, %s)\n", initial_x, initial_y, "pic1"); return test_xpm(initial_x, initial_y, pic1); } else if (strncmp(argv[4], "pic2", 4) == 0) { printf("test_xpm(%d, %d, %s)\n", initial_x, initial_y, "pic2"); return test_xpm(initial_x, initial_y, pic2); } else if (strncmp(argv[4], "cross", 5) == 0) { printf("test_xpm(%d, %d, %s)\n", initial_x, initial_y, "cross"); return test_xpm(initial_x, initial_y, cross); } else if (strncmp(argv[4], "pic3", 4) == 0) { printf("test_xpm(%d, %d, %s)\n", initial_x, initial_y, "pic3"); return test_xpm(initial_x, initial_y, pic3); } else if (strncmp(argv[4], "penguin", 7) == 0) { printf("test_xpm(%d, %d, %s)\n", initial_x, initial_y, "penguin"); return test_xpm(initial_x, initial_y, penguin); } } else if (strncmp(argv[1], "move", 4) == 0) { if (argc != 8) { printf("wrong no of arguments for test_move()\n"); return 1; } if ((initial_x = (unsigned short) parse_long(argv[2], 10)) == LONG_MAX) return 1; if ((initial_y = (unsigned short) parse_long(argv[3], 10)) == LONG_MAX) return 1; if ((horizontal = (unsigned short) parse_long(argv[5], 10)) == LONG_MAX) return 1; if ((distance = (short) parse_long(argv[6], 10)) == LONG_MAX) return 1; if ((time = (unsigned short) parse_long(argv[7], 10)) == LONG_MAX) return 1; if (strncmp(argv[4], "pic1", 4) == 0) { printf("test_move(%d, %d, %s, %d, %d, %d)\n", initial_x, initial_y, "pic1", horizontal, distance, time); return test_move(initial_x, initial_y, pic1, horizontal, distance, time); } else if (strncmp(argv[4], "pic2", 4) == 0) { printf("test_move(%d, %d, %s, %d, %d, %d)\n", initial_x, initial_y, "pic2", horizontal, distance, time); return test_move(initial_x, initial_y, pic2, horizontal, distance, time); } else if (strncmp(argv[4], "cross", 5) == 0) { printf("test_move(%d, %d, %s, %d, %d, %d)\n", initial_x, initial_y, "cross", horizontal, distance, time); return test_move(initial_x, initial_y, cross, horizontal, distance, time); } else if (strncmp(argv[4], "pic3", 4) == 0) { printf("test_move(%d, %d, %s, %d, %d, %d)\n", initial_x, initial_y, "pic3", horizontal, distance, time); return test_move(initial_x, initial_y, pic3, horizontal, distance, time); } else if (strncmp(argv[4], "penguin", 7) == 0) { printf("test_move(%d, %d, %s, %d, %d, %d)\n", initial_x, initial_y, "penguin", horizontal, distance, time); return test_move(initial_x, initial_y, penguin, horizontal, distance, time); } } else if(strncmp(argv[1], "controller", 10) == 0) { printf("test_controller()\n"); return test_controller(); } else { printf("non valid function \"%s\" to test\n", argv[1]); return 1; } }
int main(int argc, char *argv[]) { int test_step = atoi(argv[1]); printf("%d %d\n", test_step, test_line(test_step)); return 0; }
/* * If edit_widget is NULL then we are called from the mc menu, * otherwise we are called from the mcedit menu. */ void user_menu_cmd (struct WEdit *edit_widget) { char *p; char *data, **entries; int max_cols, menu_lines, menu_limit; int col, i, accept_entry = 1; int selected, old_patterns; Listbox *listbox; if (!vfs_current_is_local ()){ message (1, MSG_ERROR, _(" Cannot execute commands on non-local filesystems")); return; } menu = g_strdup (edit_widget ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)){ g_free (menu); menu = concat_dir_and_file \ (home_dir, edit_widget ? CEDIT_HOME_MENU : MC_HOME_MENU); if (!exist_file (menu)){ g_free (menu); menu = concat_dir_and_file \ (mc_home, edit_widget ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); } } if ((data = load_file (menu)) == NULL){ message (1, MSG_ERROR, _(" Cannot open file %s \n %s "), menu, unix_error_string (errno)); g_free (menu); menu = NULL; return; } max_cols = 0; selected = 0; menu_limit = 0; entries = 0; /* Parse the menu file */ old_patterns = easy_patterns; p = check_patterns (data); for (menu_lines = col = 0; *p; p++){ if (menu_lines >= menu_limit){ char ** new_entries; menu_limit += MAX_ENTRIES; new_entries = g_realloc (entries, sizeof (new_entries[0]) * menu_limit); if (new_entries == 0) break; entries = new_entries; new_entries += menu_limit; while (--new_entries >= &entries[menu_lines]) *new_entries = 0; } if (col == 0 && !entries [menu_lines]){ if (*p == '#'){ /* A commented menu entry */ accept_entry = 1; } else if (*p == '+'){ if (*(p+1) == '='){ /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ p = test_line (edit_widget, p, &accept_entry); } } else if (*p == '='){ if (*(p+1) == '+'){ /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; p = test_line (edit_widget, p, &i); if (selected == 0 && i) selected = menu_lines; } } else if (*p != ' ' && *p != '\t' && is_printable (*p)) { /* A menu entry title line */ if (accept_entry) entries [menu_lines] = p; else accept_entry = 1; } } if (*p == '\n'){ if (entries [menu_lines]){ menu_lines++; accept_entry = 1; } max_cols = max (max_cols, col); col = 0; } else { if (*p == '\t') *p = ' '; col++; } } if (menu_lines == 0) { message (1, MSG_ERROR, _(" No suitable entries found in %s "), menu); } else { max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) { p = entries [i]; LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0], extract_line (p, p + MAX_ENTRY_LEN), p ); } /* Select the default entry */ listbox_select_by_number (listbox->list, selected); selected = run_listbox (listbox); if (selected >= 0) execute_menu_command (edit_widget, entries [selected]); do_refresh (); } easy_patterns = old_patterns; g_free (menu); menu = NULL; g_free (entries); g_free (data); }
void gl_select_block(block_t *block) { if (block->len == 0) { return; } GLfloat zmax = 0.0f, zmin = 1.0f; #define test(func, ...) if (test_##func(__VA_ARGS__)) { select_match(block, zmin, zmax, i); return; } #define test_point(a) test(point, a) #define test_line(a, b) test(line, a, b) #define test_tri(a, b, c) test(tri, a, b, c) GLfloat data[3][3], first[3], *tmp; GLfloat *a = data[0], *b = data[1], *c = data[2]; gl_transform_vertex(first, _vert(block, 0)); for (int i = 0; i < block->len; i++) { tmp = c; c = b; b = a; a = tmp; gl_transform_vertex(a, _vert(block, i)); zmin = MIN(zmin, a[2]); zmax = MAX(zmax, a[2]); switch (block->mode) { case GL_LINES: if (i % 2 == 1) { test_point(a); test_point(b); test_line(a, b); } break; case GL_LINE_LOOP: // catch the loop segment if (i == block->len - 1) { test_line(a, first); } case GL_LINE_STRIP: if (i > 0) { if (i == 1) { test_point(b); } test_point(a); test_line(a, b); } break; case GL_TRIANGLES: if (i % 3 == 2) { test_point(a); test_point(b); test_point(c); test_line(a, b); test_line(b, c); test_line(c, a); test_tri(a, b, c); } case GL_TRIANGLE_FAN: // this isn't *quite* right // as the point won't be drawn if we run out of verts test_point(a); if (i > 1) { test_line(a, b); test_line(a, first); test_tri(first, a, b); } break; case GL_TRIANGLE_STRIP: test_point(a); if (i == 1) { test_line(a, b); } else if (i > 1) { test_line(a, b); test_tri(a, b, c); } break; case GL_POINTS: test_point(a); break; default: printf("warning: unsupported GL_SELECT mode: %s\n", gl_str(block->mode)); return; } } #undef test_point #undef test_line #undef test_tri }
gboolean user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_entry) { char *p; char *data, **entries; int max_cols, menu_lines, menu_limit; int col, i, accept_entry = 1; int selected, old_patterns; gboolean res = FALSE; gboolean interactive = TRUE; if (!vfs_current_is_local ()) { message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems")); return FALSE; } if (menu_file != NULL) menu = g_strdup (menu_file); else menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)) { if (menu_file != NULL) { message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"), menu, unix_error_string (errno)); MC_PTR_FREE (menu); return FALSE; } g_free (menu); if (edit_widget) menu = mc_config_get_full_path (EDIT_HOME_MENU); else menu = mc_config_get_full_path (MC_USERMENU_FILE); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_config_get_home_dir (), edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_global.sysconfig_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_global.share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); } } } } if (!g_file_get_contents (menu, &data, NULL, NULL)) { message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno)); MC_PTR_FREE (menu); return FALSE; } max_cols = 0; selected = 0; menu_limit = 0; entries = 0; /* Parse the menu file */ old_patterns = easy_patterns; p = check_patterns (data); for (menu_lines = col = 0; *p; str_next_char (&p)) { if (menu_lines >= menu_limit) { char **new_entries; menu_limit += MAX_ENTRIES; new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit); if (new_entries == NULL) break; entries = new_entries; new_entries += menu_limit; while (--new_entries >= &entries[menu_lines]) *new_entries = NULL; } if (col == 0 && !entries[menu_lines]) { if (*p == '#') { /* show prompt if first line of external script is #interactive */ if (selected_entry >= 0 && strncmp (p, "#silent", 7) == 0) interactive = FALSE; /* A commented menu entry */ accept_entry = 1; } else if (*p == '+') { if (*(p + 1) == '=') { /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ p = test_line (edit_widget, p, &accept_entry); } } else if (*p == '=') { if (*(p + 1) == '+') { /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; p = test_line (edit_widget, p, &i); if (selected == 0 && i) selected = menu_lines; } } else if (*p != ' ' && *p != '\t' && str_isprint (p)) { /* A menu entry title line */ if (accept_entry) entries[menu_lines] = p; else accept_entry = 1; } } if (*p == '\n') { if (entries[menu_lines]) { menu_lines++; accept_entry = 1; } max_cols = max (max_cols, col); col = 0; } else { if (*p == '\t') *p = ' '; col++; } } if (menu_lines == 0) { message (D_ERROR, MSG_ERROR, _("No suitable entries found in %s"), menu); res = FALSE; } else { if (selected_entry >= 0) selected = selected_entry; else { Listbox *listbox; max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ listbox = create_listbox_window (menu_lines, max_cols + 2, _("User menu"), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) { p = entries[i]; LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0], extract_line (p, p + MAX_ENTRY_LEN), p); } /* Select the default entry */ listbox_select_entry (listbox->list, selected); selected = run_listbox (listbox); } if (selected >= 0) { execute_menu_command (edit_widget, entries[selected], interactive); res = TRUE; } do_refresh (); } easy_patterns = old_patterns; MC_PTR_FREE (menu); g_free (entries); g_free (data); return res; }