int main(int argc, char **argv) #endif { int i; #ifdef LINUXVGA LINUX_setup(); /* setup VGA before dropping privilege DBT 4/5/99 */ drop_privilege(); #endif /* make sure that we really have revoked root access, this might happen if gnuplot is compiled without vga support but is installed suid by mistake */ #ifdef __linux__ setuid(getuid()); #endif #if defined(MSDOS) && !defined(_Windows) && !defined(__GNUC__) PC_setup(); #endif /* MSDOS !Windows */ /* HBB: Seems this isn't needed any more for DJGPP V2? */ /* HBB: disable all floating point exceptions, just keep running... */ #if defined(DJGPP) && (DJGPP!=2) _control87(MCW_EM, MCW_EM); #endif #if defined(OS2) int rc; #ifdef OS2_IPC char semInputReadyName[40]; sprintf( semInputReadyName, "\\SEM32\\GP%i_Input_Ready", getpid() ); rc = DosCreateEventSem(semInputReadyName,&semInputReady,0,0); if (rc != 0) fputs("DosCreateEventSem error\n",stderr); #endif rc = RexxRegisterSubcomExe("GNUPLOT", (PFN) RexxInterface, NULL); #endif /* malloc large blocks, otherwise problems with fragmented mem */ #ifdef MALLOCDEBUG malloc_debug(7); #endif /* get helpfile from home directory */ #ifdef __DJGPP__ { char *s; strcpy(HelpFile, argv[0]); for (s = HelpFile; *s; s++) if (*s == DIRSEP1) *s = DIRSEP2; /* '\\' to '/' */ strcpy(strrchr(HelpFile, DIRSEP2), "/gnuplot.gih"); } /* Add also some "paranoid" tests for '\\': AP */ #endif /* DJGPP */ #ifdef VMS unsigned int status[2] = { 1, 0 }; #endif #if defined(HAVE_LIBEDITLINE) rl_getc_function = getc_wrapper; #endif #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) /* T.Walter 1999-06-24: 'rl_readline_name' must be this fix name. * It is used to parse a 'gnuplot' specific section in '~/.inputrc' * or gnuplot specific commands in '.editrc' (when using editline * instead of readline) */ rl_readline_name = "Gnuplot"; rl_terminal_name = getenv("TERM"); #if defined(HAVE_LIBREADLINE) using_history(); #else history_init(); #endif #endif #if defined(HAVE_LIBREADLINE) && !defined(MISSING_RL_TILDE_EXPANSION) rl_complete_with_tilde_expansion = 1; #endif for (i = 1; i < argc; i++) { if (!argv[i]) continue; if (!strcmp(argv[i], "-V") || !strcmp(argv[i], "--version")) { printf("gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); return 0; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { printf( "Usage: gnuplot [OPTION] ... [FILE]\n" #ifdef X11 "for X11 options see 'help X11->command-line-options'\n" #endif " -V, --version\n" " -h, --help\n" " -p --persist\n" " -d --default-settings\n" " -c scriptfile ARG1 ARG2 ... \n" " -e \"command1; command2; ...\"\n" "gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); #ifdef DEVELOPMENT_VERSION printf( #ifdef DIST_CONTACT "Report bugs to "DIST_CONTACT"\n" " or %s\n", #else "Report bugs to %s\n", #endif bug_email); #endif return 0; } else if (!strncmp(argv[i], "-persist", 2) || !strcmp(argv[i], "--persist") #ifdef _Windows || !stricmp(argv[i], "-noend") || !stricmp(argv[i], "/noend") #endif ) { persist_cl = TRUE; } else if (!strncmp(argv[i], "-d", 2) || !strcmp(argv[i], "--default-settings")) { /* Skip local customization read from ~/.gnuplot */ skip_gnuplotrc = TRUE; } } #ifdef X11 /* the X11 terminal removes tokens that it recognizes from argv. */ { int n = X11_args(argc, argv); argv += n; argc -= n; } #endif setbuf(stderr, (char *) NULL); #ifdef HAVE_SETVBUF /* This was once setlinebuf(). Docs say this is * identical to setvbuf(,NULL,_IOLBF,0), but MS C * faults this (size out of range), so we try with * size of 1024 instead. [SAS/C does that, too. -lh] */ if (setvbuf(stdout, (char *) NULL, _IOLBF, (size_t) 1024) != 0) (void) fputs("Could not linebuffer stdout\n", stderr); /* Switching to unbuffered mode causes all characters in the input * buffer to be lost. So the only safe time to do it is on program entry. * Do any non-X platforms suffer from this problem? * EAM - Jan 2013 YES. */ setvbuf(stdin, (char *) NULL, _IONBF, 0); #endif gpoutfile = stdout; /* Initialize pre-loaded user variables */ /* "pi" is hard-wired as the first variable */ (void) add_udv_by_name("GNUTERM"); (void) add_udv_by_name("NaN"); init_constants(); udv_user_head = &(udv_NaN->next_udv); init_memory(); interactive = FALSE; init_terminal(); /* can set term type if it likes */ push_terminal(0); /* remember the default terminal */ /* reset the terminal when exiting */ /* this is done through gp_atexit so that other terminal functions * can be registered to be executed before the terminal is reset. */ gp_atexit(term_reset); # if defined(WIN32) && !defined(WGP_CONSOLE) interactive = TRUE; # else interactive = isatty(fileno(stdin)); # endif /* Note: we want to know whether this is an interactive session so that we can * decide whether or not to write status information to stderr. The old test * for this was to see if (argc > 1) but the addition of optional command line * switches broke this. What we really wanted to know was whether any of the * command line arguments are file names or an explicit in-line "-e command". */ for (i = 1; i < argc; i++) { # ifdef _Windows if (!stricmp(argv[i], "/noend")) continue; # endif if ((argv[i][0] != '-') || (argv[i][1] == 'e') || (argv[i][1] == 'c') ) { interactive = FALSE; break; } } /* Need this before show_version is called for the first time */ if (interactive) show_version(stderr); else show_version(NULL); /* Only load GPVAL_COMPILE_OPTIONS */ #ifdef WGP_CONSOLE #ifdef CONSOLE_SWITCH_CP if (cp_changed && interactive) { fprintf(stderr, "\ngnuplot changed the codepage of this console from %i to %i to\n" \ "match the graph window. Some characters might only display correctly\n" \ "if you change the font to a non-raster type.\n", cp_input, GetConsoleCP()); } #else if ((GetConsoleCP() != GetACP()) && interactive) { fprintf(stderr, "\nWarning: The codepage of the graph window (%i) and that of the\n" \ "console (%i) differ. Use `set encoding` or `!chcp` if extended\n" \ "characters don't display correctly.\n", GetACP(), GetConsoleCP()); } #endif #endif update_gpval_variables(3); /* update GPVAL_ variables available to user */ #ifdef VMS /* initialise screen management routines for command recall */ if (status[1] = smg$create_virtual_keyboard(&vms_vkid) != SS$_NORMAL) done(status[1]); if (status[1] = smg$create_key_table(&vms_ktid) != SS$_NORMAL) done(status[1]); #endif /* VMS */ if (!SETJMP(command_line_env, 1)) { /* first time */ interrupt_setup(); /* should move this stuff to another initialisation routine, * something like init_set() maybe */ get_user_env(); init_loadpath(); init_locale(); memset(&sm_palette, 0, sizeof(sm_palette)); init_fit(); /* Initialization of fitting module */ init_session(); if (interactive && term != 0) { /* not unknown */ #ifdef GNUPLOT_HISTORY #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) expanded_history_filename = tilde_expand(GNUPLOT_HISTORY_FILE); #else expanded_history_filename = gp_strdup(GNUPLOT_HISTORY_FILE); gp_expand_tilde(&expanded_history_filename); #endif read_history(expanded_history_filename); /* * It is safe to ignore the return values of 'atexit()' and * 'on_exit()'. In the worst case, there is no history of your * currrent session and you have to type all again in your next * session. */ gp_atexit(wrapper_for_write_history); #endif /* GNUPLOT_HISTORY */ fprintf(stderr, "\nTerminal type set to '%s'\n", term->name); } /* if (interactive && term != 0) */ } else { /* come back here from int_error() */ if (!successful_initialization) { /* Only print the warning once */ successful_initialization = TRUE; fprintf(stderr,"WARNING: Error during initialization\n\n"); } if (interactive == FALSE) exit_status = EXIT_FAILURE; #ifdef HAVE_READLINE_RESET else { /* reset properly readline after a SIGINT+longjmp */ rl_reset_after_signal (); } #endif load_file_error(); /* if we were in load_file(), cleanup */ SET_CURSOR_ARROW; #ifdef VMS /* after catching interrupt */ /* VAX stuffs up stdout on SIGINT while writing to stdout, so reopen stdout. */ if (gpoutfile == stdout) { if ((stdout = freopen("SYS$OUTPUT", "w", stdout)) == NULL) { /* couldn't reopen it so try opening it instead */ if ((stdout = fopen("SYS$OUTPUT", "w")) == NULL) { /* don't use int_error here - causes infinite loop! */ fputs("Error opening SYS$OUTPUT as stdout\n", stderr); } } gpoutfile = stdout; } #endif /* VMS */ /* Why a goto? Because we exited the loop below via int_error */ /* using LONGJMP. The compiler was not expecting this, and */ /* "optimized" the handling of argc and argv such that simply */ /* entering the loop again from the top finds them messed up. */ /* If we reenter the loop via a goto then there is some hope */ /* that code reordering does not hurt us. */ /* NB: the test for interactive means that execution from a */ /* pipe will not continue after an error. Do we want this? */ if (reading_from_dash && interactive) goto RECOVER_FROM_ERROR_IN_DASH; reading_from_dash = FALSE; if (!interactive && !noinputfiles) { term_reset(); gp_exit(EXIT_FAILURE); /* exit on non-interactive error */ } } /* load filenames given as arguments */ while (--argc > 0) { ++argv; c_token = 0; if (!strncmp(*argv, "-persist", 2) || !strcmp(*argv, "--persist") #ifdef _Windows || !stricmp(*argv, "-noend") || !stricmp(*argv, "/noend") #endif ) { FPRINTF((stderr,"'persist' command line option recognized\n")); } else if (strcmp(*argv, "-") == 0) { #if defined(_Windows) && !defined(WGP_CONSOLE) TextShow(&textwin); interactive = TRUE; #else interactive = isatty(fileno(stdin)); #endif RECOVER_FROM_ERROR_IN_DASH: reading_from_dash = TRUE; while (!com_line()); reading_from_dash = FALSE; interactive = FALSE; } else if (strcmp(*argv, "-e") == 0) { --argc; ++argv; if (argc <= 0) { fprintf(stderr, "syntax: gnuplot -e \"commands\"\n"); return 0; } interactive = FALSE; noinputfiles = FALSE; do_string(*argv); } else if (!strncmp(*argv, "-d", 2) || !strcmp(*argv, "--default-settings")) { /* Ignore this; it already had its effect */ FPRINTF((stderr, "ignoring -d\n")); } else if (strcmp(*argv, "-c") == 0) { /* Pass command line arguments to the gnuplot script in the next * argument. This consumes the remainder of the command line */ interactive = FALSE; noinputfiles = FALSE; --argc; ++argv; if (argc <= 0) { fprintf(stderr, "syntax: gnuplot -c scriptname args\n"); gp_exit(EXIT_FAILURE); } for (i=0; i<argc; i++) /* Need to stash argv[i] somewhere visible to load_file() */ call_args[i] = gp_strdup(argv[i+1]); call_argc = argc - 1; load_file(loadpath_fopen(*argv, "r"), gp_strdup(*argv), 5); gp_exit(EXIT_SUCCESS); } else if (*argv[0] == '-') { fprintf(stderr, "unrecognized option %s\n", *argv); } else { interactive = FALSE; noinputfiles = FALSE; load_file(loadpath_fopen(*argv, "r"), gp_strdup(*argv), 4); } } /* take commands from stdin */ if (noinputfiles) while (!com_line()) ctrlc_flag = FALSE; /* reset asynchronous Ctrl-C flag */ #ifdef _Windows /* On Windows, handle 'persist' by keeping the main input loop running (windows/wxt), */ /* but only if there are any windows open. Note that qt handles this properly. */ if (persist_cl) { if (WinAnyWindowOpen()) { #ifdef WGP_CONSOLE if (!interactive) { /* no further input from pipe */ while (WinAnyWindowOpen()) win_sleep(100); } else #endif { interactive = TRUE; while (!com_line()) ctrlc_flag = FALSE; /* reset asynchronous Ctrl-C flag */ interactive = FALSE; } } } #endif #if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE)) && defined(GNUPLOT_HISTORY) #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT) /* You should be here if you neither have 'atexit()' nor 'on_exit()' */ wrapper_for_write_history(); #endif /* !HAVE_ATEXIT && !HAVE_ON_EXIT */ #endif /* (HAVE_LIBREADLINE || HAVE_LIBEDITLINE) && GNUPLOT_HISTORY */ #ifdef OS2 RexxDeregisterSubcom("GNUPLOT", NULL); #endif /* HBB 20040223: Not all compilers like exit() to end main() */ /* exit(exit_status); */ #if ! defined(_Windows) /* Windows does the cleanup later */ gp_exit_cleanup(); #endif return exit_status; }
int dotest(struct starpu_disk_ops *ops, char *base) { int *A, *C; /* Initialize StarPU with default configuration */ int ret = starpu_init(NULL); if (ret == -ENODEV) goto enodev; /* Initialize path and name */ const char *name_file_start = "STARPU_DISK_COMPUTE_DATA_"; const char *name_file_end = "STARPU_DISK_COMPUTE_DATA_RESULT_"; char * path_file_start = malloc(strlen(base) + 1 + strlen(name_file_start) + 1); strcpy(path_file_start, base); strcat(path_file_start, "/"); strcat(path_file_start, name_file_start); char * path_file_end = malloc(strlen(base) + 1 + strlen(name_file_end) + 1); strcpy(path_file_end, base); strcat(path_file_end, "/"); strcat(path_file_end, name_file_end); /* register a disk */ int new_dd = starpu_disk_register(ops, (void *) base, 1024*1024*1); /* can't write on /tmp/ */ if (new_dd == -ENOENT) goto enoent; unsigned dd = (unsigned) new_dd; /* allocate two memory spaces */ starpu_malloc_flags((void **)&A, NX*sizeof(int), STARPU_MALLOC_COUNT); starpu_malloc_flags((void **)&C, NX*sizeof(int), STARPU_MALLOC_COUNT); FPRINTF(stderr, "TEST DISK MEMORY \n"); unsigned int j; /* you register them in a vector */ for(j = 0; j < NX; ++j) { A[j] = j; C[j] = 0; } /* you create a file to store the vector ON the disk */ FILE * f = fopen(path_file_start, "wb+"); if (f == NULL) goto enoent2; /* store it in the file */ fwrite(A, sizeof(int), NX, f); /* close the file */ fclose(f); int descriptor = open(path_file_start, O_RDWR); #ifdef STARPU_HAVE_WINDOWS _commit(descriptor); #else fsync(descriptor); #endif close(descriptor); /* create a file to store result */ f = fopen(path_file_end, "wb+"); if (f == NULL) goto enoent2; /* replace all datas by 0 */ fwrite(C, sizeof(int), NX, f); /* close the file */ fclose(f); descriptor = open(path_file_end, O_RDWR); #ifdef STARPU_HAVE_WINDOWS _commit(descriptor); #else fsync(descriptor); #endif close(descriptor); /* And now, you want to use your datas in StarPU */ /* Open the file ON the disk */ void * data = starpu_disk_open(dd, (void *) name_file_start, NX*sizeof(int)); void * data_result = starpu_disk_open(dd, (void *) name_file_end, NX*sizeof(int)); starpu_data_handle_t vector_handleA, vector_handleC; /* register vector in starpu */ starpu_vector_data_register(&vector_handleA, dd, (uintptr_t) data, NX, sizeof(int)); /* and do what you want with it, here we copy it into an other vector */ starpu_vector_data_register(&vector_handleC, dd, (uintptr_t) data_result, NX, sizeof(int)); starpu_data_cpy(vector_handleC, vector_handleA, 0, NULL, NULL); /* free them */ starpu_data_unregister(vector_handleA); starpu_data_unregister(vector_handleC); /* close them in StarPU */ starpu_disk_close(dd, data, NX*sizeof(int)); starpu_disk_close(dd, data_result, NX*sizeof(int)); /* check results */ f = fopen(path_file_end, "rb+"); if (f == NULL) goto enoent2; /* take datas */ fread(C, sizeof(int), NX, f); /* close the file */ fclose(f); int try = 1; for (j = 0; j < NX; ++j) if (A[j] != C[j]) { FPRINTF(stderr, "Fail A %d != C %d \n", A[j], C[j]); try = 0; }
int main(int argc, char **argv) { int overall_errors = 0; char buf[BIG_ENOUGH]; /* * todo: add more cases for * (un)successfull writes to not empty channel * (un)successfull reads from not empty channel */ /* test (in)valid write cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR WRITE CASES\n"); ZTEST(PWRITE(STDRW_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PWRITE(STDRW_GOAT, buf, -1, -1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDRW_GOAT, buf, -1, 0) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDRW_GOAT, buf, -1, 1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDRW_GOAT, buf, 0, -1) == 0); /* accessing of 0 bytes is always ok */ ZTEST(PWRITE(STDRW_GOAT, buf, 1, -1) < 0); /* size = 1, offset invalid */ ZTEST(PWRITE(STDRW_GOAT, buf, 0, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) == 0); ZTEST(PWRITE(STDRW_GOAT, buf, 1, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test (in)valid reead cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR READ CASES\n"); ZTEST(PREAD(STDRW_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDRW_GOAT, buf, -1, -1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, -1, 0) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, -1, 1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, 0, -1) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDRW_GOAT, buf, 1, -1) < 0); /* valid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, 0, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) < 0); ZTEST(PREAD(STDRW_GOAT, buf, 1, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test NULL buffer cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST NULL BUFFER CASES\n"); ZTEST(PWRITE(STDRW_GOAT, NULL, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, NULL, 0, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDRW_GOAT, (void*)0x1, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0xffff, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x10000, -1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1000001 - 0x10000, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDRW_GOAT, (void*)0x10000, 1, 0) == 1); ZTEST(PWRITE(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDRW_GOAT, (char*)main, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1000001, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDRW_GOAT, &data_start, 1, 0) == 1); ZTEST(PREAD(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* exit with code */ if(overall_errors > 0) FPRINTF(STDERR, "OVERALL TEST FAILED with %d errors\n", overall_errors); else FPRINTF(STDERR, "OVERALL TEST SUCCEED\n\n"); return overall_errors; }
/* ADIOI_cb_gather_name_array() - gather a list of processor names from all processes * in a communicator and store them on rank 0. * * This is a collective call on the communicator(s) passed in. * * Obtains a rank-ordered list of processor names from the processes in * "dupcomm". * * Returns 0 on success, -1 on failure. * * NOTE: Needs some work to cleanly handle out of memory cases! */ int ADIOI_cb_gather_name_array(MPI_Comm comm, MPI_Comm dupcomm, ADIO_cb_name_array *arrayp) { char my_procname[MPI_MAX_PROCESSOR_NAME], **procname = 0; int *procname_len = NULL, my_procname_len, *disp = NULL, i; int commsize, commrank, found; ADIO_cb_name_array array = NULL; int alloc_size; if (ADIOI_cb_config_list_keyval == MPI_KEYVAL_INVALID) { /* cleaned up by ADIOI_End_call */ MPI_Keyval_create((MPI_Copy_function *) ADIOI_cb_copy_name_array, (MPI_Delete_function *) ADIOI_cb_delete_name_array, &ADIOI_cb_config_list_keyval, NULL); } else { MPI_Attr_get(comm, ADIOI_cb_config_list_keyval, (void *) &array, &found); if (found) { ADIOI_Assert(array != NULL); *arrayp = array; return 0; } } MPI_Comm_size(dupcomm, &commsize); MPI_Comm_rank(dupcomm, &commrank); MPI_Get_processor_name(my_procname, &my_procname_len); /* allocate space for everything */ array = (ADIO_cb_name_array) ADIOI_Malloc(sizeof(*array)); if (array == NULL) { return -1; } array->refct = 2; /* we're going to associate this with two comms */ if (commrank == 0) { /* process 0 keeps the real list */ array->namect = commsize; array->names = (char **) ADIOI_Malloc(sizeof(char *) * commsize); if (array->names == NULL) { return -1; } procname = array->names; /* simpler to read */ procname_len = (int *) ADIOI_Malloc(commsize * sizeof(int)); if (procname_len == NULL) { return -1; } } else { /* everyone else just keeps an empty list as a placeholder */ array->namect = 0; array->names = NULL; } /* gather lengths first */ MPI_Gather(&my_procname_len, 1, MPI_INT, procname_len, 1, MPI_INT, 0, dupcomm); if (commrank == 0) { #ifdef CB_CONFIG_LIST_DEBUG for (i=0; i < commsize; i++) { FPRINTF(stderr, "len[%d] = %d\n", i, procname_len[i]); } #endif alloc_size = 0; for (i=0; i < commsize; i++) { /* add one to the lengths because we need to count the * terminator, and we are going to use this list of lengths * again in the gatherv. */ alloc_size += ++procname_len[i]; } procname[0] = ADIOI_Malloc(alloc_size); if (procname[0] == NULL) { return -1; } for (i=1; i < commsize; i++) { procname[i] = procname[i-1] + procname_len[i-1]; } /* create our list of displacements for the gatherv. we're going * to do everything relative to the start of the region allocated * for procname[0] */ disp = ADIOI_Malloc(commsize * sizeof(int)); disp[0] = 0; for (i=1; i < commsize; i++) { disp[i] = (int) (procname[i] - procname[0]); } } /* now gather strings */ if (commrank == 0) { MPI_Gatherv(my_procname, my_procname_len + 1, MPI_CHAR, procname[0], procname_len, disp, MPI_CHAR, 0, dupcomm); } else { /* if we didn't do this, we would need to allocate procname[] * on all processes...which seems a little silly. */ MPI_Gatherv(my_procname, my_procname_len + 1, MPI_CHAR, NULL, NULL, NULL, MPI_CHAR, 0, dupcomm); } if (commrank == 0) { /* no longer need the displacements or lengths */ ADIOI_Free(disp); ADIOI_Free(procname_len); #ifdef CB_CONFIG_LIST_DEBUG for (i=0; i < commsize; i++) { FPRINTF(stderr, "name[%d] = %s\n", i, procname[i]); } #endif } /* store the attribute; we want to store SOMETHING on all processes * so that they can all tell if we have gone through this procedure * or not for the given communicator. * * specifically we put it on both the original comm, so we can find * it next time an open is performed on this same comm, and on the * dupcomm, so we can use it in I/O operations. */ MPI_Attr_put(comm, ADIOI_cb_config_list_keyval, array); MPI_Attr_put(dupcomm, ADIOI_cb_config_list_keyval, array); *arrayp = array; return 0; }
/* match_procs() - given a name (or NULL for wildcard) and a max. number * of aggregator processes (per processor name), this * matches in the procnames[] array and puts appropriate * ranks in the ranks array. * * Parameters: * name - processor name (or NULL for wildcard) * max_per_proc - maximum # of processes to use for aggregation from a * single processor * procnames - array of processor names * nr_procnames - length of procnames array * ranks - array of process ranks * nr_ranks - length of process ranks array (also max. # of aggregators) * nr_ranks_allocated - # of array entries which have been filled in, * which is also the index to the first empty entry * * Returns number of matches. */ static int match_procs(char *name, int max_per_proc, char *procnames[], char used_procnames[], int nr_procnames, int ranks[], int nr_ranks, int *nr_ranks_allocated) { int wildcard_proc, cur_proc, old_nr_allocated, ret; /* save this so we can report on progress */ old_nr_allocated = *nr_ranks_allocated; if (name == NULL) { /* wildcard case */ /* optimize for *:0 case */ if (max_per_proc == 0) { /* loop through procnames and mark them all as used */ for (cur_proc = 0; cur_proc < nr_procnames; cur_proc++) { used_procnames[cur_proc] = 1; } return 0; } /* the plan here is to start at the beginning of the procnames * array looking for processor names to apply the wildcard to. * * we set wildcard_proc to 0 here but do the search inside the * while loop so that we aren't starting our search from the * beginning of the procnames array each time. */ wildcard_proc = 0; while (nr_ranks - *nr_ranks_allocated > 0) { /* find a name */ while ((wildcard_proc < nr_procnames) && (used_procnames[wildcard_proc] != 0)) { wildcard_proc++; } if (wildcard_proc == nr_procnames) { /* we have used up the entire procnames list */ return *nr_ranks_allocated - old_nr_allocated; } #ifdef CB_CONFIG_LIST_DEBUG FPRINTF(stderr, "performing wildcard match (*:%d) starting with %s (%d)\n", max_per_proc, procnames[wildcard_proc], wildcard_proc); #endif cur_proc = wildcard_proc; #ifdef CB_CONFIG_LIST_DEBUG FPRINTF(stderr, " assigning name %s (%d) to rank %d in mapping\n", procnames[cur_proc], cur_proc, *nr_ranks_allocated); #endif /* alloc max_per_proc from this host; cur_proc points to * the first one. We want to save this name for use in * our while loop. */ ranks[*nr_ranks_allocated] = cur_proc; *nr_ranks_allocated = *nr_ranks_allocated + 1; cur_proc++; /* so, to accomplish this we use the match_this_proc() to * alloc max_per_proc-1. we increment cur_proc so that the * procnames[] entry doesn't get trashed. then AFTER the call * we clean up the first instance of the name. */ ret = match_this_proc(procnames[wildcard_proc], cur_proc, max_per_proc-1, procnames, used_procnames, nr_procnames, ranks, nr_ranks, *nr_ranks_allocated); if (ret > 0) *nr_ranks_allocated = *nr_ranks_allocated + ret; /* clean up and point wildcard_proc to the next entry, since * we know that this one is NULL now. */ used_procnames[wildcard_proc] = 1; wildcard_proc++; } } else { /* specific host was specified; this one is easy */ #ifdef CB_CONFIG_LIST_DEBUG FPRINTF(stderr, "performing name match (%s:%d)\n", name, max_per_proc); #endif ret = match_this_proc(name, 0, max_per_proc, procnames, used_procnames, nr_procnames, ranks, nr_ranks, *nr_ranks_allocated); if (ret > 0) *nr_ranks_allocated = *nr_ranks_allocated + ret; } return *nr_ranks_allocated - old_nr_allocated; }
void util_out_print_vaparm(caddr_t message, int flush, va_list var, int faocnt) { char fmt_buff[OUT_BUFF_SIZE]; caddr_t fmtc; int rc; /* * Note: this function checks for EINTR on FPRINTF. This check should not be * converted to an EINTR wrapper macro because of the variable number of args used * by fprintf. */ if (util_outptr == NULL) util_outptr = util_outbuff; if (message != NULL) util_outptr = util_format(message, var, util_outptr, OUT_BUFF_SIZE - (util_outptr - util_outbuff) - 2, faocnt); switch (flush) { case NOFLUSH: break; case RESET: break; case FLUSH: *util_outptr++ = '\n'; case OPER: case SPRINT: /****************************************************************************************************** For all three of these actions we need to do some output buffer translation. In all cases a '%' is translated to the escape version '%%'. For OPER and SPRINT, we also translate '\n' to a ', ' since some syslog() implementations (like Tru64) stop processing the passed message on a newline. *******************************************************************************************************/ *util_outptr = '\0'; for (util_outptr = util_outbuff, fmtc = fmt_buff; 0 != *util_outptr; ) { if ('%' == *util_outptr) { *fmtc++ = '%'; /* escape for '%' */ *fmtc++ = '%'; util_outptr++; } else if ('\n' == *util_outptr && (OPER == flush || SPRINT == flush)) { *fmtc++ = ','; *fmtc++ = ' '; util_outptr++; } else *fmtc++ = *util_outptr++; } *fmtc++ = '\0'; switch (flush) { case FLUSH: do { rc = FPRINTF(stderr, fmt_buff); } while (-1 == rc && EINTR == errno); break; case OPER: util_out_send_oper(STR_AND_LEN(fmt_buff)); break; case SPRINT: memcpy(util_outbuff, fmt_buff, fmtc - fmt_buff); break; } break; default: assert(FALSE); } switch (flush) { case NOFLUSH: break; case FLUSH: case RESET: case OPER: case SPRINT: /* Reset buffer information. */ util_outptr = util_outbuff; break; } }
int VCPU::print_state_compat(FILE * o) const { int len = 0; if ( this->flags & CPU_GP_REGS ) { len += FPRINTF(o, "\tEIP: %04"PRIx16":[<%08"PRIx32">] Ring %d\n", this->regs.cs, this->regs.eip, this->regs.cs & 0x3); len += FPRINTF(o, "\tEFLAGS: %08"PRIx32" ", this->regs.eflags); len += print_rflags(o, this->regs.rflags & -((uint32_t)1)); len += FPUTS("\n", o); len += FPRINTF(o, "\teax: %08"PRIx32" ebx: %08"PRIx32" ", this->regs.eax, this->regs.ebx); len += FPRINTF(o, "ecx: %08"PRIx32" edx: %08"PRIx32"\n", this->regs.ecx, this->regs.edx); len += FPRINTF(o, "\tesi: %08"PRIx32" edi: %08"PRIx32" ", this->regs.esi, this->regs.edi); len += FPRINTF(o, "ebp: %08"PRIx32" esp: %08"PRIx32"\n", this->regs.ebp, this->regs.esp); } if ( this->flags & CPU_CR_REGS ) { len += FPRINTF(o, "\tcr3: %016"PRIx64"\n", this->regs.cr3); } if ( this->flags & CPU_GP_REGS ) { len += FPUTS("\n", o); if ( this->flags & CPU_SEG_REGS ) len += FPRINTF(o, "\tds: %04"PRIx16" es: %04"PRIx16" " "fs: %04"PRIx16" gs: %04"PRIx16" " "ss: %04"PRIx16" cs: %04"PRIx16"\n", this->regs.ds, this->regs.es, this->regs.fs, this->regs.gs, this->regs.ss, this->regs.cs); else len += FPRINTF(o, "\tss: %04"PRIx16" cs: %04"PRIx16"\n", this->regs.ss, this->regs.cs); } len += FPUTS("\n", o); len += FPRINTF(o, "\tPause Count: %"PRId32", Flags: 0x%"PRIx32" ", this->pause_count, this->pause_flags); len += print_pause_flags(o, this->pause_flags); len += FPUTS("\n", o); switch ( this->runstate ) { case RST_NONE: len += FPRINTF(o, "\tNot running: Last run on PCPU%"PRIu32"\n", this->processor); break; case RST_RUNNING: len += FPRINTF(o, "\tCurrently running on PCPU%"PRIu32"\n", this->processor); break; case RST_CTX_SWITCH: len += FPUTS("\tBeing Context Switched: State unreliable\n", o); break; default: len += FPUTS("\tUnknown runstate\n", o); break; } len += FPRINTF(o, "\tStruct vcpu at %016"PRIx64"\n", this->vcpu_ptr); len += FPUTS("\n", o); if ( this->flags & CPU_GP_REGS && this->flags & CPU_CR_REGS ) { len += FPRINTF(o, "\tStack at %08"PRIx32":", this->regs.esp); len += print_32bit_stack(o, *this->dompt, this->regs.rsp); len += FPUTS("\n\tCode:\n", o); len += print_code(o, *this->dompt, this->regs.rip); len += FPUTS("\n\tCall Trace:\n", o); if ( this->domid == 0 ) { vaddr_t sp = this->regs.rsp; vaddr_t top = (this->regs.rsp | (PAGE_SIZE-1))+1; union { uint32_t val32; uint64_t val64; } val; val.val64 = 0; len += host.dom0_symtab.print_symbol32(o, this->regs.rip, true); try { while ( sp < top ) { memory.read32_vaddr(*this->dompt, sp, val.val32); len += host.dom0_symtab.print_symbol32(o, val.val64); sp += 4; } } catch ( const CommonError & e ) { e.log(); } } else len += FPUTS("\t No symbol table for domain\n", o); } len += FPUTS("\n", o); return len; }
int main(int argc, char **argv) #endif { int i; #ifdef LINUXVGA LINUX_setup(); /* setup VGA before dropping privilege DBT 4/5/99 */ drop_privilege(); #endif /* make sure that we really have revoked root access, this might happen if gnuplot is compiled without vga support but is installed suid by mistake */ #ifdef __linux__ setuid(getuid()); #endif #if defined(MSDOS) && !defined(_Windows) && !defined(__GNUC__) PC_setup(); #endif /* MSDOS !Windows */ /* HBB: Seems this isn't needed any more for DJGPP V2? */ /* HBB: disable all floating point exceptions, just keep running... */ #if defined(DJGPP) && (DJGPP!=2) _control87(MCW_EM, MCW_EM); #endif #if defined(OS2) int rc; #ifdef OS2_IPC char semInputReadyName[40]; sprintf( semInputReadyName, "\\SEM32\\GP%i_Input_Ready", getpid() ); rc = DosCreateEventSem(semInputReadyName,&semInputReady,0,0); if (rc != 0) fputs("DosCreateEventSem error\n",stderr); #endif rc = RexxRegisterSubcomExe("GNUPLOT", (PFN) RexxInterface, NULL); #endif /* malloc large blocks, otherwise problems with fragmented mem */ #ifdef OSK _mallocmin(102400); #endif #ifdef MALLOCDEBUG malloc_debug(7); #endif /* get helpfile from home directory */ #ifndef DOSX286 # ifndef _Windows # if defined (__TURBOC__) && (defined (MSDOS) || defined(DOS386)) strcpy(HelpFile, argv[0]); strcpy(strrchr(HelpFile, DIRSEP1), "\\gnuplot.gih"); # endif /* - DJL */ # endif /* !_Windows */ #endif /* !DOSX286 */ #ifdef __DJGPP__ { char *s; strcpy(HelpFile, argv[0]); for (s = HelpFile; *s; s++) if (*s == DIRSEP1) *s = DIRSEP2; /* '\\' to '/' */ strcpy(strrchr(HelpFile, DIRSEP2), "/gnuplot.gih"); } /* Add also some "paranoid" tests for '\\': AP */ #endif /* DJGPP */ #ifdef VMS unsigned int status[2] = { 1, 0 }; #endif #if defined(HAVE_LIBEDITLINE) rl_getc_function = getc_wrapper; #endif #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) using_history(); /* T.Walter 1999-06-24: 'rl_readline_name' must be this fix name. * It is used to parse a 'gnuplot' specific section in '~/.inputrc' */ rl_readline_name = "Gnuplot"; rl_terminal_name = getenv("TERM"); #endif #if defined(HAVE_LIBREADLINE) rl_complete_with_tilde_expansion = 1; #endif for (i = 1; i < argc; i++) { if (!argv[i]) continue; if (!strcmp(argv[i], "-V") || !strcmp(argv[i], "--version")) { printf("gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); return 0; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { printf( "Usage: gnuplot [OPTION]... [FILE]\n" #ifdef X11 "for X11 options see 'help X11->command-line-options'\n" #endif " -V, --version\n" " -h, --help\n" " -p --persist\n" " -e \"command1; command2; ...\"\n" "gnuplot %s patchlevel %s\n" #ifdef DIST_CONTACT "Report bugs to "DIST_CONTACT"\n" " or %s\n", #else "Report bugs to %s\n", #endif gnuplot_version, gnuplot_patchlevel, bug_report); return 0; } else if (!strncmp(argv[i], "-persist", 2) || !strcmp(argv[i], "--persist")) { persist_cl = TRUE; } } #ifdef X11 /* the X11 terminal removes tokens that it recognizes from argv. */ { int n = X11_args(argc, argv); argv += n; argc -= n; } #endif #ifdef APOLLO apollo_pfm_catch(); #endif setbuf(stderr, (char *) NULL); #ifdef HAVE_SETVBUF /* this was once setlinebuf(). Docs say this is * identical to setvbuf(,NULL,_IOLBF,0), but MS C * faults this (size out of range), so we try with * size of 1024 instead. [SAS/C does that, too. -lh] * Failing this, I propose we just make the call and * ignore the return : its probably not a big deal */ if (setvbuf(stdout, (char *) NULL, _IOLBF, (size_t) 1024) != 0) (void) fputs("Could not linebuffer stdout\n", stderr); #ifdef X11 /* This call used to be in x11.trm, with the following comment: * Multi-character inputs like escape sequences but also mouse-pasted * text got buffered and therefore didn't trigger the select() function * in X11_waitforinput(). Switching to unbuffered input solved this. * 23 Jan 2002 (joze) * But switching to unbuffered mode causes all characters in the input * buffer to be lost. So the only safe time to do it is on program entry. * The #ifdef X11 is probably unnecessary, but makes the change minimal. * Do any non-X platforms suffer from the same problem? * EAM - Jan 2004. */ setvbuf(stdin, (char *) NULL, _IONBF, 0); #endif #endif gpoutfile = stdout; /* Initialize pre-loaded user variables */ (void) Gcomplex(&udv_pi.udv_value, M_PI, 0.0); #ifdef HAVE_ISNAN udv_NaN = add_udv_by_name("NaN"); (void) Gcomplex(&(udv_NaN->udv_value), not_a_number(), 0.0); udv_NaN->udv_undef = FALSE; #endif init_memory(); interactive = FALSE; init_terminal(); /* can set term type if it likes */ push_terminal(0); /* remember the default terminal */ /* reset the terminal when exiting */ /* this is done through gp_atexit so that other terminal functions * can be registered to be executed before the terminal is reset. */ GP_ATEXIT(term_reset); #ifdef AMIGA_SC_6_1 if (IsInteractive(Input()) == DOSTRUE) interactive = TRUE; else interactive = FALSE; #else # if ((defined(__MSC__) && defined(_Windows)) || defined(__WIN32__)) && ! defined(WGP_CONSOLE) interactive = TRUE; # else interactive = isatty(fileno(stdin)); # endif #endif /* !AMIGA_SC_6_1 */ if (argc > 1) interactive = noinputfiles = FALSE; else noinputfiles = TRUE; /* Need this before show_version is called for the first time */ #ifdef HAVE_SYS_UTSNAME_H { struct utsname uts; /* something is fundamentally wrong if this fails ... */ if (uname(&uts) > -1) { # ifdef _AIX strcpy(os_name, uts.sysname); sprintf(os_name, "%s.%s", uts.version, uts.release); # elif defined(SCO) strcpy(os_name, "SCO"); strcpy(os_rel, uts.release); # elif defined(DJGPP) if (!strncmp(uts.sysname, "??Un", 4)) /* don't print ??Unknow" */ strcpy(os_name, "Unknown"); else { strcpy(os_name, uts.sysname); strcpy(os_rel, uts.release); } # else strcpy(os_name, uts.sysname); strcpy(os_rel, uts.release); # ifdef OS2 if (!strchr(os_rel,'.')) /* write either "2.40" or "4.0", or empty -- don't print "OS/2 1" */ strcpy(os_rel, ""); # endif # endif } } #else /* ! HAVE_SYS_UTSNAME_H */ strcpy(os_name, OS); strcpy(os_rel, ""); #endif /* HAVE_SYS_UTSNAME_H */ if (interactive) show_version(stderr); else show_version(NULL); /* Only load GPVAL_COMPILE_OPTIONS */ update_gpval_variables(3); /* update GPVAL_ variables available to user */ #ifdef VMS /* initialise screen management routines for command recall */ if (status[1] = smg$create_virtual_keyboard(&vms_vkid) != SS$_NORMAL) done(status[1]); if (status[1] = smg$create_key_table(&vms_ktid) != SS$_NORMAL) done(status[1]); #endif /* VMS */ if (!SETJMP(command_line_env, 1)) { /* first time */ interrupt_setup(); /* should move this stuff another initialisation routine, * something like init_set() maybe */ get_user_env(); init_loadpath(); init_locale(); /* HBB: make sure all variables start in the same mode 'reset' * would set them to. Since the axis variables aren't in * initialized arrays any more, this is now necessary... */ reset_command(); init_color(); /* Initialization of color */ load_rcfile(); init_fit(); /* Initialization of fitting module */ if (interactive && term != 0) { /* not unknown */ #ifdef GNUPLOT_HISTORY FPRINTF((stderr, "Before read_history\n")); #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) expanded_history_filename = tilde_expand(GNUPLOT_HISTORY_FILE); #else expanded_history_filename = gp_strdup(GNUPLOT_HISTORY_FILE); gp_expand_tilde(&expanded_history_filename); #endif FPRINTF((stderr, "expanded_history_filename = %s\n", expanded_history_filename)); read_history(expanded_history_filename); { /* BEGIN: Go local to get environment variable */ const char *temp_env = getenv ("GNUPLOT_HISTORY_SIZE"); if (temp_env) gnuplot_history_size = strtol (temp_env, (char **) NULL, 10); } /* END: Go local to get environment variable */ /* * It is safe to ignore the return values of 'atexit()' and * 'on_exit()'. In the worst case, there is no history of your * currrent session and you have to type all again in your next * session. * This is the default behaviour (traditional reasons), too. * In case you don't have one of these functions, or you don't * want to use them, 'write_history()' is called directly. */ GP_ATEXIT(wrapper_for_write_history); #endif /* GNUPLOT_HISTORY */ fprintf(stderr, "\nTerminal type set to '%s'\n", term->name); } /* if (interactive && term != 0) */ } else { /* come back here from int_error() */ if (interactive == FALSE) exit_status = EXIT_FAILURE; #ifdef HAVE_LIBREADLINE else { /* reset properly readline after a SIGINT+longjmp */ rl_reset_after_signal (); } #endif #ifdef AMIGA_SC_6_1 (void) rawcon(0); #endif load_file_error(); /* if we were in load_file(), cleanup */ reset_eval_depth(); /* reset evaluate command recursion counter */ SET_CURSOR_ARROW; #ifdef VMS /* after catching interrupt */ /* VAX stuffs up stdout on SIGINT while writing to stdout, so reopen stdout. */ if (gpoutfile == stdout) { if ((stdout = freopen("SYS$OUTPUT", "w", stdout)) == NULL) { /* couldn't reopen it so try opening it instead */ if ((stdout = fopen("SYS$OUTPUT", "w")) == NULL) { /* don't use int_error here - causes infinite loop! */ fputs("Error opening SYS$OUTPUT as stdout\n", stderr); } } gpoutfile = stdout; } #endif /* VMS */ if (!interactive && !noinputfiles) { term_reset(); exit(EXIT_FAILURE); /* exit on non-interactive error */ } } if (argc > 1) { #ifdef _Windows TBOOLEAN noend = persist_cl; #endif /* load filenames given as arguments */ while (--argc > 0) { ++argv; c_token = NO_CARET; /* in case of file not found */ #ifdef _Windows if (stricmp(*argv, "-noend") == 0 || stricmp(*argv, "/noend") == 0 || stricmp(*argv, "-persist") == 0) noend = TRUE; else #endif if (!strncmp(*argv, "-persist", 2) || !strcmp(*argv, "--persist")) { FPRINTF((stderr,"'persist' command line option recognized\n")); } else if (strcmp(*argv, "-") == 0) { /* DBT 10-7-98 go interactive if "-" on command line */ interactive = TRUE; /* will this work on all platforms? */ while (!com_line()); interactive = FALSE; } else if (strcmp(*argv, "-e") == 0) { --argc; ++argv; if (argc <= 0) { fprintf(stderr, "syntax: gnuplot -e \"commands\"\n"); return 0; } do_string(*argv, FALSE); } else load_file(loadpath_fopen(*argv, "r"), gp_strdup(*argv), FALSE); } #ifdef _Windows if (noend) { interactive = TRUE; while (!com_line()); } #endif } else { /* take commands from stdin */ while (!com_line()); } #if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE)) && defined(GNUPLOT_HISTORY) #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT) /* You should be here if you neither have 'atexit()' nor 'on_exit()' */ wrapper_for_write_history(); #endif /* !HAVE_ATEXIT && !HAVE_ON_EXIT */ #endif /* (HAVE_LIBREADLINE || HAVE_LIBEDITLINE) && GNUPLOT_HISTORY */ #ifdef OS2 RexxDeregisterSubcom("GNUPLOT", NULL); #endif /* HBB 20040223: Not all compilers like exit() to end main() */ /* exit(exit_status); */ return exit_status; }
static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message) { static int n; unsigned int s; char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; const struct TestMessage *hdr; hdr = (const struct TestMessage *) message; if (MTYPE != ntohs (message->type)) return; msg_recv = ntohl (hdr->num); s = get_size (ntohl (hdr->num)); if (ntohs (message->size) != s) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected message %u of size %u, got %u bytes of message %u\n", ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num)); if (NULL != die_task) GNUNET_SCHEDULER_cancel (die_task); test_sending = GNUNET_YES; die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); return; } memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage)); if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected message %u with bits %u, but body did not match\n", ntohl (hdr->num), (unsigned char) n); if (NULL != die_task) GNUNET_SCHEDULER_cancel (die_task); test_sending = GNUNET_YES; die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); return; } #if VERBOSE if (ntohl (hdr->num) % 5 == 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", ntohl (hdr->num), ntohs (message->size)); } #endif n++; if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Message id %u is bigger than maxmimum number of messages %u expected\n", ntohl (hdr->num), TOTAL_MSGS); } test_sending = GNUNET_YES; if (0 == (n % (TOTAL_MSGS / 100))) { FPRINTF (stderr, "%s", "."); if (NULL != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); } if (n == TOTAL_MSGS) { end (); } }
/* * This is more general aggregator search function which does not base on the assumption * that each aggregator hosts the file domain with the same size */ int ADIOI_GPFS_Calc_aggregator(ADIO_File fd, ADIO_Offset off, ADIO_Offset min_off, ADIO_Offset *len, ADIO_Offset fd_size, ADIO_Offset *fd_start, ADIO_Offset *fd_end) { int rank_index, rank; ADIO_Offset avail_bytes; TRACE_ERR("Entering ADIOI_GPFS_Calc_aggregator\n"); ADIOI_Assert ( (off <= fd_end[fd->hints->cb_nodes-1] && off >= min_off && fd_start[0] >= min_off ) ); /* binary search --> rank_index is returned */ int ub = fd->hints->cb_nodes; int lb = 0; /* get an index into our array of aggregators */ /* Common code for striping - bg doesn't use it but it's here to make diff'ing easier. rank_index = (int) ((off - min_off + fd_size)/ fd_size - 1); if (fd->hints->striping_unit > 0) { * wkliao: implementation for file domain alignment fd_start[] and fd_end[] have been aligned with file lock boundaries when returned from ADIOI_Calc_file_domains() so cannot just use simple arithmatic as above * rank_index = 0; while (off > fd_end[rank_index]) rank_index++; } bg does it's own striping below */ rank_index = fd->hints->cb_nodes / 2; while ( off < fd_start[rank_index] || off > fd_end[rank_index] ) { if ( off > fd_end [rank_index] ) { lb = rank_index; rank_index = (rank_index + ub) / 2; } else if ( off < fd_start[rank_index] ) { ub = rank_index; rank_index = (rank_index + lb) / 2; } } /* we index into fd_end with rank_index, and fd_end was allocated to be no * bigger than fd->hins->cb_nodes. If we ever violate that, we're * overrunning arrays. Obviously, we should never ever hit this abort */ if (rank_index >= fd->hints->cb_nodes || rank_index < 0) { FPRINTF(stderr, "Error in ADIOI_Calc_aggregator(): rank_index(%d) >= fd->hints->cb_nodes (%d) fd_size=%lld off=%lld\n", rank_index,fd->hints->cb_nodes,fd_size,off); MPI_Abort(MPI_COMM_WORLD, 1); } /* DBG_FPRINTF ("ADIOI_GPFS_Calc_aggregator: rank_index = %d\n", rank_index ); */ /* * remember here that even in Rajeev's original code it was the case that * different aggregators could end up with different amounts of data to * aggregate. here we use fd_end[] to make sure that we know how much * data this aggregator is working with. * * the +1 is to take into account the end vs. length issue. */ avail_bytes = fd_end[rank_index] + 1 - off; if (avail_bytes < *len && avail_bytes > 0) { /* this file domain only has part of the requested contig. region */ *len = avail_bytes; } /* map our index to a rank */ /* NOTE: FOR NOW WE DON'T HAVE A MAPPING...JUST DO 0..NPROCS_FOR_COLL */ rank = fd->hints->ranklist[rank_index]; TRACE_ERR("Leaving ADIOI_GPFS_Calc_aggregator\n"); return rank; }
/* EAM July 2004 (revised to dynamic buffer July 2005) * There are probably an infinite number of things that can * go wrong if the user mis-matches arguments and format strings * in the call to sprintf, but I hope none will do worse than * result in a garbage output string. */ void f_sprintf(union argument *arg) { struct value a[10], *args; struct value num_params; struct value result; char *buffer; int bufsize; char *next_start, *outpos, tempchar; int next_length; char *prev_start; int prev_pos; int i, remaining; int nargs = 0; int save_errno; enum DATA_TYPES spec_type; /* Retrieve number of parameters from top of stack */ pop(&num_params); nargs = num_params.v.int_val; if (nargs > 10) { /* Fall back to slow but sure allocation */ args = gp_alloc(sizeof(struct value)*nargs, "sprintf args"); } else args = a; for (i=0; i<nargs; i++) pop(&args[i]); /* pop next argument */ /* Make sure we got a format string of some sort */ if (args[nargs-1].type != STRING) int_error(NO_CARET,"First parameter to sprintf must be a format string"); /* Allocate space for the output string. If this isn't */ /* long enough we can reallocate a larger space later. */ bufsize = 80 + strlen(args[nargs-1].v.string_val); buffer = gp_alloc(bufsize, "f_sprintf"); /* Copy leading fragment of format into output buffer */ outpos = buffer; next_start = args[nargs-1].v.string_val; next_length = strcspn(next_start,"%"); strncpy(outpos, next_start, next_length); next_start += next_length; outpos += next_length; /* Format the remaining sprintf() parameters one by one */ prev_start = next_start; prev_pos = next_length; remaining = nargs - 1; /* If the user has set an explicit LC_NUMERIC locale, apply it */ /* to sprintf calls during expression evaluation. */ set_numeric_locale(); /* Each time we start this loop we are pointing to a % character */ while (remaining-->0 && next_start[0] && next_start[1]) { struct value *next_param = &args[remaining]; /* Check for %%; print as literal and don't consume a parameter */ if (!strncmp(next_start,"%%",2)) { next_start++; do { *outpos++ = *next_start++; } while(*next_start && *next_start != '%'); remaining++; continue; } next_length = strcspn(next_start+1,"%") + 1; tempchar = next_start[next_length]; next_start[next_length] = '\0'; spec_type = sprintf_specifier(next_start); /* string value <-> numerical value check */ if ( spec_type == STRING && next_param->type != STRING ) int_error(NO_CARET,"f_sprintf: attempt to print numeric value with string format"); if ( spec_type != STRING && next_param->type == STRING ) int_error(NO_CARET,"f_sprintf: attempt to print string value with numeric format"); #ifdef HAVE_SNPRINTF /* Use the format to print next arg */ save_errno = errno; switch(spec_type) { case INTGR: snprintf(outpos,bufsize-(outpos-buffer), next_start, (int)real(next_param)); break; case CMPLX: snprintf(outpos,bufsize-(outpos-buffer), next_start, real(next_param)); break; case STRING: snprintf(outpos,bufsize-(outpos-buffer), next_start, next_param->v.string_val); break; default: int_error(NO_CARET,"internal error: invalid spec_type"); } #if _MSC_VER buffer[bufsize-1] = '\0'; /* VC++ is not ANSI-compliant */ if (errno == ERANGE) errno = save_errno; #endif #else /* FIXME - this is bad; we should dummy up an snprintf equivalent */ switch(spec_type) { case INTGR: sprintf(outpos, next_start, (int)real(next_param)); break; case CMPLX: sprintf(outpos, next_start, real(next_param)); break; case STRING: sprintf(outpos, next_start, next_param->v.string_val); break; default: int_error(NO_CARET,"internal error: invalid spec_type"); } #endif next_start[next_length] = tempchar; next_start += next_length; outpos = &buffer[strlen(buffer)]; /* Check whether previous parameter output hit the end of the buffer */ /* If so, reallocate a larger buffer, go back and try it again. */ if (strlen(buffer) >= bufsize-2) { bufsize *= 2; buffer = gp_realloc(buffer, bufsize, "f_sprintf"); next_start = prev_start; outpos = buffer + prev_pos; remaining++; continue; } else { prev_start = next_start; prev_pos = outpos - buffer; } } /* Copy the trailing portion of the format, if any */ /* We could just call snprintf(), but it doesn't check for */ /* whether there really are more variables to handle. */ i = bufsize - (outpos-buffer); while (*next_start && --i > 0) { if (*next_start == '%' && *(next_start+1) == '%') next_start++; *outpos++ = *next_start++; } *outpos = '\0'; FPRINTF((stderr," snprintf result = \"%s\"\n",buffer)); push(Gstring(&result, buffer)); free(buffer); /* Free any strings from parameters we have now used */ for (i=0; i<nargs; i++) gpfree_string(&args[i]); if (args != a) free(args); /* Return to C locale for internal use */ reset_numeric_locale(); }
void ADIOI_PIOFS_WriteStrided(ADIO_File fd, void *buf, int count, MPI_Datatype datatype, int file_ptr_type, ADIO_Offset offset, ADIO_Status *status, int *error_code) { /* Since PIOFS does not support file locking, can't do buffered writes as on Unix */ /* offset is in units of etype relative to the filetype. */ ADIOI_Flatlist_node *flat_buf, *flat_file; struct iovec *iov; int i, j, k, err=-1, bwr_size, fwr_size=0, st_index=0; int num, size, sum, n_etypes_in_filetype, size_in_filetype; MPI_Count bufsize; int n_filetypes, etype_in_filetype; ADIO_Offset abs_off_in_filetype=0; MPI_Count filetype_size, etype_size, buftype_size; MPI_Aint filetype_extent, buftype_extent, indx; int buf_count, buftype_is_contig, filetype_is_contig; ADIO_Offset off, disp; int flag, new_bwr_size, new_fwr_size, err_flag=0; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_PIOFS_WRITESTRIDED"; #endif if (fd->atomicity) { FPRINTF(stderr, "ROMIO cannot guarantee atomicity of noncontiguous accesses in atomic mode, as PIOFS doesn't support file locking. Use nonatomic mode and its associated semantics.\n"); MPI_Abort(MPI_COMM_WORLD, 1); } ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig); MPI_Type_size_x(fd->filetype, &filetype_size); if ( ! filetype_size ) { #ifdef HAVE_STATUS_SET_BYTES MPIR_Status_set_bytes(status, datatype, 0); #endif *error_code = MPI_SUCCESS; return; } MPI_Type_extent(fd->filetype, &filetype_extent); MPI_Type_size_x(datatype, &buftype_size); MPI_Type_extent(datatype, &buftype_extent); etype_size = fd->etype_size; bufsize = buftype_size * count; if (!buftype_is_contig && filetype_is_contig) { /* noncontiguous in memory, contiguous in file. use writev */ ADIOI_Flatten_datatype(datatype); flat_buf = ADIOI_Flatlist; while (flat_buf->type != datatype) flat_buf = flat_buf->next; /* There is a limit of 16 on the number of iovecs for readv/writev! */ iov = (struct iovec *) ADIOI_Malloc(16*sizeof(struct iovec)); if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { off = fd->disp + etype_size * offset; llseek(fd->fd_sys, off, SEEK_SET); } else off = llseek(fd->fd_sys, fd->fp_ind, SEEK_SET); k = 0; for (j=0; j<count; j++) for (i=0; i<flat_buf->count; i++) { iov[k].iov_base = ((char *) buf) + j*buftype_extent + flat_buf->indices[i]; iov[k].iov_len = flat_buf->blocklens[i]; /*FPRINTF(stderr, "%d %d\n", iov[k].iov_base, iov[k].iov_len);*/ off += flat_buf->blocklens[i]; k = (k+1)%16; if (!k) { err = writev(fd->fd_sys, iov, 16); if (err == -1) err_flag = 1; } } if (k) { err = writev(fd->fd_sys, iov, k); if (err == -1) err_flag = 1; } if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off; ADIOI_Free(iov); if (err_flag) { #ifdef MPICH *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else /* MPICH-1 */ *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; } /* if (!buftype_is_contig && filetype_is_contig) ... */ else { /* noncontiguous in file */ /* split up into several contiguous writes */ /* find starting location in the file */ /* filetype already flattened in ADIO_Open */ flat_file = ADIOI_Flatlist; while (flat_file->type != fd->filetype) flat_file = flat_file->next; disp = fd->disp; if (file_ptr_type == ADIO_INDIVIDUAL) { offset = fd->fp_ind; /* in bytes */ n_filetypes = -1; flag = 0; while (!flag) { n_filetypes++; for (i=0; i<flat_file->count; i++) { if (disp + flat_file->indices[i] + (ADIO_Offset) n_filetypes*filetype_extent + flat_file->blocklens[i] >= offset) { st_index = i; fwr_size = disp + flat_file->indices[i] + (ADIO_Offset) n_filetypes*filetype_extent + flat_file->blocklens[i] - offset; flag = 1; break; } } } } else { n_etypes_in_filetype = filetype_size/etype_size; n_filetypes = (int) (offset / n_etypes_in_filetype); etype_in_filetype = (int) (offset % n_etypes_in_filetype); size_in_filetype = etype_in_filetype * etype_size; sum = 0; for (i=0; i<flat_file->count; i++) { sum += flat_file->blocklens[i]; if (sum > size_in_filetype) { st_index = i; fwr_size = sum - size_in_filetype; abs_off_in_filetype = flat_file->indices[i] + size_in_filetype - (sum - flat_file->blocklens[i]); break; } } /* abs. offset in bytes in the file */ offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + abs_off_in_filetype; } if (buftype_is_contig && !filetype_is_contig) { /* contiguous in memory, noncontiguous in file. should be the most common case. */ i = 0; j = st_index; off = offset; fwr_size = ADIOI_MIN(fwr_size, bufsize); while (i < bufsize) { if (fwr_size) { /* TYPE_UB and TYPE_LB can result in fwr_size = 0. save system call in such cases */ llseek(fd->fd_sys, off, SEEK_SET); err = write(fd->fd_sys, ((char *) buf) + i, fwr_size); if (err == -1) err_flag = 1; } i += fwr_size; if (off + fwr_size < disp + flat_file->indices[j] + flat_file->blocklens[j] + (ADIO_Offset) n_filetypes*filetype_extent) off += fwr_size; /* did not reach end of contiguous block in filetype. no more I/O needed. off is incremented by fwr_size. */ else { if (j < (flat_file->count - 1)) j++; else { j = 0; n_filetypes++; } off = disp + flat_file->indices[j] + (ADIO_Offset) n_filetypes*filetype_extent; fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i); } } } else { /* noncontiguous in memory as well as in file */ ADIOI_Flatten_datatype(datatype); flat_buf = ADIOI_Flatlist; while (flat_buf->type != datatype) flat_buf = flat_buf->next; k = num = buf_count = 0; indx = flat_buf->indices[0]; j = st_index; off = offset; bwr_size = flat_buf->blocklens[0]; while (num < bufsize) { size = ADIOI_MIN(fwr_size, bwr_size); if (size) { llseek(fd->fd_sys, off, SEEK_SET); err = write(fd->fd_sys, ((char *) buf) + indx, size); if (err == -1) err_flag = 1; } new_fwr_size = fwr_size; new_bwr_size = bwr_size; if (size == fwr_size) { /* reached end of contiguous block in file */ if (j < (flat_file->count - 1)) j++; else { j = 0; n_filetypes++; } off = disp + flat_file->indices[j] + (ADIO_Offset) n_filetypes*filetype_extent; new_fwr_size = flat_file->blocklens[j]; if (size != bwr_size) { indx += size; new_bwr_size -= size; } } if (size == bwr_size) { /* reached end of contiguous block in memory */ k = (k + 1)%flat_buf->count; buf_count++; indx = buftype_extent*(buf_count/flat_buf->count) + flat_buf->indices[k]; new_bwr_size = flat_buf->blocklens[k]; if (size != fwr_size) { off += size; new_fwr_size -= size; } } num += size; fwr_size = new_fwr_size; bwr_size = new_bwr_size; } } if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off; if (err_flag) { #ifdef MPICH *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else /* MPICH-1 */ *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; } fd->fp_sys_posn = -1; /* set it to null. */ #ifdef HAVE_STATUS_SET_BYTES MPIR_Status_set_bytes(status, datatype, bufsize); /* This is a temporary way of filling in status. The right way is to keep track of how much data was actually written by ADIOI_BUFFERED_WRITE. */ #endif if (!buftype_is_contig) ADIOI_Delete_flattened(datatype); }
/** stMEMGINFO_Prt function. * * Printing Function * * @param *pcPrtPrefixStr : Print Prefix String * @param *pthis : Print변수 Pointer * * @return void * @see memg.h * * @exception 규칙에 틀린 곳을 찾아주세요. * @note structg.pl로 만들어진 자동 코드 **/ void stMEMGINFO_Prt(S8 *pcPrtPrefixStr, stMEMGINFO *pthis){ FPRINTF(LOG_LEVEL,"_%s : pthis = %p",pcPrtPrefixStr, pthis); /* U32 uiType */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiType = %u",pcPrtPrefixStr,(U32)(pthis->uiType)); /* U32 uiShmKey */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiShmKey = %u",pcPrtPrefixStr,(U32)(pthis->uiShmKey)); /* U32 uiTotMemSize */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiTotMemSize = %u",pcPrtPrefixStr,(U32)(pthis->uiTotMemSize)); /* U32 uiHeadRoomSize */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiHeadRoomSize = %u",pcPrtPrefixStr,(U32)(pthis->uiHeadRoomSize)); /* U32 uiMemNodeHdrSize */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiMemNodeHdrSize = %u",pcPrtPrefixStr,(U32)(pthis->uiMemNodeHdrSize)); /* U32 uiMemNodeBodySize */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiMemNodeBodySize = %u",pcPrtPrefixStr,(U32)(pthis->uiMemNodeBodySize)); /* U32 uiMemNodeAllocedCnt */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiMemNodeAllocedCnt = %u",pcPrtPrefixStr,(U32)(pthis->uiMemNodeAllocedCnt)); /* U32 uiMemNodeTotCnt */ FPRINTF(LOG_LEVEL,"_%s : pthis->uiMemNodeTotCnt = %u",pcPrtPrefixStr,(U32)(pthis->uiMemNodeTotCnt)); /* OFFSET offsetHeadRoom */ FPRINTF(LOG_LEVEL,"_%s : pthis->offsetHeadRoom = %ld",pcPrtPrefixStr,(pthis->offsetHeadRoom)); /* OFFSET offsetNodeStart */ FPRINTF(LOG_LEVEL,"_%s : pthis->offsetNodeStart = %ld",pcPrtPrefixStr,(pthis->offsetNodeStart)); /* OFFSET offsetFreeList */ FPRINTF(LOG_LEVEL,"_%s : pthis->offsetFreeList = %ld",pcPrtPrefixStr,(pthis->offsetFreeList)); /* OFFSET offsetNodeEnd */ FPRINTF(LOG_LEVEL,"_%s : pthis->offsetNodeEnd = %ld",pcPrtPrefixStr,(pthis->offsetNodeEnd)); }
/** * Main function that will be run by the scheduler. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param cfg configuration */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { int dst_af; int req_af; struct GNUNET_PeerIdentity peer; struct GNUNET_HashCode sd; const void *addr; struct in_addr v4; struct in6_addr v6; uint8_t protocol; struct GNUNET_TIME_Absolute etime; etime = GNUNET_TIME_relative_to_absolute (duration); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_disconnect, NULL); handle = GNUNET_VPN_connect (cfg); if (NULL == handle) goto error; req_af = AF_UNSPEC; if (ipv4) { if (ipv6) { FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"), "-4", "-6"); goto error; } req_af = AF_INET; } if (ipv6) req_af = AF_INET6; if (NULL == target_ip) { if (NULL == service_name) { FPRINTF (stderr, _("Option `%s' or `%s' is required.\n"), "-i", "-s"); goto error; } if (NULL == peer_id) { FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"), "-p", "-s"); goto error; } if (! (tcp | udp) ) { FPRINTF (stderr, _("Option `%s' or `%s' is required when using option `%s'.\n"), "-t", "-u", "-s"); goto error; } if (tcp & udp) { FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"), "-t", "-u"); goto error; } if (tcp) protocol = IPPROTO_TCP; if (udp) protocol = IPPROTO_UDP; if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, strlen (peer_id), &peer.public_key)) { FPRINTF (stderr, _("`%s' is not a valid peer identifier.\n"), peer_id); goto error; } GNUNET_TUN_service_name_to_hash (service_name, &sd); request = GNUNET_VPN_redirect_to_peer (handle, req_af, protocol, &peer, &sd, etime, &allocation_cb, NULL); } else { if (1 != inet_pton (AF_INET6, target_ip, &v6)) { if (1 != inet_pton (AF_INET, target_ip, &v4)) { FPRINTF (stderr, _("`%s' is not a valid IP address.\n"), target_ip); goto error; } else { dst_af = AF_INET; addr = &v4; } } else { dst_af = AF_INET6; addr = &v6; } request = GNUNET_VPN_redirect_to_ip (handle, req_af, dst_af, addr, etime, &allocation_cb, NULL); } return; error: GNUNET_SCHEDULER_shutdown (); ret = 1; }
int main(int argc, char **argv) { int ret; unsigned part; double timing; double start, end; unsigned row, pos; unsigned ind; /* CSR matrix description */ float *nzval; uint32_t nnz; uint32_t *colind; uint32_t *rowptr; /* Input and Output vectors */ float *vector_in_ptr; float *vector_out_ptr; /* * Parse command-line arguments */ parse_args(argc, argv); /* * Launch StarPU */ ret = starpu_init(NULL); if (ret == -ENODEV) return 77; STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); /* * Create a 3-band sparse matrix as input example */ nnz = 3*size-2; starpu_malloc((void **)&nzval, nnz*sizeof(float)); starpu_malloc((void **)&colind, nnz*sizeof(uint32_t)); starpu_malloc((void **)&rowptr, (size+1)*sizeof(uint32_t)); assert(nzval && colind && rowptr); /* fill the matrix */ for (row = 0, pos = 0; row < size; row++) { rowptr[row] = pos; if (row > 0) { nzval[pos] = 1.0f; colind[pos] = row-1; pos++; } nzval[pos] = 5.0f; colind[pos] = row; pos++; if (row < size - 1) { nzval[pos] = 1.0f; colind[pos] = row+1; pos++; } } STARPU_ASSERT(pos == nnz); rowptr[size] = nnz; /* initiate the 2 vectors */ starpu_malloc((void **)&vector_in_ptr, size*sizeof(float)); starpu_malloc((void **)&vector_out_ptr, size*sizeof(float)); assert(vector_in_ptr && vector_out_ptr); /* fill them */ for (ind = 0; ind < size; ind++) { vector_in_ptr[ind] = 2.0f; vector_out_ptr[ind] = 0.0f; } /* * Register the CSR matrix and the 2 vectors */ starpu_csr_data_register(&sparse_matrix, STARPU_MAIN_RAM, nnz, size, (uintptr_t)nzval, colind, rowptr, 0, sizeof(float)); starpu_vector_data_register(&vector_in, STARPU_MAIN_RAM, (uintptr_t)vector_in_ptr, size, sizeof(float)); starpu_vector_data_register(&vector_out, STARPU_MAIN_RAM, (uintptr_t)vector_out_ptr, size, sizeof(float)); /* * Partition the CSR matrix and the output vector */ csr_f.nchildren = nblocks; vector_f.nchildren = nblocks; starpu_data_partition(sparse_matrix, &csr_f); starpu_data_partition(vector_out, &vector_f); /* * If we use OpenCL, we need to compile the SpMV kernel */ #ifdef STARPU_USE_OPENCL compile_spmv_opencl_kernel(); #endif start = starpu_timing_now(); /* * Create and submit StarPU tasks */ for (part = 0; part < nblocks; part++) { struct starpu_task *task = starpu_task_create(); task->cl = &spmv_cl; task->handles[0] = starpu_data_get_sub_data(sparse_matrix, 1, part); task->handles[1] = vector_in; task->handles[2] = starpu_data_get_sub_data(vector_out, 1, part); ret = starpu_task_submit(task); if (STARPU_UNLIKELY(ret == -ENODEV)) { FPRINTF(stderr, "No worker may execute this task\n"); exit(0); } } starpu_task_wait_for_all(); end = starpu_timing_now(); /* * Unregister the CSR matrix and the output vector */ starpu_data_unpartition(sparse_matrix, STARPU_MAIN_RAM); starpu_data_unpartition(vector_out, STARPU_MAIN_RAM); /* * Unregister data */ starpu_data_unregister(sparse_matrix); starpu_data_unregister(vector_in); starpu_data_unregister(vector_out); /* * Display the result */ for (row = 0; row < STARPU_MIN(size, 16); row++) { FPRINTF(stdout, "%2.2f\t%2.2f\n", vector_in_ptr[row], vector_out_ptr[row]); } starpu_free(nzval); starpu_free(colind); starpu_free(rowptr); starpu_free(vector_in_ptr); starpu_free(vector_out_ptr); /* * Stop StarPU */ starpu_shutdown(); timing = end - start; FPRINTF(stderr, "Computation took (in ms)\n"); FPRINTF(stdout, "%2.2f\n", timing/1000); return 0; }
static size_t notify_ready (void *cls, size_t size, void *buf) { static int n; char *cbuf = buf; struct TestMessage hdr; unsigned int s; unsigned int ret; th = NULL; if (buf == NULL) { test_send_timeout = GNUNET_YES; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout occurred while waiting for transmit_ready for msg %u of %u\n", msg_scheduled, TOTAL_MSGS); if (NULL != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); ok = 42; return 0; } ret = 0; s = get_size (n); GNUNET_assert (size >= s); GNUNET_assert (buf != NULL); GNUNET_assert (n < TOTAL_MSGS); cbuf = buf; do { GNUNET_assert (n < TOTAL_MSGS); hdr.header.size = htons (s); hdr.header.type = htons (MTYPE); hdr.num = htonl (n); msg_sent = n; memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); ret += sizeof (struct TestMessage); memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); ret += s - sizeof (struct TestMessage); #if VERBOSE if (n % 5000 == 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n, s); } #endif n++; s = get_size (n); if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) break; /* sometimes pack buffer full, sometimes not */ } while ((size - ret >= s) && (n < TOTAL_MSGS)); if (n < TOTAL_MSGS) { th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, TIMEOUT_TRANSMIT, ¬ify_ready, NULL); msg_scheduled = n; } else { FPRINTF (stderr, "%s", "\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n"); if (NULL != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); } if (n % 5000 == 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning total message block of size %u\n", ret); } total_bytes += ret; return ret; }
int ADIOI_UFS_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset, int wr, void *handle) { int err=-1, fd_sys; #ifndef NO_AIO int error_code; #ifdef AIO_SUN aio_result_t *result; #else struct aiocb *aiocbp; #endif #endif fd_sys = fd->fd_sys; #ifdef AIO_SUN result = (aio_result_t *) ADIOI_Malloc(sizeof(aio_result_t)); result->aio_return = AIO_INPROGRESS; if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result); if (err == -1) { if (errno == EAGAIN) { /* the man pages say EPROCLIM, but in reality errno is set to EAGAIN! */ /* exceeded the max. no. of outstanding requests. complete all previous async. requests and try again.*/ ADIOI_Complete_async(&error_code); if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result); while (err == -1) { if (errno == EAGAIN) { /* sleep and try again */ sleep(1); if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result); } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_UFS_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_UFS_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } *((aio_result_t **) handle) = result; #endif #ifdef NO_FD_IN_AIOCB /* IBM */ aiocbp = (struct aiocb *) ADIOI_Malloc(sizeof(struct aiocb)); aiocbp->aio_whence = SEEK_SET; aiocbp->aio_offset = offset; aiocbp->aio_buf = buf; aiocbp->aio_nbytes = len; if (wr) err = aio_write(fd_sys, aiocbp); else err = aio_read(fd_sys, aiocbp); if (err == -1) { if (errno == EAGAIN) { /* exceeded the max. no. of outstanding requests. complete all previous async. requests and try again. */ ADIOI_Complete_async(&error_code); if (wr) err = aio_write(fd_sys, aiocbp); else err = aio_read(fd_sys, aiocbp); while (err == -1) { if (errno == EAGAIN) { /* sleep and try again */ sleep(1); if (wr) err = aio_write(fd_sys, aiocbp); else err = aio_read(fd_sys, aiocbp); } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_UFS_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_UFS_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } *((struct aiocb **) handle) = aiocbp; #elif (!defined(NO_AIO) && !defined(AIO_SUN)) /* DEC, SGI IRIX 5 and 6 */ aiocbp = (struct aiocb *) ADIOI_Calloc(sizeof(struct aiocb), 1); aiocbp->aio_fildes = fd_sys; aiocbp->aio_offset = offset; aiocbp->aio_buf = buf; aiocbp->aio_nbytes = len; #ifdef AIO_PRIORITY_DEFAULT /* DEC */ aiocbp->aio_reqprio = AIO_PRIO_DFL; /* not needed in DEC Unix 4.0 */ aiocbp->aio_sigevent.sigev_signo = 0; #else aiocbp->aio_reqprio = 0; #endif #ifdef AIO_SIGNOTIFY_NONE /* SGI IRIX 6 */ aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE; #else aiocbp->aio_sigevent.sigev_signo = 0; #endif if (wr) err = aio_write(aiocbp); else err = aio_read(aiocbp); if (err == -1) { if (errno == EAGAIN) { /* exceeded the max. no. of outstanding requests. complete all previous async. requests and try again. */ ADIOI_Complete_async(&error_code); if (wr) err = aio_write(aiocbp); else err = aio_read(aiocbp); while (err == -1) { if (errno == EAGAIN) { /* sleep and try again */ sleep(1); if (wr) err = aio_write(aiocbp); else err = aio_read(aiocbp); } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_UFS_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_UFS_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } *((struct aiocb **) handle) = aiocbp; #endif return err; }
int main(int argc, char *argv[], char *envp[]) { int i; struct line_list l, options, request_list; char msg[SMALLBUFFER], *s; Init_line_list(&l); Init_line_list(&options); Init_line_list(&request_list); /* set signal handlers */ (void) plp_signal (SIGHUP, cleanup_HUP); (void) plp_signal (SIGINT, cleanup_INT); (void) plp_signal (SIGQUIT, cleanup_QUIT); (void) plp_signal (SIGTERM, cleanup_TERM); (void) signal(SIGCHLD, SIG_DFL); (void) signal(SIGPIPE, SIG_IGN); /* * set up the user state */ Status_line_count = 1; #ifndef NODEBUG Debug = 0; #endif Displayformat = REQ_DLONG; Initialize(argc, argv, envp, 'T' ); Setup_configuration(); Get_parms(argc, argv ); /* scan input args */ if( A_flag && !getenv( "AUTH" ) ){ FPRINTF(STDERR,"lpstat: requested authenticated transfer (-A) and AUTH environment variable not set"); usage(); } /* set up configuration */ Get_printer(); Fix_Rm_Rp_info(0,0); Get_all_printcap_entries(); /* check on printing scheduler is running */ if( t_flag ){ All_printers = 1; r_flag = d_flag = p_flag = o_flag = 1; s_flag = 0; } if( s_flag ){ /* a_flag = 1; */ r_flag = 1; d_flag = 1; v_flag = 1; All_printers = 1; } if( All_printers ){ Merge_line_list( &request_list, &All_line_list,0,0,0); } Merge_line_list( &request_list, &Printer_list,0,0,0); Check_max(&options,2); if( options.count ){ for( i = options.count; i > 0 ; --i ){ options.list[i] = options.list[i-1]; } options.list[0] = safestrdup(Logname_DYN,__FILE__,__LINE__); ++options.count; } options.list[options.count] = 0; if( Found_flag == 0 ){ if( request_list.count == 0 ){ Split(&request_list,Printer_DYN,", ",1,0,1,1,0,0); } o_flag = 1; flag_count = 1; } #ifdef ORIGINAL_DEBUG//[email protected] if(DEBUGL1)Dump_line_list("lpstat - printer request list", &request_list); if(DEBUGL1)Dump_line_list("lpstat - options", &options); #endif if( r_flag ){ Write_fd_str(1,"scheduler is running\n"); } if( d_flag ){ if( Printer_DYN == 0 ){ Write_fd_str(1,"no system default destination\n"); } else { SNPRINTF(msg,sizeof(msg)) "system default destination: %s\n", Printer_DYN); Write_fd_str(1,msg); } } if( v_flag ){ for( i = 0; i < request_list.count; ++i ){ Set_DYN(&Printer_DYN,request_list.list[i] ); Fix_Rm_Rp_info(0,0); SNPRINTF(msg,sizeof(msg)) "system for %s: %s\n", Printer_DYN, RemoteHost_DYN); Write_fd_str(1,msg); } } /* see if additional status required */ Free_line_list( &Printer_list ); for( i = 0; i < request_list.count; ++i ){ s = request_list.list[i]; Set_DYN(&Printer_DYN,s ); Show_status(options.list, 0); } Free_line_list( &Printer_list ); if( flag_count ){ for( i = 0; i < request_list.count; ++i ){ s = request_list.list[i]; Set_DYN(&Printer_DYN,s ); Show_status(options.list, 1); } } DEBUG1("lpstat: done"); Remove_tempfiles(); DEBUG1("lpstat: tempfiles removed"); Errorcode = 0; DEBUG1("lpstat: cleaning up"); return(0); }
int VCPU::print_state(FILE * o) const { int len = 0; if ( ! this->is_online() ) return len + FPUTS("\tVCPU Offline\n\n", o); if ( this->flags & CPU_PV_COMPAT ) return len + this->print_state_compat(o); if ( this->flags & CPU_GP_REGS ) { len += FPRINTF(o, "\tRIP: %04x:[<%016"PRIx64">] Ring %d\n", this->regs.cs, this->regs.rip, this->regs.cs & 0x3); len += FPRINTF(o, "\tRFLAGS: %016"PRIx64" ", this->regs.rflags); len += print_rflags(o, this->regs.rflags); len += FPUTS("\n\n", o); len += FPRINTF(o, "\trax: %016"PRIx64" rbx: %016"PRIx64" rcx: %016"PRIx64"\n", this->regs.rax, this->regs.rbx, this->regs.rcx); len += FPRINTF(o, "\trdx: %016"PRIx64" rsi: %016"PRIx64" rdi: %016"PRIx64"\n", this->regs.rdx, this->regs.rsi, this->regs.rdi); len += FPRINTF(o, "\trbp: %016"PRIx64" rsp: %016"PRIx64" r8: %016"PRIx64"\n", this->regs.rbp, this->regs.rsp, this->regs.r8); len += FPRINTF(o, "\tr9: %016"PRIx64" r10: %016"PRIx64" r11: %016"PRIx64"\n", this->regs.r9, this->regs.r10, this->regs.r11); len += FPRINTF(o, "\tr12: %016"PRIx64" r13: %016"PRIx64" r14: %016"PRIx64"\n", this->regs.r12, this->regs.r13, this->regs.r14); len += FPRINTF(o, "\tr15: %016"PRIx64"\n", this->regs.r15); } if ( this->flags & CPU_CR_REGS ) { len += FPUTS("\n", o); len += FPRINTF(o, "\tcr3: %016"PRIx64"\n", this->regs.cr3); } if ( this->flags & CPU_GP_REGS ) { len += FPUTS("\n", o); if ( this->flags & CPU_SEG_REGS ) len += FPRINTF(o, "\tds: %04"PRIx16" es: %04"PRIx16" " "fs: %04"PRIx16" gs: %04"PRIx16" " "ss: %04"PRIx16" cs: %04"PRIx16"\n", this->regs.ds, this->regs.es, this->regs.fs, this->regs.gs, this->regs.ss, this->regs.cs); else len += FPRINTF(o, "\tss: %04"PRIx16" cs: %04"PRIx16"\n", this->regs.ss, this->regs.cs); } len += FPUTS("\n", o); len += FPRINTF(o, "\tPause Count: %"PRId32", Flags: 0x%"PRIx32" ", this->pause_count, this->pause_flags); len += print_pause_flags(o, this->pause_flags); len += FPUTS("\n", o); switch ( this->runstate ) { case RST_NONE: len += FPRINTF(o, "\tNot running: Last run on PCPU%"PRIu32"\n", this->processor); break; case RST_RUNNING: len += FPRINTF(o, "\tCurrently running on PCPU%"PRIu32"\n", this->processor); break; case RST_CTX_SWITCH: len += FPUTS("\tBeing Context Switched: State unreliable\n", o); break; default: len += FPUTS("\tUnknown runstate\n", o); break; } len += FPRINTF(o, "\tStruct vcpu at %016"PRIx64"\n", this->vcpu_ptr); len += FPUTS("\n", o); if ( this->flags & CPU_GP_REGS && this->flags & CPU_CR_REGS && ( this->paging_support == VCPU::PAGING_NONE || this->paging_support == VCPU::PAGING_SHADOW ) ) { len += FPRINTF(o, "\tStack at %16"PRIx64":", this->regs.rsp); len += print_64bit_stack(o, *this->dompt, this->regs.rsp); len += FPUTS("\n\tCode:\n", o); len += print_code(o, *this->dompt, this->regs.rip); len += FPUTS("\n\tCall Trace:\n", o); if ( this->domid == 0 ) { vaddr_t sp = this->regs.rsp; vaddr_t top = (this->regs.rsp | (PAGE_SIZE-1))+1; uint64_t val; len += host.dom0_symtab.print_symbol64(o, this->regs.rip, true); try { while ( sp < top ) { memory.read64_vaddr(*this->dompt, sp, val); len += host.dom0_symtab.print_symbol64(o, val); sp += 8; } } catch ( const CommonError & e ) { e.log(); } } else len += FPUTS("\t No symbol table for domain\n", o); len += FPUTS("\n", o); } return len; }
void ADIOI_PFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code) { MPI_Datatype copy_etype, copy_filetype; int combiner, i, j, k, filetype_is_contig, err; ADIOI_Flatlist_node *flat_file; int iomod, np_total, np_comm; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_PFS_FCNTL"; #endif switch(flag) { case ADIO_FCNTL_SET_VIEW: /* free copies of old etypes and filetypes and delete flattened version of filetype if necessary */ MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner); if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype)); ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig); if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype); MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner); if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype)); /* set new info */ ADIO_SetInfo(fd, fcntl_struct->info, &err); /* set new etypes and filetypes */ MPI_Type_get_envelope(fcntl_struct->etype, &i, &j, &k, &combiner); if (combiner == MPI_COMBINER_NAMED) fd->etype = fcntl_struct->etype; else { MPI_Type_contiguous(1, fcntl_struct->etype, ©_etype); MPI_Type_commit(©_etype); fd->etype = copy_etype; } MPI_Type_get_envelope(fcntl_struct->filetype, &i, &j, &k, &combiner); if (combiner == MPI_COMBINER_NAMED) fd->filetype = fcntl_struct->filetype; else { MPI_Type_contiguous(1, fcntl_struct->filetype, ©_filetype); MPI_Type_commit(©_filetype); fd->filetype = copy_filetype; ADIOI_Flatten_datatype(fd->filetype); /* this function will not flatten the filetype if it turns out to be all contiguous. */ } MPI_Type_size(fd->etype, &(fd->etype_size)); fd->disp = fcntl_struct->disp; /* reset MPI-IO file pointer to point to the first byte that can be accessed in this view. */ ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig); if (filetype_is_contig) fd->fp_ind = fcntl_struct->disp; else { flat_file = ADIOI_Flatlist; while (flat_file->type != fd->filetype) flat_file = flat_file->next; for (i=0; i<flat_file->count; i++) { if (flat_file->blocklens[i]) { fd->fp_ind = fcntl_struct->disp + flat_file->indices[i]; break; } } } *error_code = MPI_SUCCESS; break; case ADIO_FCNTL_GET_FSIZE: if (!(fd->atomicity)) { /* in M_ASYNC mode, all processes are not aware of changes in file size (although the manual says otherwise). Therefore, temporarily change to M_UNIX and then change back to M_ASYNC.*/ MPI_Comm_size(MPI_COMM_WORLD, &np_total); MPI_Comm_size(fd->comm, &np_comm); if (np_total == np_comm) { err = _setiomode(fd->fd_sys, M_UNIX); err = _setiomode(fd->fd_sys, M_ASYNC); } /* else it is M_UNIX anyway, so no problem */ } fcntl_struct->fsize = lseek(fd->fd_sys, 0, SEEK_END); if (fd->fp_sys_posn != -1) lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET); *error_code = MPI_SUCCESS; break; case ADIO_FCNTL_SET_DISKSPACE: err = _lsize(fd->fd_sys, fcntl_struct->diskspace, SEEK_SET); #ifdef PRINT_ERR_MSG *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS ; #else if (err == -1) { *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); } else *error_code = MPI_SUCCESS; #endif break; case ADIO_FCNTL_SET_IOMODE: /* for implementing PFS I/O modes. will not occur in MPI-IO implementation.*/ if (fd->iomode != fcntl_struct->iomode) { fd->iomode = fcntl_struct->iomode; setiomode(fd->fd_sys, iomode); /* for some unknown reason, the compiler gives a warning here */ } *error_code = MPI_SUCCESS; break; case ADIO_FCNTL_SET_ATOMICITY: MPI_Comm_size(MPI_COMM_WORLD, &np_total); MPI_Comm_size(fd->comm, &np_comm); if (np_total == np_comm) { iomod = (fcntl_struct->atomicity == 0) ? M_ASYNC : M_UNIX; err = _setiomode(fd->fd_sys, iomod); } /* else can't do anything because setiomode is global. but the file will have been opened with M_UNIX anyway, because gopen is also global. */ fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1; #ifdef PRINT_ERR_MSG *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS ; #else if (err == -1) { *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); } else *error_code = MPI_SUCCESS; #endif break; default: FPRINTF(stderr, "Unknown flag passed to ADIOI_PFS_Fcntl\n"); MPI_Abort(MPI_COMM_WORLD, 1); } }
void ADIOI_HFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code) { int i, ntimes, err; ADIO_Offset curr_fsize, alloc_size, size, len, done; ADIO_Status status; char *buf; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_HFS_FCNTL"; #endif switch(flag) { case ADIO_FCNTL_GET_FSIZE: fcntl_struct->fsize = lseek64(fd->fd_sys, 0, SEEK_END); #ifdef HPUX if (fd->fp_sys_posn != -1) lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET); /* not required in SPPUX since there we use pread/pwrite */ #endif if (fcntl_struct->fsize == -1) { #ifdef MPICH2 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else /* MPICH-1 */ *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; break; case ADIO_FCNTL_SET_DISKSPACE: /* will be called by one process only */ #ifdef HPUX err = prealloc64(fd->fd_sys, fcntl_struct->diskspace); /* prealloc64 works only if file is of zero length */ if (err && (errno != ENOTEMPTY)) { #ifdef MPICH2 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif return; } if (err && (errno == ENOTEMPTY)) { #endif #ifdef SPPUX /* SPPUX has no prealloc64. therefore, use prealloc if size < (2GB - 1), otherwise use long method. */ if (fcntl_struct->diskspace <= 2147483647) { err = prealloc(fd->fd_sys, (off_t) fcntl_struct->diskspace); if (err && (errno != ENOTEMPTY)) { #ifdef MPICH2 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif return; } } if ((fcntl_struct->diskspace > 2147483647) || (err && (errno == ENOTEMPTY))) { #endif ADIOI_GEN_Prealloc(fd,fcntl_struct->diskspace, error_code); } ADIOI_Free(buf); #ifdef HPUX if (fd->fp_sys_posn != -1) lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET); /* not required in SPPUX since there we use pread/pwrite */ #endif } *error_code = MPI_SUCCESS; break; case ADIO_FCNTL_SET_ATOMICITY: fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1; *error_code = MPI_SUCCESS; break; default: FPRINTF(stderr, "Unknown flag passed to ADIOI_HFS_Fcntl\n"); MPI_Abort(MPI_COMM_WORLD, 1); } }
static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) { switch (event->status) { case GNUNET_FS_STATUS_SEARCH_RESULT: if (sks_search == event->value.search.sc) { if (!GNUNET_FS_uri_test_equal (sks_expect_uri, event->value.search.specifics.result.uri)) { FPRINTF (stderr, "%s", "Wrong result for sks search!\n"); err = 1; } /* give system 1ms to initiate update search! */ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, &abort_sks_search_task, NULL); } else if (ksk_search == event->value.search.sc) { if (!GNUNET_FS_uri_test_equal (ksk_expect_uri, event->value.search.specifics.result.uri)) { FPRINTF (stderr, "%s", "Wrong result for ksk search!\n"); err = 1; } GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); } else { FPRINTF (stderr, "%s", "Unexpected search result received!\n"); GNUNET_break (0); } break; case GNUNET_FS_STATUS_SEARCH_ERROR: FPRINTF (stderr, "Error searching file: %s\n", event->value.search.specifics.error.message); if (sks_search == event->value.search.sc) GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); else if (ksk_search == event->value.search.sc) GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); else GNUNET_break (0); break; case GNUNET_FS_STATUS_SEARCH_START: GNUNET_assert ((NULL == event->value.search.cctx) || (0 == strcmp ("sks_search", event->value.search.cctx)) || (0 == strcmp ("ksk_search", event->value.search.cctx))); if (NULL == event->value.search.cctx) { GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx)); update_started = GNUNET_YES; } GNUNET_assert (1 == event->value.search.anonymity); break; case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: return NULL; case GNUNET_FS_STATUS_SEARCH_STOPPED: return NULL; default: FPRINTF (stderr, "Unexpected event: %d\n", event->status); break; } return event->value.search.cctx; }
/* ADIOI_cb_config_list_parse() - parse the cb_config_list and build the * ranklist * * Parameters: * (pretty self explanatory) * * Returns number of ranks allocated in parsing, -1 on error. */ int ADIOI_cb_config_list_parse(char *config_list, ADIO_cb_name_array array, int ranklist[], int cb_nodes) { int token, max_procs, cur_rank = 0, nr_procnames; char *cur_procname, *cur_procname_p, **procnames; char *used_procnames; nr_procnames = array->namect; procnames = array->names; /* nothing big goes on the stack */ /* we use info val here and for yylval because we know the string * cannot be any bigger than this. */ cur_procname = ADIOI_Malloc((MPI_MAX_INFO_VAL+1) * sizeof(char)); if (cur_procname == NULL) { return -1; } yylval = ADIOI_Malloc((MPI_MAX_INFO_VAL+1) * sizeof(char)); if (yylval == NULL) { ADIOI_Free(cur_procname); return -1; } token_ptr = config_list; /* right away let's make sure cb_nodes isn't too big */ if (cb_nodes > nr_procnames) cb_nodes = nr_procnames; /* used_procnames is used as a mask so that we don't have to destroy * our procnames array */ used_procnames = ADIOI_Malloc(array->namect * sizeof(char)); if (used_procnames == NULL) { ADIOI_Free(cur_procname); ADIOI_Free(yylval); yylval = NULL; return -1; } memset(used_procnames, 0, array->namect); /* optimization for "*:*"; arguably this could be done before we * build the list of processor names...but that would make things * messy. */ if (strcmp(config_list, "*:*") == 0) { for (cur_rank = 0; cur_rank < cb_nodes; cur_rank++) { ranklist[cur_rank] = cur_rank; } ADIOI_Free(cur_procname); ADIOI_Free(yylval); yylval = NULL; ADIOI_Free(used_procnames); return cb_nodes; } while (cur_rank < cb_nodes) { token = cb_config_list_lex(); if (token == AGG_EOS) { ADIOI_Free(cur_procname); ADIOI_Free(yylval); yylval = NULL; ADIOI_Free(used_procnames); return cur_rank; } if (token != AGG_WILDCARD && token != AGG_STRING) { /* maybe ignore and try to keep going? */ FPRINTF(stderr, "error parsing config list\n"); ADIOI_Free(cur_procname); ADIOI_Free(yylval); yylval = NULL; ADIOI_Free(used_procnames); return cur_rank; } if (token == AGG_WILDCARD) { cur_procname_p = NULL; } else { /* AGG_STRING is the only remaining case */ /* save procname (for now) */ ADIOI_Strncpy(cur_procname, yylval, MPI_MAX_INFO_VAL+1); cur_procname_p = cur_procname; } /* after we have saved the current procname, we can grab max_procs */ max_procs = get_max_procs(cb_nodes); #ifdef CB_CONFIG_LIST_DEBUG if (token == AGG_WILDCARD) { FPRINTF(stderr, "looking for *:%d\n", max_procs); } else { FPRINTF(stderr, "looking for %s:%d\n", cur_procname, max_procs); } #endif /* do the matching for this piece of the cb_config_list */ match_procs(cur_procname_p, max_procs, procnames, used_procnames, nr_procnames, ranklist, cb_nodes, &cur_rank); } ADIOI_Free(cur_procname); ADIOI_Free(yylval); yylval = NULL; ADIOI_Free(used_procnames); return cur_rank; }
/*@ MPI_File_read - Read using individual file pointer Input Parameters: . fh - file handle (handle) . count - number of elements in buffer (nonnegative integer) . datatype - datatype of each buffer element (handle) Output Parameters: . buf - initial address of buffer (choice) . status - status object (Status) .N fortran @*/ int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status) { int error_code, bufsize, buftype_is_contig, filetype_is_contig; #ifndef PRINT_ERR_MSG static char myname[] = "MPI_FILE_READ"; #endif int datatype_size; ADIO_Offset off; #ifdef MPI_hpux int fl_xmpi; HPMP_IO_START(fl_xmpi, BLKMPIFILEREAD, TRDTBLOCK, fh, datatype, count); #endif /* MPI_hpux */ #ifdef PRINT_ERR_MSG if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE)) { FPRINTF(stderr, "MPI_File_read: Invalid file handle\n"); MPI_Abort(MPI_COMM_WORLD, 1); } #else ADIOI_TEST_FILE_HANDLE(fh, myname); #endif if (count < 0) { #ifdef PRINT_ERR_MSG FPRINTF(stderr, "MPI_File_read: Invalid count argument\n"); MPI_Abort(MPI_COMM_WORLD, 1); #else error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_COUNT_ARG, myname, (char *) 0, (char *) 0); return ADIOI_Error(fh, error_code, myname); #endif } if (datatype == MPI_DATATYPE_NULL) { #ifdef PRINT_ERR_MSG FPRINTF(stderr, "MPI_File_read: Invalid datatype\n"); MPI_Abort(MPI_COMM_WORLD, 1); #else error_code = MPIR_Err_setmsg(MPI_ERR_TYPE, MPIR_ERR_TYPE_NULL, myname, (char *) 0, (char *) 0); return ADIOI_Error(fh, error_code, myname); #endif } MPI_Type_size(datatype, &datatype_size); if (count*datatype_size == 0) { #ifdef MPI_hpux HPMP_IO_END(fl_xmpi, fh, datatype, count); #endif /* MPI_hpux */ return MPI_SUCCESS; } if ((count*datatype_size) % fh->etype_size != 0) { #ifdef PRINT_ERR_MSG FPRINTF(stderr, "MPI_File_read: Only an integral number of etypes can be accessed\n"); MPI_Abort(MPI_COMM_WORLD, 1); #else error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_ETYPE_FRACTIONAL, myname, (char *) 0, (char *) 0); return ADIOI_Error(fh, error_code, myname); #endif } if (fh->access_mode & MPI_MODE_WRONLY) { #ifdef PRINT_ERR_MSG FPRINTF(stderr, "MPI_File_read: Can't read from a file opened with MPI_MODE_WRONLY\n"); MPI_Abort(MPI_COMM_WORLD, 1); #else error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION, MPIR_ERR_MODE_WRONLY, myname, (char *) 0, (char *) 0); return ADIOI_Error(fh, error_code, myname); #endif } if (fh->access_mode & MPI_MODE_SEQUENTIAL) { #ifdef PRINT_ERR_MSG FPRINTF(stderr, "MPI_File_read: Can't use this function because file was opened with MPI_MODE_SEQUENTIAL\n"); MPI_Abort(MPI_COMM_WORLD, 1); #else error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION, MPIR_ERR_AMODE_SEQ, myname, (char *) 0, (char *) 0); return ADIOI_Error(fh, error_code, myname); #endif } ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); ADIOI_Datatype_iscontig(fh->filetype, &filetype_is_contig); /* contiguous or strided? */ if (buftype_is_contig && filetype_is_contig) { bufsize = datatype_size * count; /* if atomic mode requested, lock (exclusive) the region, because there could be a concurrent noncontiguous request. Locking doesn't work on PIOFS and PVFS, and on NFS it is done in the ADIO_ReadContig.*/ off = fh->fp_ind; if ((fh->atomicity) && (fh->file_system != ADIO_PIOFS) && (fh->file_system != ADIO_NFS) && (fh->file_system != ADIO_PVFS)) ADIOI_WRITE_LOCK(fh, off, SEEK_SET, bufsize); ADIO_ReadContig(fh, buf, count, datatype, ADIO_INDIVIDUAL, 0, status, &error_code); if ((fh->atomicity) && (fh->file_system != ADIO_PIOFS) && (fh->file_system != ADIO_NFS) && (fh->file_system != ADIO_PVFS)) ADIOI_UNLOCK(fh, off, SEEK_SET, bufsize); } else ADIO_ReadStrided(fh, buf, count, datatype, ADIO_INDIVIDUAL, 0, status, &error_code); /* For strided and atomic mode, locking is done in ADIO_ReadStrided */ #ifdef MPI_hpux HPMP_IO_END(fl_xmpi, fh, datatype, count); #endif /* MPI_hpux */ return error_code; }
int open_outfile() /* return 1 if fail */ { #ifdef DOS_NT_OS2 if (stat(filename, &statbuf) == 0 && !(statbuf.st_mode & S_IWRITE)) chmod(filename, S_IREAD | S_IWRITE); #endif #ifdef UNIX if (stat(filename, &statbuf) == 0 && unlink(filename) < 0) { FPRINTF(stderr, LoadFarString(CannotDeleteOldFile), filename); return 1; } #endif #ifdef TOPS20 char *tfilnam; if ((tfilnam = (char *)malloc(2*strlen(filename)+1)) == (char *)NULL) return 1; strcpy(tfilnam, filename); upper(tfilnam); enquote(tfilnam); if ((outfile = fopen(tfilnam, FOPW)) == (FILE *)NULL) { FPRINTF(stderr, LoadFarString(CannotCreateFile), tfilnam); free(tfilnam); return 1; } free(tfilnam); #else #ifdef MTS if (aflag) outfile = fopen(filename, FOPWT); else outfile = fopen(filename, FOPW); if (outfile == (FILE *)NULL) { FPRINTF(stderr, LoadFarString(CannotCreateFile), filename); return 1; } #else if ((outfile = fopen(filename, FOPW)) == (FILE *)NULL) { FPRINTF(stderr, LoadFarString(CannotCreateFile), filename); return 1; } #endif #endif #if 0 /* this SUCKS! on Ultrix, it must be writing a byte at a time... */ setbuf(outfile, (char *)NULL); /* make output unbuffered */ #endif #ifdef USE_FWRITE #ifdef DOS_NT_OS2 /* 16-bit MSC: buffer size must be strictly LESS than 32K (WSIZE): bogus */ setbuf(outfile, (char *)NULL); /* make output unbuffered */ #else /* !DOS_NT_OS2 */ #ifdef _IOFBF /* make output fully buffered (works just about like write()) */ setvbuf(outfile, (char *)slide, _IOFBF, WSIZE); #else setbuf(outfile, (char *)slide); #endif #endif /* ?DOS_NT_OS2 */ #endif /* USE_FWRITE */ return 0; } /* end function open_outfile() */
void dedtype(RING * gbl, char *name, int inlist, int binary, int stripped, int isdir) { int had_eof; int c; int count, /* ...and repeat-count */ y, /* current line-in-screen */ shift = COLS / 4, /* amount of left/right shift */ done = FALSE, shown = FALSE, infile = -1; /* # of lines processed */ OFF_T skip = 0; tabstop = 8; Shift = 0; UsePattern = FALSE; OptBinary = binary; OptStripped = stripped; if (isdir && !OptBinary) { DIR *dp; DirentT *de; char bfr[MAXPATHLEN]; # define INO_FMT "%5lu" if ((InFile = tmpfile()) == 0) { warn(gbl, "tmp-file"); return; } if ((dp = opendir(name)) != 0) { while ((de = readdir(dp)) != NULL) { (void) ded2string(gbl, bfr, (int) NAMLEN(de), de->d_name, FALSE); FPRINTF(InFile, INO_FMT, (unsigned long) de->d_ino); FPRINTF(InFile, " %s\n", bfr); } (void) closedir(dp); rewind(InFile); } else { warn(gbl, "opendir"); FCLOSE(InFile); return; } } else InFile = fopen(name, "r"); in_dedtype = TRUE; /* disable clearing of workspace via A/a cmd */ if (InFile) { int jump = 0; dlog_comment("type \"%s\" (%s %s)\n", name, OptBinary ? "binary" : "text", isdir ? "directory" : "file"); to_work(gbl, FALSE); dyn_init(&my_text, BUFSIZ); dyn_init(&my_over, BUFSIZ); max_lines = -1; MarkLine(&infile); while (!done) { if (jump) { #if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG) /* * If we're doing single-line scrolling past * the point we've read in the file, try to * cache pointers so that the scrolling logic * will go more smoothly. */ if (jump > 0 && jump < NumP(1) && infile + NumP(1) >= max_lines) { int line = infile; (void) StartPage(&line, TRUE, &had_eof); } #endif (void) JumpBackwards(&infile, jump); jump = 0; } markC(gbl, TRUE); y = StartPage(&infile, (int) skip, &had_eof); if (skip && !was_interrupted) { if (feof(InFile)) { skip = 0; jump = NumP(1); } else { IgnorePage(infile); skip--; } continue; } if (had_eof) { int blank; infile = TopOfPage(infile, &blank); (void) JumpToLine(infile); y = StartPage(&infile, 0, &had_eof); } shown |= FinishPage(gbl, inlist, infile, y); jump = NumP(1); reset_catcher(); switch (c = dlog_char(gbl, &count, 1)) { case CTL('K'): deddump(gbl); break; case 'w': retouch(gbl, 0); break; case '\t': if (OptBinary) { beep(); } else { tabstop = (count <= 1) ? (tabstop == 8 ? 4 : 8) : count; } break; case 'q': done = TRUE; break; case KEY_HOME: case '^': jump = infile; break; case KEY_END: case '$': infile = max_lines; skip = MaxP(); break; case KEY_PPAGE: case '\b': case 'b': if (AtTop(infile)) { beep(); } else { jump += NumP(count); } break; case KEY_NPAGE: case '\n': case ' ': case 'f': jump = 0; skip = count - 1; break; case '<': case CTL('L'): LeftOrRight(-shift * count); break; case '>': case CTL('R'): LeftOrRight(shift * count); break; case KEY_LEFT: case 'h': LeftOrRight(-count); break; case KEY_DOWN: case 'j': jump = NumP(1) - count; if ((infile - jump) > max_lines) { skip = (-jump + NumP(1) - 1) / NumP(1); jump = 0; } break; case KEY_UP: case 'k': if (AtTop(infile)) { beep(); } else { jump += count; } break; case KEY_RIGHT: case 'l': LeftOrRight(count); break; /* move work-area marker */ case 'A': count = -count; jump -= count; /*FALLTHRU */ case 'a': markset(gbl, (unsigned) (mark_W + count)); break; case '/': case '?': case 'n': case 'N': FindPattern(gbl, &infile, c); break; default: beep(); } } FCLOSE(InFile); if (shown) (void) reshow(gbl, (unsigned) inlist); showMARK(gbl->Xbase); showC(gbl); } else warn(gbl, name); in_dedtype = FALSE; }
// Called when terminal type is selected. // This procedure should parse options on the command line. // A list of the currently selected options should be stored in term_options[], // in a form suitable for use with the set term command. // term_options[] is used by the save command. Use options_null() if no options are available." * void qt_options() { char *s = NULL; QString fontSettings; bool duplication = false; bool set_enhanced = false, set_font = false; bool set_persist = false, set_number = false; bool set_raise = false, set_ctrl = false; bool set_title = false, set_close = false; bool set_size = false; bool set_widget = false; bool set_dash = false; if (term_interlock != NULL && term_interlock != (void *)qt_init) { term = NULL; int_error(NO_CARET, "The qt terminal cannot be used in a wxt session"); } #define SETCHECKDUP(x) { c_token++; if (x) duplication = true; x = true; } while (!END_OF_COMMAND) { FPRINTF((stderr, "processing token\n")); switch (lookup_table(&qt_opts[0], c_token)) { case QT_WIDGET: SETCHECKDUP(set_widget); if (!(s = try_to_get_string())) int_error(c_token, "widget: expecting string"); if (*s) qt_optionWidget = QString(s); free(s); break; case QT_FONT: SETCHECKDUP(set_font); if (!(s = try_to_get_string())) int_error(c_token, "font: expecting string"); if (*s) { fontSettings = QString(s); QStringList list = fontSettings.split(','); if ((list.size() > 0) && !list[0].isEmpty()) qt_optionFontName = list[0]; if ((list.size() > 1) && (list[1].toInt() > 0)) qt_optionFontSize = list[1].toInt(); } free(s); break; case QT_ENHANCED: SETCHECKDUP(set_enhanced); qt_optionEnhanced = true; term->flags |= TERM_ENHANCED_TEXT; break; case QT_NOENHANCED: SETCHECKDUP(set_enhanced); qt_optionEnhanced = false; term->flags &= ~TERM_ENHANCED_TEXT; break; case QT_SIZE: SETCHECKDUP(set_size); if (END_OF_COMMAND) int_error(c_token, "size requires 'width,heigth'"); qt_optionWidth = real_expression(); if (!equals(c_token++, ",")) int_error(c_token, "size requires 'width,heigth'"); qt_optionHeight = real_expression(); if (qt_optionWidth < 1 || qt_optionHeight < 1) int_error(c_token, "size is out of range"); break; case QT_PERSIST: SETCHECKDUP(set_persist); qt_optionPersist = true; break; case QT_NOPERSIST: SETCHECKDUP(set_persist); qt_optionPersist = false; break; case QT_RAISE: SETCHECKDUP(set_raise); qt_optionRaise = true; break; case QT_NORAISE: SETCHECKDUP(set_raise); qt_optionRaise = false; break; case QT_CTRL: SETCHECKDUP(set_ctrl); qt_optionCtrl = true; break; case QT_NOCTRL: SETCHECKDUP(set_ctrl); qt_optionCtrl = false; break; case QT_TITLE: SETCHECKDUP(set_title); if (!(s = try_to_get_string())) int_error(c_token, "title: expecting string"); if (*s) qt_optionTitle = qt_codec->toUnicode(s); free(s); break; case QT_CLOSE: SETCHECKDUP(set_close); break; case QT_DASH: SETCHECKDUP(set_dash); qt_optionDash = true; break; case QT_SOLID: SETCHECKDUP(set_dash); qt_optionDash = false; break; case QT_OTHER: default: qt_optionWindowId = int_expression(); qt_optionWidget = ""; if (set_number) duplication = true; set_number = true; break; } if (duplication) int_error(c_token-1, "Duplicated or contradicting arguments in qt term options."); } // Save options back into options string in normalized format QString termOptions = QString::number(qt_optionWindowId); /* Initialize user-visible font setting */ fontSettings = qt_optionFontName + "," + QString::number(qt_optionFontSize); if (set_title) { termOptions += " title \"" + qt_optionTitle + '"'; if (qt_initialized) qt_out << GETitle << qt_optionTitle; } if (set_size) { termOptions += " size " + QString::number(qt_optionWidth) + ", " + QString::number(qt_optionHeight); qt_setSize = true; qt_setWidth = qt_optionWidth; qt_setHeight = qt_optionHeight; } if (set_enhanced) termOptions += qt_optionEnhanced ? " enhanced" : " noenhanced"; termOptions += " font \"" + fontSettings + '"'; if (set_dash) termOptions += qt_optionDash ? " dashed" : " solid"; if (set_widget) termOptions += " widget \"" + qt_optionWidget + '"'; if (set_persist) termOptions += qt_optionPersist ? " persist" : " nopersist"; if (set_raise) termOptions += qt_optionRaise ? " raise" : " noraise"; if (set_ctrl) termOptions += qt_optionCtrl ? " ctrl" : " noctrl"; if (set_close && qt_initialized) qt_out << GECloseWindow << qt_optionWindowId; /// @bug change Utf8 to local encoding strncpy(term_options, termOptions.toUtf8().data(), MAX_LINE_LEN); }
int main(int argc, char **argv) { int overall_errors = 0; char buf[BIG_ENOUGH]; /* test an empty cdr channel */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST AN EMPTY CDR\n"); initial_put(STDCDR_EMPTY); MSG_OK(STDCDR_EMPTY, "01234"); MSG_OK(STDCDR_EMPTY, "567"); MSG_OK(STDCDR_EMPTY, "89abcdefg"); MSG_OK(STDCDR_EMPTY, "zyx"); MSG_OK(STDCDR_EMPTY, "this is the end"); MSG_ERR(STDCDR_EMPTY, "this write should fail"); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test stubbed cdr channel */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST STUBBED CDR\n"); eofpos = MANIFEST->channels[OPEN(STDCDR_STUBBED)].size; FPRINTF(STDERR, "%s size = %lld\n", MANIFEST->channels[OPEN(STDCDR_STUBBED)].name, eofpos); MSG_OK(STDCDR_STUBBED, "01234"); MSG_OK(STDCDR_STUBBED, "567"); MSG_OK(STDCDR_STUBBED, "89abcdefg"); MSG_OK(STDCDR_STUBBED, "zyx"); MSG_OK(STDCDR_STUBBED, "this is the end"); MSG_ERR(STDCDR_STUBBED, "this write should fail"); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test (in)valid write cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR WRITE CASES\n"); ZTEST(PWRITE(STDCDR_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PWRITE(STDCDR_GOAT, buf, -1, -1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDCDR_GOAT, buf, -1, 0) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDCDR_GOAT, buf, -1, 1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDCDR_GOAT, buf, 0, -1) == 0); /* accessing of 0 bytes is always ok */ ZTEST(PWRITE(STDCDR_GOAT, buf, 1, -1) == 1); /* size = 1, offset ignored = 1 byte written */ ZTEST(PWRITE(STDCDR_GOAT, buf, 0, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) == 0); ZTEST(PWRITE(STDCDR_GOAT, buf, 1, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test (in)valid read cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR READ CASES\n"); ZTEST(PREAD(STDCDR_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDCDR_GOAT, buf, -1, -1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, -1, 0) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, -1, 1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, 0, -1) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDCDR_GOAT, buf, 1, -1) < 0); /* valid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, 0, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) < 0); ZTEST(PREAD(STDCDR_GOAT, buf, 1, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test NULL buffer cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST NULL BUFFER CASES\n"); ZTEST(PWRITE(STDCDR_GOAT, NULL, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, NULL, 0, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x1, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0xffff, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x10000, -1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1000001 - 0x10000, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x10000, 1, 0) == 1); ZTEST(PWRITE(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDCDR_GOAT, (char*)main, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1000001, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDCDR_GOAT, &data_start, 1, 0) == 1); ZTEST(PREAD(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* exit with code */ if(overall_errors > 0) FPRINTF(STDERR, "OVERALL TEST FAILED with %d errors\n", overall_errors); else FPRINTF(STDERR, "OVERALL TEST SUCCEED\n\n"); return overall_errors; }
static int testDirectory (unsigned int i) { struct GNUNET_FS_DirectoryBuilder *db; char *data; size_t dlen; struct GNUNET_FS_Uri **uris; struct GNUNET_CONTAINER_MetaData **mds; struct GNUNET_CONTAINER_MetaData *meta; struct PCLS cls; char *emsg; int p; int q; char uri[512]; char txt[128]; int ret = 0; struct GNUNET_TIME_Absolute start; const char *s; cls.max = i; uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i); mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i); meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "A title", strlen ("A title") + 1); GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "An author", strlen ("An author") + 1); for (p = 0; p < i; p++) { mds[p] = GNUNET_CONTAINER_meta_data_create (); for (q = 0; q <= p; q++) { GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q); GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>", #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR q % EXTRACTOR_metatype_get_max (), #else q % 128, #endif EXTRACTOR_METAFORMAT_UTF8, "text/plain", txt, strlen (txt) + 1); } GNUNET_snprintf (uri, sizeof (uri), "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", p); emsg = NULL; uris[p] = GNUNET_FS_uri_parse (uri, &emsg); if (uris[p] == NULL) { GNUNET_CONTAINER_meta_data_destroy (mds[p]); while (--p > 0) { GNUNET_CONTAINER_meta_data_destroy (mds[p]); GNUNET_FS_uri_destroy (uris[p]); } GNUNET_free (mds); GNUNET_free (uris); GNUNET_free (emsg); GNUNET_CONTAINER_meta_data_destroy (meta); ABORT (); /* error in testcase */ } GNUNET_assert (emsg == NULL); } start = GNUNET_TIME_absolute_get (); db = GNUNET_FS_directory_builder_create (meta); for (p = 0; p < i; p++) GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL); GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data); s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES); FPRINTF (stdout, "Creating directory with %u entires and total size %llu took %s\n", i, (unsigned long long) dlen, s); if (i < 100) { cls.pos = 0; cls.uri = uris; cls.md = mds; GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls); GNUNET_assert (cls.pos == i); } GNUNET_free (data); GNUNET_CONTAINER_meta_data_destroy (meta); for (p = 0; p < i; p++) { GNUNET_CONTAINER_meta_data_destroy (mds[p]); GNUNET_FS_uri_destroy (uris[p]); } GNUNET_free (uris); GNUNET_free (mds); return ret; }
int main (int argc, char *argv[]) { struct GNUNET_DISK_FileHandle *fh; struct GNUNET_HELLO_Message *orig; struct GNUNET_HELLO_Message *result; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; uint64_t fsize; GNUNET_log_setup ("gnunet-hello", "INFO", NULL); if (argc != 2) { FPRINTF (stderr, "%s", _("Call with name of HELLO file to modify.\n")); return 1; } if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES)) { FPRINTF (stderr, _("Error accessing file `%s': %s\n"), argv[1], STRERROR (errno)); return 1; } if (fsize > 65536) { FPRINTF (stderr, _("File `%s' is too big to be a HELLO\n"), argv[1]); return 1; } if (fsize < sizeof (struct GNUNET_MessageHeader)) { FPRINTF (stderr, _("File `%s' is too small to be a HELLO\n"), argv[1]); return 1; } fh = GNUNET_DISK_file_open (argv[1], GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ); if (NULL == fh) { FPRINTF (stderr, _("Error opening file `%s': %s\n"), argv[1], STRERROR (errno)); return 1; } { char buf[fsize] GNUNET_ALIGN; GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize)); GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); orig = (struct GNUNET_HELLO_Message *) buf; if ( (fsize != GNUNET_HELLO_size (orig)) || (GNUNET_OK != GNUNET_HELLO_get_key (orig, &pk)) ) { FPRINTF (stderr, _("Did not find well-formed HELLO in file `%s'\n"), argv[1]); return 1; } result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig); GNUNET_assert (NULL != result); fh = GNUNET_DISK_file_open (argv[1], GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); if (NULL == fh) { FPRINTF (stderr, _("Error opening file `%s': %s\n"), argv[1], STRERROR (errno)); GNUNET_free (result); return 1; } fsize = GNUNET_HELLO_size (result); if (fsize != GNUNET_DISK_file_write (fh, result, fsize)) { FPRINTF (stderr, _("Error writing HELLO to file `%s': %s\n"), argv[1], STRERROR (errno)); (void) GNUNET_DISK_file_close (fh); return 1; } GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); } return 0; }