int main(int argc, char **argv) { check_files(); #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif #ifdef ENABLE_NLS /* initialize the i18n stuff */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif textui_init(); args_execute(argc, argv); if (!init_screen()) g_error(_("Can't initialize screen handling, quitting.\n")); textui_finish_init(); main_loop = g_main_new(TRUE); g_main_run(main_loop); g_main_destroy(main_loop); textui_deinit(); #ifdef MEM_DEBUG ig_mem_profile(); #endif return 0; }
std::string impl::check_requirements(const atf::tests::vars_map& metadata, const atf::tests::vars_map& config) { std::string failure_reason = ""; for (atf::tests::vars_map::const_iterator iter = metadata.begin(); failure_reason.empty() && iter != metadata.end(); iter++) { const std::string& name = (*iter).first; const std::string& value = (*iter).second; INV(!value.empty()); // Enforced by application/X-atf-tp parser. if (name == "require.arch") failure_reason = check_arch(value); else if (name == "require.config") failure_reason = check_config(value, config); else if (name == "require.files") failure_reason = check_files(value); else if (name == "require.machine") failure_reason = check_machine(value); else if (name == "require.memory") failure_reason = check_memory(value); else if (name == "require.progs") failure_reason = check_progs(value); else if (name == "require.user") failure_reason = check_user(value, config); else { // Unknown require.* properties are forbidden by the // application/X-atf-tp parser. INV(failure_reason.find("require.") != 0); } } return failure_reason; }
/****************** * scan thru arg list, call check func for each arg * default to *.fnt if no args */ int main( int argc, char *argv[] ) { dtap = (struct _dta*)Fgetdta(); if( argc == 1 ) check_files( "*.fnt" ); else { while( --argc>0 ) check_files(*++argv); } /* if */ Cconws( "finished! press a key ..." ); while( Cconis() == 0 ); (void)Cconin(); return 0; } /* main() */
int index_main(SgrepData *sgrep,int argc, char *argv[]) { int end_options; IndexOptions options; FileList *file_list=NULL; set_default_index_options(sgrep,&options); /* * Get the command line options */ end_options=parse_index_options(&options,argv); if (end_options==SGREP_ERROR) { /* There was error. Display usage information */ index_usage(sgrep); goto error; } switch(options.index_mode) { case IM_CREATE: { if (argc==end_options && options.file_list_files==NULL) { sgrep_error(sgrep,"Can't read input from stdin when indexing.\n"); sgrep_error(sgrep," Use filename '-' to force indexing from stdin.\n"); goto error; } if (argc>end_options) { file_list=check_files(sgrep,argc-end_options,argv+end_options, 0,NULL); } options.file_list=file_list; if (create_index(&options)==SGREP_ERROR) { goto error; } break; } case IM_TERMS: { if (index_query(&options,argc-end_options,argv+end_options) ==SGREP_ERROR) { return 2; } else { return 0; } } case IM_DONE: return 0; case IM_NONE: default: sgrep_error(sgrep,"sgindex: You have to give one of -c, -C -h\n"); index_usage(sgrep); goto error; } if (file_list) delete_flist(file_list); if (options.file_list_files) delete_flist(options.file_list_files); return 0; error: if (file_list) delete_flist(file_list); if (options.file_list_files) delete_flist(options.file_list_files); return 2; }
void recalculation::check_load( u32 check_sum ) { check_files( check_sum ); string_path N; FS.update_path ( N, "$level$", "recalculation_data_slots.details" ); if( !FS.exist( N ) ) setup_recalculationflags_file( check_sum ); }
int main(int argc, char **argv) { static struct poptOption options[] = { { "dummy", 'd', POPT_ARG_NONE, &dummy, 0, "Use the dummy terminal mode", NULL }, { NULL, '\0', 0, NULL } }; dummy = FALSE; quitting = FALSE; core_init_paths(argc, argv); check_files(); #ifdef WIN32 winsock_init(); #endif #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif #ifdef ENABLE_NLS /* initialize the i18n stuff */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif textui_init(); args_register(options); args_execute(argc, argv); if (!dummy && !term_init()) { fprintf(stderr, "Can't initialize screen handling, quitting.\n"); fprintf(stderr, "You can still use the dummy mode with -d parameter\n"); return 1; } textui_finish_init(); main_loop = g_main_new(TRUE); /* Does the same as g_main_run(main_loop), except we can call our dirty-checker after each iteration */ while (!quitting) { g_main_iteration(TRUE); if (reload_config) { /* SIGHUP received, do /RELOAD */ reload_config = FALSE; signal_emit("command reload", 1, ""); } dirty_check(); } g_main_destroy(main_loop); textui_deinit(); session_upgrade(); /* if we /UPGRADEd, start the new process */ return 0; }
int main( int argc, char *argv[] ) { char *rev_file; if ( argc > 1 ) rev_file = argv[ 1 ]; else rev_file = "CHECKREV.DAT"; cout << "Data file: " << rev_file << "\n"; ifstream data_file( rev_file ); if ( data_file.fail() ) cerr << "Error opening data file!\n"; else check_files( data_file ); return( 0 ); }
void check_arg(int argc, char **argv) { t_option option; int i; init_option(&option); i = 0; while (i < argc) { if (argv[i][0] == '-') { if (!check_opt(argv[i], &option)) { my_putstr("Usage: my_ls [-lR1rdtaAL] [dir1 [...]]\n"); return ; } } i++; } check_files(argc, argv, &option); }
int main (int argc,char *argv[]) { /* Initialize any global variables and data structures */ init_data(); /* Parse the command line options and process accordingly */ if (!parse_command(argc,argv)) { exit(1); } else if (!help) { check_files(); } else { print_help(); } /* Free any allocated memory and close any open files */ clean_up(); return 0; }
//******************************************************************* // start PRIVATE slot //******************************************************************* void QBtCompareFileDialog::start() { cancel_->setText( tr( BREAK ) ); start_->setVisible( false ); is_started_ = true; const qint32 retval = comparator_->compare( fpath1_, fpath2_ ); switch( retval ) { case QBtFileComparator::EQUAL: QMessageBox::information( this, tr( CAPTION ), tr( EQUAL ) ); reject(); break; case QBtFileComparator::NOT_EQUAL: if( is_canceled_ ) reject(); check_files() ? accept() : reject(); break; case QBtFileComparator::IO_ERROR: QMessageBox::critical( this, tr( CAPTION ), tr( IO_ERROR ) ); reject(); break; } }
int main(int argc, char **argv) { static struct poptOption options[] = { { "dummy", 'd', POPT_ARG_NONE, &dummy, 0, "Use the dummy terminal mode", NULL }, { NULL, '\0', 0, NULL } }; dummy = FALSE; quitting = FALSE; core_init_paths(argc, argv); check_files(); #ifdef WIN32 winsock_init(); #endif #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif #ifdef ENABLE_NLS /* initialize the i18n stuff */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif /* setlocale() must be called at the beginning before any calls that affect it, especially regexps seem to break if they're generated before t his call. locales aren't actually used for anything else than autodetection of UTF-8 currently.. */ setlocale(LC_CTYPE, ""); textui_init(); args_register(options); args_execute(argc, argv); if (!dummy && !term_init()) { fprintf(stderr, "Can't initialize screen handling, quitting.\n"); fprintf(stderr, "You can still use the dummy mode with -d parameter\n"); return 1; } textui_finish_init(); main_loop = g_main_new(TRUE); /* Does the same as g_main_run(main_loop), except we can call our dirty-checker after each iteration */ while (!quitting) { if (!dummy) term_refresh_freeze(); g_main_iteration(TRUE); if (!dummy) term_refresh_thaw(); if (reload_config) { /* SIGHUP received, do /RELOAD */ reload_config = FALSE; signal_emit("command reload", 1, ""); } dirty_check(); } g_main_destroy(main_loop); textui_deinit(); session_upgrade(); /* if we /UPGRADEd, start the new process */ return 0; }
static int process_dir(const char *oldpath, const char *newpath, const char *ext, unsigned int maxlinks, int burp_mode, int level) { int ret=-1; DIR *dirp=NULL; char *path=NULL; struct stat info; struct dirent *dirinfo=NULL; struct file newfile; struct mystruct *find=NULL; static char working[256]=""; static char finishing[256]=""; newfile.path=NULL; if(!(path=prepend(oldpath, newpath, "/"))) goto end; if(burp_mode && level==0) { if(get_link(path, "working", working, sizeof(working)) || get_link(path, "finishing", finishing, sizeof(finishing))) goto end; } if(!(dirp=opendir(path))) { logp("Could not opendir '%s': %s\n", path, strerror(errno)); ret=0; goto end; } while((dirinfo=readdir(dirp))) { if(!strcmp(dirinfo->d_name, ".") || !strcmp(dirinfo->d_name, "..")) continue; //printf("try %s\n", dirinfo->d_name); if(burp_mode) { if(level==0) { /* Be careful not to try to dedup the lockfiles. The lock actually gets lost if you open one to do a checksum and then close it. This caused me major headaches to figure out. */ if(!strcmp(dirinfo->d_name, LOCKFILE_NAME) || !strcmp(dirinfo->d_name, BEDUP_LOCKFILE_NAME)) continue; /* Skip places where backups are going on. */ if(!strcmp(dirinfo->d_name, working) || !strcmp(dirinfo->d_name, finishing)) continue; if(!strcmp(dirinfo->d_name, "deleteme")) continue; } else if(level==1) { // Do not dedup stuff that might be appended to later. if(!strncmp(dirinfo->d_name, "log", strlen("log")) || !strncmp(dirinfo->d_name, "verifylog", strlen("verifylog")) || !strncmp(dirinfo->d_name, "restorelog", strlen("restorelog"))) continue; } } free_w(&newfile.path); if(!(newfile.path=prepend(path, dirinfo->d_name, "/"))) goto end; if(lstat(newfile.path, &info)) continue; if(S_ISDIR(info.st_mode)) { if(process_dir(path, dirinfo->d_name, ext, maxlinks, burp_mode, level+1)) goto end; continue; } else if(!S_ISREG(info.st_mode) || !info.st_size) // ignore zero-length files continue; newfile.dev=info.st_dev; newfile.ino=info.st_ino; newfile.nlink=info.st_nlink; newfile.full_cksum=0; newfile.part_cksum=0; newfile.next=NULL; //printf("%s\n", newfile.path); if((find=find_key(info.st_size))) { if(check_files(find, &newfile, &info, ext, maxlinks)) goto end; } else { //printf("add: %s\n", newfile.path); if(add_key(info.st_size, &newfile)) goto end; } } ret=0; end: closedir(dirp); free_w(&newfile.path); free_w(&path); return ret; }
/* * Copy from inout-file to out-file and from in-file to inout-file. */ int main(int argc, char *argv[]) { grpc_error_t ret; int result; char *conf, *array_size_str, *end; int array_size; char **in_file_array, **inout_file_array, **out_file_array; char *in_file, *inout_file, *out_file; if (argc < 6) { fprintf(stderr, "Usage: %s config count in-file inout-file out-file\n", argv[0]); exit(2); } conf = argv[1]; array_size_str = argv[2]; in_file = argv[3]; inout_file = argv[4]; out_file = argv[5]; ret = grpc_initialize(conf); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(ret)); exit(2); } array_size = strtol(array_size_str, &end, 0); if (*end != '\0') { fprintf(stderr, "Argument \"%s\" is not digit.\n", array_size_str); exit(1); } else if (array_size < 1){ fprintf(stderr, "array_size %d < 1 (min)\n", array_size); exit(1); } result = create_file_names(array_size, in_file, inout_file, out_file, &in_file_array, &inout_file_array, &out_file_array); if (result == 0) { fprintf(stderr, "creating filenames failed\n"); exit(1); } result = check_files(array_size, in_file_array, inout_file_array); if (result == 0) { fprintf(stderr, "files are not prepared. no test performed.\n"); exit(1); } ret = grpc_function_handle_default( &handles, MODULE_NAME "/filename_array_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_call(&handles, array_size, in_file_array, inout_file_array, out_file_array); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_finalize(); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(ret)); exit(2); } result = destroy_file_names(array_size, &in_file_array, &inout_file_array, &out_file_array); if (result == 0) { fprintf(stderr, "destroying filenames failed\n"); exit(1); } return 0; }
int main(int argc, char **argv) { alpm_list_t *i; int ret = 0; if(!(config = parse_opts(argc, argv))) { ret = 1; goto cleanup; } if(checks == 0) { checks = CHECK_DEPENDS | CHECK_FILES; } if(!(handle = pu_initialize_handle_from_config(config))) { fprintf(stderr, "error: failed to initialize alpm.\n"); ret = 1; goto cleanup; } localdb = alpm_get_localdb(handle); pkgcache = alpm_db_get_pkgcache(localdb); for(; optind < argc; ++optind) { if(load_pkg(argv[optind]) == NULL) { ret = 1; } } if(!isatty(fileno(stdin)) && errno != EBADF) { char *buf = NULL; size_t len = 0; ssize_t read; while((read = getdelim(&buf, &len, isep, stdin)) != -1) { if(buf[read - 1] == isep) { buf[read - 1] = '\0'; } if(load_pkg(buf) == NULL) { ret = 1; } } free(buf); } if(ret) { goto cleanup; } if(packages == NULL) { packages = alpm_list_copy(pkgcache); recursive = 0; } else if(recursive) { /* load [opt-]depends */ alpm_list_t *i, *originals = alpm_list_copy(packages); for(i = originals; i; i = alpm_list_next(i)) { add_deps(i->data); } alpm_list_free(originals); } for(i = packages; i; i = alpm_list_next(i)) { int pkgerr = 0; #define RUNCHECK(t, b) if((checks & t) && b != 0) { pkgerr = ret = 1; } RUNCHECK(CHECK_DEPENDS, check_depends(i->data)); RUNCHECK(CHECK_OPT_DEPENDS, check_opt_depends(i->data)); RUNCHECK(CHECK_FILES, check_files(i->data)); RUNCHECK(CHECK_FILE_PROPERTIES, check_file_properties(i->data)); RUNCHECK(CHECK_MD5SUM, check_md5sum(i->data)); RUNCHECK(CHECK_SHA256SUM, check_sha256sum(i->data)); #undef RUNCHECK if(pkgerr && list_broken) { printf("%s\n", alpm_pkg_get_name(i->data)); } } cleanup: alpm_list_free(packages); alpm_release(handle); pu_config_free(config); return ret; }
void get_files_to_play(GtkWidget *widget, gpointer user_data) { /** User single file selection. **/ #ifdef DEBUG DEBUG_FUNC_MARK #endif GtkWidget *file_chooser_dialog = gtk_file_chooser_dialog_new("Choose music files to listen.", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, "Cancel", GTK_RESPONSE_CANCEL, "Open", GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser_dialog), current_folder.c_str() ) ; gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(file_chooser_dialog), FALSE) ; gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(file_chooser_dialog), FALSE) ; gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(file_chooser_dialog), TRUE) ; gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_chooser_dialog), TRUE) ; GtkFileFilter *file_filter = gtk_file_filter_new() ; for (int c=0 ; c < static_cast<int>(extension_list.size()) ; c++) { gtk_file_filter_add_pattern(GTK_FILE_FILTER(file_filter), extension_list.at(c).c_str()) ; } gtk_file_filter_set_name(GTK_FILE_FILTER(file_filter), "Supported music filetypes") ; gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser_dialog), GTK_FILE_FILTER(file_filter)) ; gtk_window_set_position(GTK_WINDOW(file_chooser_dialog), GTK_WIN_POS_CENTER_ALWAYS) ; gtk_widget_set_size_request(file_chooser_dialog,-1,-1) ; gtk_window_set_modal(GTK_WINDOW(file_chooser_dialog), TRUE) ; gtk_window_set_destroy_with_parent(GTK_WINDOW(file_chooser_dialog), TRUE) ; gtk_window_set_type_hint(GTK_WINDOW(file_chooser_dialog), GDK_WINDOW_TYPE_HINT_DIALOG) ; gtk_window_set_transient_for(GTK_WINDOW(file_chooser_dialog), GTK_WINDOW(gui->window)) ; GSList *filepath_list = NULL ; gint result = gtk_dialog_run (GTK_DIALOG (file_chooser_dialog)); switch (result) { case GTK_RESPONSE_CANCEL : gtk_widget_destroy(file_chooser_dialog); return ; case GTK_RESPONSE_ACCEPT : filepath_list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(file_chooser_dialog)) ; gtk_widget_destroy(file_chooser_dialog) ; break ; } if (filepath_list != NULL) { gchar *file_dirname = g_path_get_dirname((const gchar *) g_slist_nth_data(filepath_list, 0)) ; check_files(filepath_list) ; current_folder = file_dirname ; g_free(file_dirname) ; #ifdef DEBUG fprintf(stdout,"%s current_folder: %s\n", __func__, current_folder.c_str() ) ; #endif g_slist_free(filepath_list) ; } }
/* * The main configuration routine. Its implementation is hugely inspired by the * the same routine implementation in Solaris NSCD. */ int parse_config_file(struct configuration *config, const char *fname, char const **error_str, int *error_line) { FILE *fin; char buffer[255]; char *fields[128]; int field_count, line_num, value; int res; TRACE_IN(parse_config_file); assert(config != NULL); assert(fname != NULL); fin = fopen(fname, "r"); if (fin == NULL) { TRACE_OUT(parse_config_file); return (-1); } res = 0; line_num = 0; memset(buffer, 0, sizeof(buffer)); while ((res == 0) && (fgets(buffer, sizeof(buffer) - 1, fin) != NULL)) { field_count = strbreak(buffer, fields, sizeof(fields)); ++line_num; if (field_count == 0) continue; switch (fields[0][0]) { case '#': case '\0': continue; case 'e': if ((field_count == 3) && (strcmp(fields[0], "enable-cache") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_yesno(fields[2])) != -1)) { enable_cache(config, fields[1], value); continue; } break; case 'd': if ((field_count == 2) && (strcmp(fields[0], "debug-level") == 0) && ((value = get_number(fields[1], 0, 10)) != -1)) { continue; } break; case 'p': if ((field_count == 3) && (strcmp(fields[0], "positive-time-to-live") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { set_positive_time_to_live(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "positive-confidence-threshold") == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { set_positive_confidence_threshold(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "positive-policy") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_policy(fields[2])) != -1)) { set_positive_policy(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "perform-actual-lookups") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_yesno(fields[2])) != -1)) { set_perform_actual_lookups(config, fields[1], value); continue; } break; case 'n': if ((field_count == 3) && (strcmp(fields[0], "negative-time-to-live") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { set_negative_time_to_live(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "negative-confidence-threshold") == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { set_negative_confidence_threshold(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "negative-policy") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_policy(fields[2])) != -1)) { set_negative_policy(config, fields[1], value); continue; } break; case 's': if ((field_count == 3) && (strcmp(fields[0], "suggested-size") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { set_suggested_size(config, fields[1], value); continue; } break; case 't': if ((field_count == 2) && (strcmp(fields[0], "threads") == 0) && ((value = get_number(fields[1], 1, -1)) != -1)) { set_threads_num(config, value); continue; } break; case 'k': if ((field_count == 3) && (strcmp(fields[0], "keep-hot-count") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { set_keep_hot_count(config, fields[1], value); continue; } break; case 'c': if ((field_count == 3) && (strcmp(fields[0], "check-files") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_yesno(fields[2])) != -1)) { check_files(config, fields[1], value); continue; } break; default: break; } LOG_ERR_2("config file parser", "error in file " "%s on line %d", fname, line_num); *error_str = "syntax error"; *error_line = line_num; res = -1; } fclose(fin); TRACE_OUT(parse_config_file); return (res); }
// Return 0 for directory processed, -1 for error, 1 for not processed. static int process_dir(const char *oldpath, const char *newpath, const char *ext, unsigned int maxlinks, int burp_mode, int level) { int ret=-1; DIR *dirp=NULL; char *path=NULL; struct stat info; struct dirent *dirinfo=NULL; struct file newfile; struct mystruct *find=NULL; static char working[256]=""; static char finishing[256]=""; newfile.path=NULL; if(!(path=prepend_s(oldpath, newpath))) goto end; if(burp_mode && level==0) { if(get_link(path, "working", working, sizeof(working)) || get_link(path, "finishing", finishing, sizeof(finishing))) goto end; if(!looks_like_protocol1(path)) { logp("%s does not look like a protocol 1 storage directory - skipping\n", path); ret=1; goto end; } } if(!(dirp=opendir(path))) { logp("Could not opendir '%s': %s\n", path, strerror(errno)); ret=1; goto end; } while((dirinfo=readdir(dirp))) { if(!strcmp(dirinfo->d_name, ".") || !strcmp(dirinfo->d_name, "..")) continue; //printf("try %s\n", dirinfo->d_name); if(burp_mode && level_exclusion(level, dirinfo->d_name, working, finishing)) continue; free_w(&newfile.path); if(!(newfile.path=prepend_s(path, dirinfo->d_name))) goto end; if(lstat(newfile.path, &info)) continue; if(S_ISDIR(info.st_mode)) { if(process_dir(path, dirinfo->d_name, ext, maxlinks, burp_mode, level+1)) goto end; continue; } else if(!S_ISREG(info.st_mode) || !info.st_size) // ignore zero-length files continue; newfile.dev=info.st_dev; newfile.ino=info.st_ino; newfile.nlink=info.st_nlink; newfile.full_cksum=0; newfile.part_cksum=0; newfile.next=NULL; if((find=find_key(info.st_size))) { //printf("check %d: %s\n", info.st_size, newfile.path); if(check_files(find, &newfile, &info, ext, maxlinks)) goto end; } else { //printf("add: %s\n", newfile.path); if(add_key(info.st_size, &newfile)) goto end; } } ret=0; end: closedir(dirp); free_w(&newfile.path); free_w(&path); return ret; }
int main(int argc, char **argv) { static int version = 0; static GOptionEntry options[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display Irssi version", NULL }, { NULL } }; int loglev; core_register_options(); fe_common_core_register_options(); args_register(options); args_execute(argc, argv); if (version) { printf(PACKAGE_TARNAME" " PACKAGE_VERSION" (%d %04d)\n", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); return 0; } srand(time(NULL)); quitting = FALSE; core_preinit(argv[0]); check_files(); #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif /* setlocale() must be called at the beginning before any calls that affect it, especially regexps seem to break if they're generated before this call. locales aren't actually used for anything else than autodetection of UTF-8 currently.. furthermore to get the users's charset with g_get_charset() properly you have to call setlocale(LC_ALL, "") */ setlocale(LC_ALL, ""); /* Temporarily raise the fatal level to abort on config errors. */ loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL); textui_init(); if (!term_init()) { fprintf(stderr, "Can't initialize screen handling.\n"); return 1; } g_log_set_always_fatal(loglev); textui_finish_init(); main_loop = g_main_new(TRUE); /* Does the same as g_main_run(main_loop), except we can call our dirty-checker after each iteration */ while (!quitting) { if (reload_config) { /* SIGHUP received, do /RELOAD */ reload_config = FALSE; signal_emit("command reload", 1, ""); } dirty_check(); term_refresh_freeze(); g_main_iteration(TRUE); term_refresh_thaw(); } g_main_destroy(main_loop); textui_deinit(); session_upgrade(); /* if we /UPGRADEd, start the new process */ return 0; }
int main(int argc, char *argv[]) /********************************************************************** vicNl.c Dag Lohmann January 1996 This program controls file I/O and variable initialization as well as being the primary driver for the model. For details about variables, input files and subroutines check: http://ce.washington.edu/~hydro/Lettenmaier/Models/VIC/VIC_home.html UNITS: unless otherwise marked: all water balance components are in mm all energy balance components are in mks depths, and lengths are in m modifications: 1997-98 Model was updated from simple 2 layer water balance to an extension of the full energy and water balance 3 layer model. KAC 02-27-01 added controls for lake model KAC 11-18-02 Updated storage of lake water for water balance calculations. LCB 03-12-03 Modifed to add AboveTreeLine to soil_con_struct so that the model can make use of the computed treeline. KAC 04-10-03 Modified to initialize storm parameters using the state file. KAC 04-10-03 Modified to start the model by skipping records until the state file date is found. This replaces the previous method of modifying the global file start date, which can change the interpolation of atmospheric forcing data. KAC 04-15-03 Modified to store wet and dry fractions when intializing water balance storage. This accounts for changes in model state initialization, which now stores wet and dry fractions rather than just averagedvalues. KAC 29-Oct-03 Modified the version display banner to print the version string defined in global.h. TJB 01-Nov-04 Updated arglist for make_dist_prcp(), as part of fix for QUICK_FLUX state file compatibility. TJB 02-Nov-04 Updated arglist for read_lakeparam(), as part of fix for lake fraction readjustment. TJB 2005-Apr-13 OUTPUT_FORCE option now calls close_files(). TJB 2006-Sep-23 Implemented flexible output configuration; uses the new out_data, out_data_files, and save_data structures. TJB 2006-Oct-16 Merged infiles and outfiles structs into filep_struct; This included merging builtnames into filenames. TJB 2006-Nov-07 Removed LAKE_MODEL option. TJB 2006-Nov-07 Changed statefile to init_state in call to check_state_file(). TJB 2007-Jan-15 Added PRT_HEADER option; added call to write_header(). TJB 2007-Apr-04 Added option to continue run after a cell fails. GCT/KAC 2007-Apr-21 Added calls to free_dmy(), free_out_data_files(), free_out_data(), and free_veglib(). Added closing of all parameter files. TJB 2007-Aug-21 Return ErrorFlag from initialize_model_state. JCA 2007-Sep-14 Excluded calls to free_veglib() and closing of parameter files other than the soil param file for the case when OUTPUT_FORCE=TRUE. TJB 2007-Nov-06 Moved computation of cell_area from read_lakeparam() to read_soilparam() and read_soilparam_arc(). TJB 2008-May-05 Added prcp fraction (mu) to initial water storage computation. This solves water balance errors for the case where DIST_PRCP is TRUE. TJB 2009-Jan-16 Added soil_con.avgJulyAirTemp to argument list of initialize_atmos(). TJB 2009-Jun-09 Modified to use extension of veg_lib structure to contain bare soil information. TJB 2009-Jul-07 Added soil_con.BandElev[] to read_snowband() arg list. TJB 2009-Jul-31 Replaced references to N+1st veg tile with references to index of lake/wetland tile. TJB 2009-Sep-28 Replaced initial water/energy storage computations and calls to calc_water_balance_error/calc_energy_balance_error with an initial call to put_data. Modified the call to read_snowband(). TJB 2009-Dec-11 Removed save_data structure from argument list of initialize_model_state(). TJB 2010-Mar-31 Added cell_area to initialize_atmos(). TJB 2010-Apr-28 Removed individual soil_con variables from argument list of initialize_atmos() and replaced with *soil_con. TJB 2010-Nov-10 Added closing of state files. TJB 2011-Jan-04 Made read_soilparam_arc() a sub-function of read_soilparam(). TJB 2012-Jan-16 Removed LINK_DEBUG code BN **********************************************************************/ { extern veg_lib_struct *veg_lib; extern option_struct options; extern Error_struct Error; extern global_param_struct global_param; /** Variable Declarations **/ char NEWCELL; char LASTREC; char MODEL_DONE; char RUN_MODEL; char *init_STILL_STORM; char ErrStr[MAXSTRING]; int rec, i, j; int veg; int dist; int band; int Ndist; int Nveg_type; int cellnum; int index; int *init_DRY_TIME; int Ncells; int cell_cnt; int startrec; int ErrorFlag; float mu; double storage; double veg_fract; double band_fract; double Clake; dmy_struct *dmy; atmos_data_struct *atmos; veg_con_struct *veg_con; soil_con_struct soil_con; dist_prcp_struct prcp; /* stores information about distributed precipitation */ filenames_struct filenames; filep_struct filep; lake_con_struct lake_con; out_data_file_struct *out_data_files; out_data_struct *out_data; save_data_struct save_data; /** Read Model Options **/ initialize_global(); filenames = cmd_proc(argc, argv); #if VERBOSE display_current_settings(DISP_VERSION,(filenames_struct*)NULL,(global_param_struct*)NULL); #endif /** Read Global Control File **/ filep.globalparam = open_file(filenames.global,"r"); global_param = get_global_param(&filenames, filep.globalparam); /** Set up output data structures **/ out_data = create_output_list(); out_data_files = set_output_defaults(out_data); fclose(filep.globalparam); filep.globalparam = open_file(filenames.global,"r"); parse_output_info(&filenames, filep.globalparam, &out_data_files, out_data); /** Check and Open Files **/ check_files(&filep, &filenames); #if !OUTPUT_FORCE /** Read Vegetation Library File **/ veg_lib = read_veglib(filep.veglib,&Nveg_type); #endif // !OUTPUT_FORCE /** Initialize Parameters **/ if(options.DIST_PRCP) Ndist = 2; else Ndist = 1; cellnum = -1; /** Make Date Data Structure **/ dmy = make_dmy(&global_param); /** allocate memory for the atmos_data_struct **/ alloc_atmos(global_param.nrecs, &atmos); /** Initial state **/ startrec = 0; #if !OUTPUT_FORCE if ( options.INIT_STATE ) filep.init_state = check_state_file(filenames.init_state, dmy, &global_param, options.Nlayer, options.Nnode, &startrec); /** open state file if model state is to be saved **/ if ( options.SAVE_STATE && strcmp( filenames.statefile, "NONE" ) != 0 ) filep.statefile = open_state_file(&global_param, filenames, options.Nlayer, options.Nnode); else filep.statefile = NULL; #endif // !OUTPUT_FORCE /************************************ Run Model for all Active Grid Cells ************************************/ MODEL_DONE = FALSE; cell_cnt=0; while(!MODEL_DONE) { soil_con = read_soilparam(filep.soilparam, filenames.soil_dir, &cell_cnt, &RUN_MODEL, &MODEL_DONE); if(RUN_MODEL) { #if QUICK_FS /** Allocate Unfrozen Water Content Table **/ if(options.FROZEN_SOIL) { for(i=0;i<MAX_LAYERS;i++) { soil_con.ufwc_table_layer[i] = (double **)malloc((QUICK_FS_TEMPS+1)*sizeof(double *)); for(j=0;j<QUICK_FS_TEMPS+1;j++) soil_con.ufwc_table_layer[i][j] = (double *)malloc(2*sizeof(double)); } for(i=0;i<MAX_NODES;i++) { soil_con.ufwc_table_node[i] = (double **)malloc((QUICK_FS_TEMPS+1)*sizeof(double *)); for(j=0;j<QUICK_FS_TEMPS+1;j++) soil_con.ufwc_table_node[i][j] = (double *)malloc(2*sizeof(double)); } } #endif /* QUICK_FS */ NEWCELL=TRUE; cellnum++; #if !OUTPUT_FORCE /** Read Grid Cell Vegetation Parameters **/ veg_con = read_vegparam(filep.vegparam, soil_con.gridcel, Nveg_type); calc_root_fractions(veg_con, &soil_con); if ( options.LAKES ) lake_con = read_lakeparam(filep.lakeparam, soil_con, veg_con); #endif // !OUTPUT_FORCE /** Build Gridded Filenames, and Open **/ make_in_and_outfiles(&filep, &filenames, &soil_con, out_data_files); if (options.PRT_HEADER) { /** Write output file headers **/ write_header(out_data_files, out_data, dmy, global_param); } #if !OUTPUT_FORCE /** Read Elevation Band Data if Used **/ read_snowband(filep.snowband, &soil_con); /** Make Precipitation Distribution Control Structure **/ prcp = make_dist_prcp(veg_con[0].vegetat_type_num); #endif // !OUTPUT_FORCE /************************************************** Initialize Meteological Forcing Values That Have not Been Specifically Set **************************************************/ #if VERBOSE fprintf(stderr,"Initializing Forcing Data\n"); #endif /* VERBOSE */ initialize_atmos(atmos, dmy, filep.forcing, #if OUTPUT_FORCE &soil_con, out_data_files, out_data); #else /* OUTPUT_FORCE */ &soil_con); #endif /* OUTPUT_FORCE */ #if !OUTPUT_FORCE /************************************************** Initialize Energy Balance and Snow Variables **************************************************/ #if VERBOSE fprintf(stderr,"Model State Initialization\n"); #endif /* VERBOSE */ ErrorFlag = initialize_model_state(&prcp, dmy[0], &global_param, filep, soil_con.gridcel, veg_con[0].vegetat_type_num, options.Nnode, Ndist, atmos[0].air_temp[NR], &soil_con, veg_con, lake_con, &init_STILL_STORM, &init_DRY_TIME); if ( ErrorFlag == ERROR ) { if ( options.CONTINUEONERROR == TRUE ) { // Handle grid cell solution error fprintf(stderr, "ERROR: Grid cell %i failed in record %i so the simulation has not finished. An incomplete output file has been generated, check your inputs before rerunning the simulation.\n", soil_con.gridcel, rec); break; } else { // Else exit program on cell solution error as in previous versions sprintf(ErrStr, "ERROR: Grid cell %i failed in record %i so the simulation has ended. Check your inputs before rerunning the simulation.\n", soil_con.gridcel, rec); vicerror(ErrStr); } } #if VERBOSE fprintf(stderr,"Running Model\n"); #endif /* VERBOSE */ /** Update Error Handling Structure **/ Error.filep = filep; Error.out_data_files = out_data_files; /** Initialize the storage terms in the water and energy balances **/ /** Sending a negative record number (-global_param.nrecs) to dist_prec() will accomplish this **/ ErrorFlag = dist_prec(&atmos[0], &prcp, &soil_con, veg_con, &lake_con, dmy, &global_param, &filep, out_data_files, out_data, &save_data, -global_param.nrecs, cellnum, NEWCELL, LASTREC, init_STILL_STORM, init_DRY_TIME); /****************************************** Run Model in Grid Cell for all Time Steps ******************************************/ for ( rec = startrec ; rec < global_param.nrecs; rec++ ) { if ( rec == global_param.nrecs - 1 ) LASTREC = TRUE; else LASTREC = FALSE; ErrorFlag = dist_prec(&atmos[rec], &prcp, &soil_con, veg_con, &lake_con, dmy, &global_param, &filep, out_data_files, out_data, &save_data, rec, cellnum, NEWCELL, LASTREC, init_STILL_STORM, init_DRY_TIME); if ( ErrorFlag == ERROR ) { if ( options.CONTINUEONERROR == TRUE ) { // Handle grid cell solution error fprintf(stderr, "ERROR: Grid cell %i failed in record %i so the simulation has not finished. An incomplete output file has been generated, check your inputs before rerunning the simulation.\n", soil_con.gridcel, rec); break; } else { // Else exit program on cell solution error as in previous versions sprintf(ErrStr, "ERROR: Grid cell %i failed in record %i so the simulation has ended. Check your inputs before rerunning the simulation.\n", soil_con.gridcel, rec); vicerror(ErrStr); } } NEWCELL=FALSE; for ( veg = 0; veg <= veg_con[0].vegetat_type_num; veg++ ) init_DRY_TIME[veg] = -999; } /* End Rec Loop */ #endif /* !OUTPUT_FORCE */ close_files(&filep,out_data_files,&filenames); #if !OUTPUT_FORCE #if QUICK_FS if(options.FROZEN_SOIL) { for(i=0;i<MAX_LAYERS;i++) { for(j=0;j<6;j++) free((char *)soil_con.ufwc_table_layer[i][j]); free((char *)soil_con.ufwc_table_layer[i]); } for(i=0;i<MAX_NODES;i++) { for(j=0;j<6;j++) free((char *)soil_con.ufwc_table_node[i][j]); free((char *)soil_con.ufwc_table_node[i]); } } #endif /* QUICK_FS */ free_dist_prcp(&prcp,veg_con[0].vegetat_type_num); free_vegcon(&veg_con); free((char *)soil_con.AreaFract); free((char *)soil_con.BandElev); free((char *)soil_con.Tfactor); free((char *)soil_con.Pfactor); free((char *)soil_con.AboveTreeLine); free((char*)init_STILL_STORM); free((char*)init_DRY_TIME); #endif /* !OUTPUT_FORCE */ } /* End Run Model Condition */ } /* End Grid Loop */ /** cleanup **/ free_atmos(global_param.nrecs, &atmos); free_dmy(&dmy); free_out_data_files(&out_data_files); free_out_data(&out_data); #if !OUTPUT_FORCE free_veglib(&veg_lib); #endif /* !OUTPUT_FORCE */ fclose(filep.soilparam); #if !OUTPUT_FORCE fclose(filep.vegparam); fclose(filep.veglib); if (options.SNOW_BAND>1) fclose(filep.snowband); if (options.LAKES) fclose(filep.lakeparam); if ( options.INIT_STATE ) fclose(filep.init_state); if ( options.SAVE_STATE && strcmp( filenames.statefile, "NONE" ) != 0 ) fclose(filep.statefile); #endif /* !OUTPUT_FORCE */ return EXIT_SUCCESS; } /* End Main Program */
void TestChasteCitation() { /* * Get location of output file to pass through as -citation argument. * At this point we haven't called PetscSetup, so the number of threads * running at this point is implementation-dependent, and it's not really * safe to do anything collective! Fortunately FileFinder isn't. */ FileFinder output_petsc_file("TestCitations/petsc_citations.txt", RelativeTo::ChasteTestOutput); // First part of PETSc citation testing. { // Turn on citations with argument - N.B. we direct PETSc to a different file to Chaste implementation. // N.B. This is needed twice - PETSc implementation reads the first one, // Chaste implementation masquerading as PETSc reads the second! CommandLineArgumentsMocker mocker("-citations " + output_petsc_file.GetAbsolutePath()); // Setup PETSc (with command line for citations pointing to PETSc output file) PetscSetupUtils::CommonSetup(); } /* * Make empty directory, has to be done after PETSc is set up to be safe in parallel. */ OutputFileHandler handler("TestCitations"); // If we need to check the Chaste version manually (PETSc is new) // Otherwise on old PETSc the test below covers what is in this guard. #if ((PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 5) || PETSC_VERSION_MAJOR > 3) FileFinder output_chaste_file("TestCitations/chaste_citations.txt", RelativeTo::ChasteTestOutput); // Test Chaste implementation on its own (for PETSc <= 3.4, or no PETSc setup) Citations::mUseChasteImplementation = true; { std::cout << "Testing Chaste implementation" << std::endl; // Turn on citations with argument CommandLineArgumentsMocker mocker("-citations " + output_chaste_file.GetAbsolutePath()); Citations::Register(PetscCitation1, &PetscCite1); Citations::Register(PetscCitation2, &PetscCite2); Citations::Register(ChasteCitation, &ChasteCite); Citations::Print(); // Writes the citations file. PetscTools::Barrier("Make sure the master process has finished writing the citations file."); FileFinder reference_citations("global/test/data/citations.txt", RelativeTo::ChasteSourceRoot); FileComparison check_files(output_chaste_file, reference_citations); // Collective call (default behaviour) check_files.CompareFiles(); TS_ASSERT_EQUALS(Citations::mUseChasteImplementation, true); } // Reset to default Citations::mUseChasteImplementation = false; Citations::mCitations.clear(); #endif // Now test as part of PETSc, // PETSc implementation will be used if PETSc is >= 3.5 // if not, this is something of a duplicate of the above test! { std::cout << "Testing PETSc implementation" << std::endl; // Turn on citations with argument - N.B. we direct PETSc to a different file to Chaste implementation. // N.B. This is needed twice - PETSc implementation reads the first one, // Chaste implementation masquerading as PETSc reads the second! CommandLineArgumentsMocker mocker("-citations " + output_petsc_file.GetAbsolutePath()); PetscSetupUtils::CommonFinalize(); // This prints the citations to disk // Check PETSc version - this is just because they reformatted their BibTex between versions, no change to function! #if (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR == 9) //PETSc 3.9 FileFinder reference_citations("global/test/data/citations-2018.txt", RelativeTo::ChasteSourceRoot); #elif (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR == 8) //PETSc 3.8 FileFinder reference_citations("global/test/data/citations-2017.txt", RelativeTo::ChasteSourceRoot); #elif (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR == 7) //PETSc 3.7 FileFinder reference_citations("global/test/data/citations-2016.txt", RelativeTo::ChasteSourceRoot); #elif (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR == 6) //PETSc 3.6 FileFinder reference_citations("global/test/data/citations-2015.txt", RelativeTo::ChasteSourceRoot); #else // Use PETSc 3.4 older version (or mocked up version that matches 3.4) FileFinder reference_citations("global/test/data/citations.txt", RelativeTo::ChasteSourceRoot); #endif FileComparison check_files(output_petsc_file, reference_citations, false); // false = not collective (this is after Finalize) check_files.CompareFiles(); } }
int main(int argc, char **argv) { static int version = 0; static GOptionEntry options[] = { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, "Use the dummy terminal mode", NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display irssi version", NULL }, { NULL } }; #ifdef USE_GC g_mem_set_vtable(&gc_mem_table); #endif core_register_options(); fe_common_core_register_options(); args_register(options); args_execute(argc, argv); if (version) { printf(PACKAGE_TARNAME" " PACKAGE_VERSION" (%d %04d)\n", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); return 0; } srand(time(NULL)); dummy = FALSE; quitting = FALSE; core_preinit(argv[0]); check_files(); #ifdef WIN32 winsock_init(); #endif #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif /* setlocale() must be called at the beginning before any calls that affect it, especially regexps seem to break if they're generated before this call. locales aren't actually used for anything else than autodetection of UTF-8 currently.. furthermore to get the users's charset with g_get_charset() properly you have to call setlocale(LC_ALL, "") */ setlocale(LC_ALL, ""); textui_init(); if (!dummy && !term_init()) { fprintf(stderr, "Can't initialize screen handling, quitting.\n"); fprintf(stderr, "You can still use the dummy mode with -d parameter\n"); return 1; } textui_finish_init(); main_loop = g_main_new(TRUE); /* Does the same as g_main_run(main_loop), except we can call our dirty-checker after each iteration */ while (!quitting) { #ifdef USE_GC GC_collect_a_little(); #endif if (!dummy) term_refresh_freeze(); g_main_iteration(TRUE); if (!dummy) term_refresh_thaw(); if (reload_config) { /* SIGHUP received, do /RELOAD */ reload_config = FALSE; signal_emit("command reload", 1, ""); } dirty_check(); } g_main_destroy(main_loop); textui_deinit(); session_upgrade(); /* if we /UPGRADEd, start the new process */ return 0; }