void run() { test_empty(); test_space(); test_alpha(); test_alpha_bravo(); test_escape_quote(); test_escape_reverse_solidus(); test_escape_solidus(); test_escape_backspace(); test_escape_formfeed(); test_escape_newline(); test_escape_carriage_return(); test_escape_tab(); test_escape_unicode_one(); test_escape_unicode_a(); test_escape_unicode_0123(); test_escape_unicode_4567(); test_escape_unicode_89AB(); test_escape_unicode_CDEF(); fail_escape_unicode_missing_one(); fail_escape_unicode_missing_two(); fail_escape_unicode_missing_three(); fail_escape_unicode_missing_four(); fail_escape_unicode_eof(); fail_escape_unicode_eof_one(); fail_escape_unicode_eof_two(); fail_escape_unicode_eof_three(); fail_escape_unicode_eof_four(); fail_escape(); fail_begin(); fail_as_int(); fail_as_float(); }
int get_map(t_glob *g) { t_temp_list *node; node = g->data; while (node->next != NULL) { ft_putstr(node->str); ft_putchar('\n'); test_alpha(node->str); ((g->lines == 0) && (test_digit(node->str) == 0)) ? g->ant_flag = 1 : 0; ((ft_strcmp("##start", node->str)) == 0) ? g->start_flag = 1 : 0; ((ft_strcmp("##end", node->str)) == 0) ? g->end_flag = 1 : 0; if ((ft_strncmp("#", node->str, 1)) == 0) { node = node->next; continue; } if (node->str == NULL) error(); check_data(g, node->str); node = node->next; } if (validate(g)) return (1); free(node); return (0); }
int sh_setenv(t_info *info, char **env, char **args) { char name[1024]; if (!args[0]) sh_printenv(info, env, args); else if (args[1] && args[2]) ft_putendl_fd("sh_setenv: Too many arguments.", 2); else if (test_alpha(args[0])) ft_putendl_fd("sh_setenv: Variable name must contain" " alphanumeric characters.", 2); else { ft_bzero(name, 1024); ft_strcpy(name, args[0]); ft_strcat(name, "="); if (args[1]) ft_strcat(name, args[1]); if (ft_replaceenv(name, info->env)) ft_addenv(name, &info->env); } return (EXIT_SUCCESS); }
static void show_canvas(FtkDisplay* display, FtkCanvas* canvas) { FtkBitmap* bitmap = NULL; FtkRect rect = {.x = 0, .y=0, .width=0, .height=0}; rect.width = ftk_display_width(display); rect.height = ftk_display_height(display); ftk_canvas_lock_buffer(canvas, &bitmap); ftk_display_update(display, bitmap, &rect, 0, 0); ftk_canvas_unlock_buffer(canvas); return; } #if 1 void test_misc(FtkDisplay* display, FtkFont* font) { if(display != NULL) { int i = 0; FtkGc gc = {0}; int extent = 0; FtkColor color = {0x0, 0, 0, 0x0}; FtkRect rect = {.x = 0, .y=0, .width=0, .height=0}; rect.width = ftk_display_width(display); rect.height = ftk_display_height(display); gc.mask = FTK_GC_FG | FTK_GC_FONT; gc.fg.a = 0xff; gc.fg.r = 0x00; gc.fg.g = 0x00; gc.fg.b = 0xff; gc.font = font; FtkCanvas* thiz = ftk_canvas_create(rect.width, rect.height, &color); show_canvas(display, thiz); for(i = 0; i < ftk_display_height(display); i++) { if(gc.fg.r < 0xff) { gc.fg.r++; } else { gc.fg.g++; } ftk_canvas_set_gc(thiz, &gc); ftk_canvas_draw_hline(thiz, 0, i, 320); } FtkBitmap* bitmap = ftk_bitmap_create(100, 100, color); ftk_canvas_draw_bitmap_simple(thiz, bitmap, 0, 0, 100, 100, 100, 100); ftk_canvas_draw_string(thiz, 0, 240, " Jim is a Programmer.", -1, 0); gc.fg.b = 0xff; ftk_canvas_set_gc(thiz, &gc); ftk_canvas_draw_string(thiz, 0, 220, "李先静是一个程序员", -1, 0); unsigned int line_mask = 0xaaaaaaaa; gc.line_mask = line_mask; gc.mask = FTK_GC_LINE_MASK; ftk_canvas_set_gc(thiz, &gc); show_canvas(display, thiz); assert(ftk_canvas_font_height(thiz) == 16); extent = ftk_canvas_get_extent(thiz, "李先静", -1); printf("extent=%d\n", ftk_canvas_get_extent(thiz, "李先静", -1)); ftk_bitmap_unref(bitmap); ftk_canvas_destroy(thiz); } sleep(3); return; } #if 0 void test_draw_point(FtkDisplay* display) { int i = 0; FtkGc gc = {.mask = FTK_GC_FG}; FtkRect rect = {0}; FtkColor color = {.a = 0xff}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, color); rect.width = width; rect.height = height; color.r = 0xff; color.a = 0xff; gc.fg = color; for(i = 0; i < width; i++) { ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_point(thiz, i, 10); } color.g = 0xff; color.r = 0; for(i = 0; i < width; i++) { color.a = 0xff - (0xff & i); gc.fg = color; ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_point(thiz, i, 20); } color.r = 0; color.g = 0; color.b = 0xff; color.a = 0xff; gc.fg = color; gc.mask |= FTK_GC_ALPHA; for(i = 0; i < width; i++) { gc.alpha = 0xff - (0xff & i); ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_point(thiz, i, 30); } show_canvas(display, thiz); ftk_canvas_destroy(thiz); sleep(3); return; } #endif void test_draw_vline(FtkDisplay* display) { int i = 0; FtkGc gc = {.mask = FTK_GC_FG}; FtkRect rect = {0}; FtkColor color = {.a = 0xff}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, &color); rect.width = width; rect.height = height; color.r = 0xff; color.a = 0xff; gc.fg = color; for(i = 0; i < width; i++) { ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_vline(thiz, i, 0, 20); } color.g = 0xff; color.r = 0; for(i = 0; i < width; i++) { color.a = 0xff - (0xff & i); gc.fg = color; ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_vline(thiz, i, 30, 20); } color.r = 0; color.g = 0; color.b = 0xff; color.a = 0xff; gc.fg = color; gc.mask |= FTK_GC_ALPHA; for(i = 0; i < width; i++) { gc.alpha = 0xff - (0xff & i); ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_vline(thiz, i, 60, 20); } show_canvas(display, thiz); ftk_canvas_destroy(thiz); sleep(3); return; } void test_draw_hline(FtkDisplay* display) { int i = 0; FtkGc gc = {.mask = FTK_GC_FG}; FtkRect rect = {0}; FtkColor color = {.a = 0xff}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, &color); rect.width = width; rect.height = height; color.r = 0xff; color.a = 0xff; gc.fg = color; for(i = 0; i < height; i++) { ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_hline(thiz, 0, i, 20); } color.g = 0xff; color.r = 0; for(i = 0; i < height; i++) { color.a = 0xff - (0xff & i); gc.fg = color; ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_hline(thiz, 30, i, 20); } color.r = 0; color.g = 0; color.b = 0xff; color.a = 0xff; gc.fg = color; gc.mask |= FTK_GC_ALPHA; for(i = 0; i < height; i++) { gc.alpha = 0xff - (0xff & i); ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_hline(thiz, 60, i, 20); } show_canvas(display, thiz); ftk_canvas_destroy(thiz); sleep(3); return; } #if 0 void test_draw_line(FtkDisplay* display) { int i = 0; FtkGc gc = {.mask = FTK_GC_FG}; FtkRect rect = {0}; FtkColor color = {.a = 0xff}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, color); rect.width = width; rect.height = height; color.r = 0xff; color.a = 0xff; gc.fg = color; for(i = 0; i < height/2; i++) { ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_line(thiz, 0, i, 20, i+10); } color.g = 0xff; color.r = 0; for(i = 0; i < height/2; i++) { color.a = 0xff - (0xff & i); gc.fg = color; ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_line(thiz, 30, i, 50, i+10); } color.r = 0; color.g = 0; color.b = 0xff; color.a = 0xff; gc.fg = color; gc.mask |= FTK_GC_ALPHA; for(i = 0; i < height/2; i++) { gc.alpha = 0xff - (0xff & i); ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_line(thiz, 60, i, 80, i+10); } ftk_display_update(display, ftk_canvas_bitmap(thiz), &rect, 0, 0); ftk_canvas_destroy(thiz); sleep(3); return; } #endif void test_alpha(FtkDisplay* display) { int i = 0; FtkGc gc = {.mask = FTK_GC_FG}; FtkRect rect = {0}; FtkColor color = {.a = 0xff}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, &color); rect.width = width; rect.height = height; color.g = 0xff; color.r = 0; for(i = 0; i < 0xff; i += 4) { color.a = 0xff; color.g = 0; gc.fg = color; ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_rect(thiz, 0, 0, width, height, 0, 1); color.a = 0xff - i; color.g = 0xff; gc.fg = color; ftk_canvas_reset_gc(thiz, &gc); ftk_canvas_draw_rect(thiz, 0, 0, width, height, 0, 1); show_canvas(display, thiz); usleep(200000); } ftk_canvas_destroy(thiz); sleep(3); return; } void test_put_get_pixel(FtkDisplay* display) { int i = 0; int j = 0; FtkColor color = {.a=0xff, .r=0xef, .g=0xdf, .b=0xcf}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, &color); for(i = 0; i < height; i++) { for(j = 0; j < width; j++) { FtkColor c = {0}; FtkColor* colorp = NULL; colorp = &c; assert(colorp->r == color.r); assert(colorp->g == color.g); assert(colorp->b == color.b); assert(colorp->a == color.a); } } ftk_canvas_destroy(thiz); return; } void test_font(FtkDisplay* display, FtkFont* font) { int extent2 = 0; FtkGc gc = {.mask = FTK_GC_FONT}; FtkColor color = {.a=0xff, .r=0xef, .g=0xdf, .b=0xcf}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, &color); const char* str = "隐式声明与内建函数"; const char* other_side = NULL; gc.font = font; ftk_canvas_set_gc(thiz, &gc); other_side = ftk_canvas_calc_str_visible_range(thiz, str, 0, -1, 60); assert(strcmp(other_side, "明与内建函数") == 0); other_side = ftk_canvas_calc_str_visible_range(thiz, str, other_side-str, -1, 60); assert(strcmp(other_side, "建函数") == 0); other_side = ftk_canvas_calc_str_visible_range(thiz, str, other_side-str, -1, 60); assert(strcmp(other_side, "") == 0); other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60); assert(strcmp(other_side, "建函数") == 0); other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60); assert(strcmp(other_side, "明与内建函数") == 0); other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60); assert(strcmp(other_side, str) == 0); other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60); assert(strcmp(other_side, str) == 0); printf("other_side = %s\n", other_side); str = "Single line editor, that means you can input a one line only."; extent2 = ftk_canvas_get_extent(thiz, str, -1); ftk_canvas_destroy(thiz); sleep(3); return; } static void test_fill_bg(FtkDisplay* display) { FtkRect rect = {0}; FtkColor color = {.a=0xff, .r=0xef, .g=0xdf, .b=0xcf}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkCanvas* thiz = ftk_canvas_create(width, height, &color); FtkBitmap* bitmap = ftk_theme_load_image(ftk_default_theme(), "btn_default_pressed.9.png"); ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 10, 10, 100, 60); ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 120, 10, 40, 60); ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 10, 80, 20, 20); ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 30, 80, 40, 20); ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 80, 80, 60, 20); rect.width = width; rect.height = height; show_canvas(display, thiz); ftk_canvas_destroy(thiz); sleep(3); return; } static void test_draw_rect(FtkDisplay* display) { int i = 0; FtkColor color = {.a = 0xff}; FtkRect rect = {0}; int width = ftk_display_width(display); int height = ftk_display_height(display); FtkGc gc = {.mask = FTK_GC_FG}; FtkCanvas* thiz = ftk_canvas_create(width, height, &color); gc.fg.a = 0xff; gc.fg.r = 0xff; for(i = 0; i < width/8; i++) { gc.fg.r -= 0x10; ftk_canvas_set_gc(thiz, &gc); ftk_canvas_draw_rect(thiz, width * i/8, 0, width/8 - 1, height/8 - 1, 0, 1); } gc.fg.r = 0xff; for(i = 0; i < width/8; i++) { gc.fg.r -= 0x10; gc.fg.b += 0x10; ftk_canvas_set_gc(thiz, &gc); ftk_canvas_draw_rect(thiz, width * i/8, height/8, width/8 - 1, height/8 - 1, 0, 0); } gc.fg.r = 0xff; for(i = 0; i < width/8; i++) { gc.fg.r -= 0x10; ftk_canvas_set_gc(thiz, &gc); ftk_canvas_draw_rect(thiz, width * i/8, height/4, width/8 - 1, height/8 - 1, 1, 1); } gc.fg.r = 0xff; for(i = 0; i < width/8; i++) { gc.fg.r -= 0x10; gc.fg.b += 0x10; ftk_canvas_set_gc(thiz, &gc); ftk_canvas_draw_rect(thiz, width * i/8, 3*height/8, width/8 - 1, height/8 - 1, 1, 0); } rect.width = width; rect.height = height; show_canvas(display, thiz); ftk_canvas_destroy(thiz); sleep(3); return; } int main(int argc, char* argv[]) { ftk_init(argc, argv); FtkRect rect = {0}; FtkColor bg = {.a = 0xff}; FtkBitmap* bitmap = NULL; FtkFont* font = ftk_default_font(); FtkDisplay* display = ftk_default_display(); rect.width = ftk_display_width(display); rect.height = ftk_display_height(display); #if 0 #else test_draw_rect(display); test_alpha(display); test_draw_vline(display); bitmap = ftk_bitmap_create(ftk_display_width(display), ftk_display_height(display), bg); ftk_display_snap(display, &rect, bitmap); test_draw_hline(display); ftk_display_update(display, bitmap, &rect, 0, 0); test_fill_bg(display); test_font(display, font); test_put_get_pixel(display); test_draw_hline(display); test_draw_vline(display); ftk_bitmap_unref(bitmap); #endif ftk_run(); return 0; } #else int main(int argc, char* argv[]) { return 0; }
int main(int argc, char *argv[]) { gen_workspace *gen_workspace_p; lapack_workspace *lapack_workspace_p; size_t N; int c; int lower; int upper; int incremental; size_t nmat; gsl_matrix *A, *B; gsl_rng *r; int s; int compute_schur; size_t i; gsl_ieee_env_setup(); gsl_rng_env_setup(); N = 30; lower = -10; upper = 10; incremental = 0; nmat = 0; compute_schur = 0; while ((c = getopt(argc, argv, "ic:n:l:u:z")) != (-1)) { switch (c) { case 'i': incremental = 1; break; case 'n': N = strtol(optarg, NULL, 0); break; case 'l': lower = strtol(optarg, NULL, 0); break; case 'u': upper = strtol(optarg, NULL, 0); break; case 'c': nmat = strtoul(optarg, NULL, 0); break; case 'z': compute_schur = 1; break; case '?': default: printf("usage: %s [-i] [-z] [-n size] [-l lower-bound] [-u upper-bound] [-c num]\n", argv[0]); exit(1); break; } /* switch (c) */ } A = gsl_matrix_alloc(N, N); B = gsl_matrix_alloc(N, N); gen_workspace_p = gen_alloc(N, compute_schur); lapack_workspace_p = lapack_alloc(N); r = gsl_rng_alloc(gsl_rng_default); if (incremental) { make_start_matrix(A, lower); /* we need B to be non-singular */ make_random_integer_matrix(B, r, lower, upper); } fprintf(stderr, "testing N = %d", N); if (incremental) fprintf(stderr, " incrementally"); else fprintf(stderr, " randomly"); fprintf(stderr, " on element range [%d, %d]", lower, upper); if (compute_schur) fprintf(stderr, ", with Schur vectors"); fprintf(stderr, "\n"); while (1) { if (nmat && (count >= nmat)) break; ++count; if (!incremental) { make_random_matrix(A, r, lower, upper); make_random_matrix(B, r, lower, upper); } else { s = inc_matrix(A, lower, upper); if (s) break; /* all done */ make_random_integer_matrix(B, r, lower, upper); } /*if (count != 89120) continue;*/ /* make copies of matrices */ gsl_matrix_memcpy(gen_workspace_p->A, A); gsl_matrix_memcpy(gen_workspace_p->B, B); gsl_matrix_transpose_memcpy(lapack_workspace_p->A, A); gsl_matrix_transpose_memcpy(lapack_workspace_p->B, B); /* compute eigenvalues with LAPACK */ s = lapack_proc(lapack_workspace_p); if (s != GSL_SUCCESS) { printf("LAPACK failed, case %lu\n", count); exit(1); } #if 0 print_matrix(A, "A"); print_matrix(B, "B"); gsl_matrix_transpose(lapack_workspace_p->A); gsl_matrix_transpose(lapack_workspace_p->B); print_matrix(lapack_workspace_p->A, "S_lapack"); print_matrix(lapack_workspace_p->B, "T_lapack"); #endif /* compute eigenvalues with GSL */ s = gen_proc(gen_workspace_p); if (s != GSL_SUCCESS) { printf("=========== CASE %lu ============\n", count); printf("Failed to converge: found %u eigenvalues\n", gen_workspace_p->n_evals); print_matrix(A, "A"); print_matrix(B, "B"); print_matrix(gen_workspace_p->A, "Af"); print_matrix(gen_workspace_p->B, "Bf"); print_matrix(lapack_workspace_p->A, "Ae"); print_matrix(lapack_workspace_p->B, "Be"); exit(1); } #if 0 print_matrix(gen_workspace_p->A, "S_gsl"); print_matrix(gen_workspace_p->B, "T_gsl"); #endif /* compute alpha / beta vectors */ for (i = 0; i < N; ++i) { double beta; gsl_complex alpha, z; beta = gsl_vector_get(gen_workspace_p->beta, i); if (beta == 0.0) GSL_SET_COMPLEX(&z, GSL_POSINF, GSL_POSINF); else { alpha = gsl_vector_complex_get(gen_workspace_p->alpha, i); z = gsl_complex_div_real(alpha, beta); } gsl_vector_complex_set(gen_workspace_p->evals, i, z); beta = gsl_vector_get(lapack_workspace_p->beta, i); GSL_SET_COMPLEX(&alpha, lapack_workspace_p->alphar[i], lapack_workspace_p->alphai[i]); if (beta == 0.0) GSL_SET_COMPLEX(&z, GSL_POSINF, GSL_POSINF); else z = gsl_complex_div_real(alpha, beta); gsl_vector_complex_set(lapack_workspace_p->evals, i, z); gsl_vector_complex_set(lapack_workspace_p->alpha, i, alpha); } #if 0 gsl_sort_vector(gen_workspace_p->beta); gsl_sort_vector(lapack_workspace_p->beta); sort_complex_vector(gen_workspace_p->alpha); sort_complex_vector(lapack_workspace_p->alpha); s = test_alpha(gen_workspace_p->alpha, lapack_workspace_p->alpha, A, B, "gen", "lapack"); s = test_beta(gen_workspace_p->beta, lapack_workspace_p->beta, A, B, "gen", "lapack"); #endif #if 1 sort_complex_vector(gen_workspace_p->evals); sort_complex_vector(lapack_workspace_p->evals); s = test_evals(gen_workspace_p->evals, lapack_workspace_p->evals, A, B, "gen", "lapack"); #endif if (compute_schur) { test_schur(A, gen_workspace_p->A, gen_workspace_p->Q, gen_workspace_p->Z); test_schur(B, gen_workspace_p->B, gen_workspace_p->Q, gen_workspace_p->Z); } } gsl_matrix_free(A); gsl_matrix_free(B); gen_free(gen_workspace_p); lapack_free(lapack_workspace_p); if (r) gsl_rng_free(r); return 0; } /* main() */