int line6_pcm_start(struct snd_line6_pcm *line6pcm, int channels) { unsigned long flags_old = __sync_fetch_and_or(&line6pcm->flags, channels); unsigned long flags_new = flags_old | channels; int err = 0; line6pcm->prev_fbuf = NULL; if (test_flags(flags_old, flags_new, MASK_CAPTURE)) { /* Waiting for completion of active URBs in the stop handler is a bug, we therefore report an error if capturing is restarted too soon. */ if (line6pcm->active_urb_in | line6pcm->unlink_urb_in) return -EBUSY; if (!(flags_new & MASK_PCM_ALSA_CAPTURE)) { err = line6_alloc_capture_buffer(line6pcm); if (err < 0) goto pcm_start_error; } line6pcm->count_in = 0; line6pcm->prev_fsize = 0; err = line6_submit_audio_in_all_urbs(line6pcm); if (err < 0) goto pcm_start_error; } if (test_flags(flags_old, flags_new, MASK_PLAYBACK)) { /* See comment above regarding PCM restart. */ if (line6pcm->active_urb_out | line6pcm->unlink_urb_out) return -EBUSY; if (!(flags_new & MASK_PCM_ALSA_PLAYBACK)) { err = line6_alloc_playback_buffer(line6pcm); if (err < 0) goto pcm_start_error; } line6pcm->count_out = 0; err = line6_submit_audio_out_all_urbs(line6pcm); if (err < 0) goto pcm_start_error; } return 0; pcm_start_error: __sync_fetch_and_and(&line6pcm->flags, ~channels); return err; }
int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels) { unsigned long flags_old, flags_new; do { flags_old = ACCESS_ONCE(line6pcm->flags); flags_new = flags_old & ~channels; } while (cmpxchg(&line6pcm->flags, flags_old, flags_new) != flags_old); if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_STREAM)) line6_unlink_audio_in_urbs(line6pcm); if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) { line6_wait_clear_audio_in_urbs(line6pcm); line6_free_capture_buffer(line6pcm); } if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_STREAM)) line6_unlink_audio_out_urbs(line6pcm); if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_BUFFER)) { line6_wait_clear_audio_out_urbs(line6pcm); line6_free_playback_buffer(line6pcm); } return 0; }
int line6_pcm_stop(struct snd_line6_pcm *line6pcm, int channels) { unsigned long flags_old = __sync_fetch_and_and(&line6pcm->flags, ~channels); unsigned long flags_new = flags_old & ~channels; if (test_flags(flags_new, flags_old, MASK_CAPTURE)) { line6_unlink_audio_in_urbs(line6pcm); if (!(flags_old & MASK_PCM_ALSA_CAPTURE)) line6_free_capture_buffer(line6pcm); } if (test_flags(flags_new, flags_old, MASK_PLAYBACK)) { line6_unlink_audio_out_urbs(line6pcm); if (!(flags_old & MASK_PCM_ALSA_PLAYBACK)) line6_free_playback_buffer(line6pcm); } return 0; }
int main( int argc , char ** argv) { const char * src_file = argv[1]; const char * target_file = argv[2]; { test_work_area_type * work_area = test_work_area_alloc("ecl_file"); test_work_area_install_file( work_area , src_file ); test_flags( src_file ); test_loadall(src_file , target_file ); test_close_stream1( src_file , target_file); test_close_stream2( src_file , target_file); test_writable( src_file ); test_work_area_free( work_area ); } test_truncated(); exit(0); }
void test_writable(const char * src_file ) { test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" ); char * fname = util_split_alloc_filename( src_file ); test_work_area_copy_file( work_area , src_file ); { test_flags( fname ); ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE); ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat ); test_assert_true( ecl_kw_equal( swat , swat0 )); ecl_kw_iset_float( swat , 0 , 1000.0 ); ecl_file_save_kw( ecl_file , swat ); test_assert_true( ecl_file_writable( ecl_file )); ecl_file_close( ecl_file ); ecl_file = ecl_file_open( fname , 0); swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 )); } test_work_area_free( work_area ); }
/** The real implementation of wildcard expansion is in this function. Other functions are just wrappers around this one. This function traverses the relevant directory tree looking for matches, and recurses when needed to handle wildcrards spanning multiple components and recursive wildcards. */ static int wildcard_expand_internal( const wchar_t *wc, const wchar_t *base_dir, expand_flags_t flags, std::vector<completion_t> &out, std::set<wcstring> &completion_set, std::set<file_id_t> &visited_files ) { /* Points to the end of the current wildcard segment */ const wchar_t *wc_end; /* Variables for traversing a directory */ DIR *dir; /* The result returned */ int res = 0; /* Length of the directory to search in */ size_t base_len; /* Variables for testing for presense of recursive wildcards */ const wchar_t *wc_recursive; int is_recursive; /* Slightly mangled version of base_dir */ const wchar_t *dir_string; // debug( 3, L"WILDCARD_EXPAND %ls in %ls", wc, base_dir ); if( reader_interrupted() ) { return -1; } if( !wc || !base_dir ) { debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); return 0; } if( flags & ACCEPT_INCOMPLETE ) { /* Avoid excessive number of returned matches for wc ending with a * */ size_t len = wcslen(wc); if( len && (wc[len-1]==ANY_STRING) ) { wchar_t * foo = wcsdup( wc ); foo[len-1]=0; int res = wildcard_expand_internal( foo, base_dir, flags, out, completion_set, visited_files ); free( foo ); return res; } } /* Initialize various variables */ dir_string = base_dir[0]==L'\0'?L".":base_dir; if( !(dir = wopendir( dir_string ))) { return 0; } wc_end = wcschr(wc,L'/'); base_len = wcslen( base_dir ); /* Test for recursive match string in current segment */ wc_recursive = wcschr( wc, ANY_STRING_RECURSIVE ); is_recursive = ( wc_recursive && (!wc_end || wc_recursive < wc_end)); /* Is this segment of the wildcard the last? */ if( !wc_end ) { /* Wildcard segment is the last segment, Insert all matching files/directories */ if( wc[0]=='\0' ) { /* The last wildcard segment is empty. Insert everything if completing, the directory itself otherwise. */ if( flags & ACCEPT_INCOMPLETE ) { wcstring next; while(wreaddir(dir, next)) { if( next[0] != L'.' ) { wcstring long_name = make_path( base_dir, next ); if( test_flags( long_name.c_str(), flags ) ) { wildcard_completion_allocate( out, long_name, next, L"", flags); } } } } else { res = 1; insert_completion_if_missing(base_dir, out, completion_set); } } else { /* This is the last wildcard segment, and it is not empty. Match files/directories. */ wcstring next; while (wreaddir(dir, next)) { const wchar_t * const name = next.c_str(); if( flags & ACCEPT_INCOMPLETE ) { const wcstring long_name = make_path( base_dir, next ); /* Test for matches before stating file, so as to minimize the number of calls to the much slower stat function */ std::vector<completion_t> test; if( wildcard_complete( name, wc, L"", 0, test, 0 ) ) { if( test_flags( long_name.c_str(), flags ) ) { wildcard_completion_allocate( out, long_name, name, wc, flags); } } } else { if( wildcard_match2( name, wc, 1 ) ) { const wcstring long_name = make_path(base_dir, next); int skip = 0; if( is_recursive ) { /* In recursive mode, we are only interested in adding files -directories will be added in the next pass. */ struct stat buf; if( !wstat( long_name, &buf ) ) { skip = S_ISDIR(buf.st_mode); } } if (! skip) { insert_completion_if_missing(long_name, out, completion_set); } res = 1; } } } } } if( wc_end || is_recursive ) { /* Wilcard segment is not the last segment. Recursively call wildcard_expand for all matching subdirectories. */ /* wc_str is the part of the wildcarded string from the beginning to the first slash */ wchar_t *wc_str; /* new_dir is a scratch area containing the full path to a file/directory we are iterating over */ wchar_t *new_dir; /* The maximum length of a file element */ long ln=MAX_FILE_LENGTH; char * narrow_dir_string = wcs2str( dir_string ); /* In recursive mode, we look through the directory twice. If so, this rewind is needed. */ rewinddir( dir ); if( narrow_dir_string ) { /* Find out how long the filename can be in a worst case scenario */ ln = pathconf( narrow_dir_string, _PC_NAME_MAX ); /* If not specified, use som large number as fallback */ if( ln < 0 ) ln = MAX_FILE_LENGTH; free( narrow_dir_string ); } new_dir= (wchar_t *)malloc( sizeof(wchar_t)*(base_len+ln+2) ); wc_str = wc_end?wcsndup(wc, wc_end-wc):wcsdup(wc); if( (!new_dir) || (!wc_str) ) { DIE_MEM(); } wcscpy( new_dir, base_dir ); wcstring next; while (wreaddir(dir, next)) { const wchar_t *name = next.c_str(); /* Test if the file/directory name matches the whole wildcard element, i.e. regular matching. */ int whole_match = wildcard_match2( name, wc_str, 1 ); int partial_match = 0; /* If we are doing recursive matching, also check if this directory matches the part up to the recusrive wildcard, if so, then we can search all subdirectories for matches. */ if( is_recursive ) { const wchar_t *end = wcschr( wc, ANY_STRING_RECURSIVE ); wchar_t *wc_sub = wcsndup( wc, end-wc+1); partial_match = wildcard_match2( name, wc_sub, 1 ); free( wc_sub ); } if( whole_match || partial_match ) { struct stat buf; char *dir_str; int stat_res; int new_res; wcscpy(&new_dir[base_len], name ); dir_str = wcs2str( new_dir ); if( dir_str ) { stat_res = stat( dir_str, &buf ); free( dir_str ); if( !stat_res ) { // Insert a "file ID" into visited_files // If the insertion fails, we've already visited this file (i.e. a symlink loop) const file_id_t file_id(buf.st_dev, buf.st_ino); if( S_ISDIR(buf.st_mode) && visited_files.insert(file_id).second) { size_t new_len = wcslen( new_dir ); new_dir[new_len] = L'/'; new_dir[new_len+1] = L'\0'; /* Regular matching */ if( whole_match ) { const wchar_t *new_wc = L""; if( wc_end ) { new_wc=wc_end+1; /* Accept multiple '/' as a single direcotry separator */ while(*new_wc==L'/') { new_wc++; } } new_res = wildcard_expand_internal( new_wc, new_dir, flags, out, completion_set, visited_files ); if( new_res == -1 ) { res = -1; break; } res |= new_res; } /* Recursive matching */ if( partial_match ) { new_res = wildcard_expand_internal( wcschr( wc, ANY_STRING_RECURSIVE ), new_dir, flags | WILDCARD_RECURSIVE, out, completion_set, visited_files); if( new_res == -1 ) { res = -1; break; } res |= new_res; } } } } } } free( wc_str ); free( new_dir ); } closedir( dir ); return res; }
/** The real implementation of wildcard expansion is in this function. Other functions are just wrappers around this one. This function traverses the relevant directory tree looking for matches, and recurses when needed to handle wildcrards spanning multiple components and recursive wildcards. Because this function calls itself recursively with substrings, it's important that the parameters be raw pointers instead of wcstring, which would be too expensive to construct for all substrings. */ static int wildcard_expand_internal(const wchar_t *wc, const wchar_t * const base_dir, expand_flags_t flags, std::vector<completion_t> *out, std::set<wcstring> &completion_set, std::set<file_id_t> &visited_files) { /* Variables for traversing a directory */ DIR *dir; /* The result returned */ int res = 0; // debug( 3, L"WILDCARD_EXPAND %ls in %ls", wc, base_dir ); if (is_main_thread() ? reader_interrupted() : reader_thread_job_is_stale()) { return -1; } if (!wc || !base_dir) { debug(2, L"Got null string on line %d of file %s", __LINE__, __FILE__); return 0; } const size_t base_dir_len = wcslen(base_dir); const size_t wc_len = wcslen(wc); if (flags & ACCEPT_INCOMPLETE) { /* Avoid excessive number of returned matches for wc ending with a * */ if (wc_len > 0 && (wc[wc_len-1]==ANY_STRING)) { wchar_t * foo = wcsdup(wc); foo[wc_len-1]=0; int res = wildcard_expand_internal(foo, base_dir, flags, out, completion_set, visited_files); free(foo); return res; } } /* Determine if we are the last segment */ const wchar_t * const next_slash = wcschr(wc,L'/'); const bool is_last_segment = (next_slash == NULL); const size_t wc_segment_len = next_slash ? next_slash - wc : wc_len; const wcstring wc_segment = wcstring(wc, wc_segment_len); /* Maybe this segment has no wildcards at all. If this is not the last segment, and it has no wildcards, then we don't need to match against the directory contents, and in fact we don't want to match since we may not be able to read it anyways (#2099). Don't even open the directory! */ const bool segment_has_wildcards = wildcard_has(wc_segment, true /* internal, i.e. look for ANY_CHAR instead of ? */); if (! segment_has_wildcards && ! is_last_segment) { wcstring new_base_dir = make_path(base_dir, wc_segment); new_base_dir.push_back(L'/'); /* Skip multiple separators */ assert(next_slash != NULL); const wchar_t *new_wc = next_slash; while (*new_wc==L'/') { new_wc++; } /* Early out! */ return wildcard_expand_internal(new_wc, new_base_dir.c_str(), flags, out, completion_set, visited_files); } /* Test for recursive match string in current segment */ const bool is_recursive = (wc_segment.find(ANY_STRING_RECURSIVE) != wcstring::npos); const wchar_t *base_dir_or_cwd = (base_dir[0] == L'\0') ? L"." : base_dir; if (!(dir = wopendir(base_dir_or_cwd))) { return 0; } /* Is this segment of the wildcard the last? */ if (is_last_segment) { /* Wildcard segment is the last segment, Insert all matching files/directories */ if (wc[0]=='\0') { /* The last wildcard segment is empty. Insert everything if completing, the directory itself otherwise. */ if (flags & ACCEPT_INCOMPLETE) { wcstring next; while (wreaddir(dir, next)) { if (next[0] != L'.') { wcstring long_name = make_path(base_dir, next); if (test_flags(long_name.c_str(), flags)) { wildcard_completion_allocate(out, long_name, next, L"", flags); } } } } else { res = 1; insert_completion_if_missing(base_dir, out, &completion_set); } } else { /* This is the last wildcard segment, and it is not empty. Match files/directories. */ wcstring name_str; while (wreaddir(dir, name_str)) { if (flags & ACCEPT_INCOMPLETE) { const wcstring long_name = make_path(base_dir, name_str); /* Test for matches before stating file, so as to minimize the number of calls to the much slower stat function. The only expand flag we care about is EXPAND_FUZZY_MATCH; we have no complete flags. */ std::vector<completion_t> test; if (wildcard_complete(name_str, wc, L"", NULL, &test, flags & EXPAND_FUZZY_MATCH, 0)) { if (test_flags(long_name.c_str(), flags)) { wildcard_completion_allocate(out, long_name, name_str, wc, flags); } } } else { if (wildcard_match(name_str, wc, true /* skip files with leading dots */)) { const wcstring long_name = make_path(base_dir, name_str); int skip = 0; if (is_recursive) { /* In recursive mode, we are only interested in adding files -directories will be added in the next pass. */ struct stat buf; if (!wstat(long_name, &buf)) { skip = S_ISDIR(buf.st_mode); } } if (! skip) { insert_completion_if_missing(long_name, out, &completion_set); } res = 1; } } } } } if ((! is_last_segment) || is_recursive) { /* Wilcard segment is not the last segment. Recursively call wildcard_expand for all matching subdirectories. */ /* In recursive mode, we look through the directory twice. If so, this rewind is needed. */ rewinddir(dir); /* new_dir is a scratch area containing the full path to a file/directory we are iterating over */ wcstring new_dir = base_dir; wcstring name_str; while (wreaddir(dir, name_str)) { /* Test if the file/directory name matches the whole wildcard element, i.e. regular matching. */ bool whole_match = wildcard_match(name_str, wc_segment, true /* ignore leading dots */); bool partial_match = false; /* If we are doing recursive matching, also check if this directory matches the part up to the recusrive wildcard, if so, then we can search all subdirectories for matches. */ if (is_recursive) { const wchar_t *end = wcschr(wc, ANY_STRING_RECURSIVE); wchar_t *wc_sub = wcsndup(wc, end-wc+1); partial_match = wildcard_match(name_str, wc_sub, true /* ignore leading dots */); free(wc_sub); } if (whole_match || partial_match) { struct stat buf; int new_res; // new_dir is base_dir + some other path components // Replace everything after base_dir with the new path component new_dir.replace(base_dir_len, wcstring::npos, name_str); int stat_res = wstat(new_dir, &buf); if (!stat_res) { // Insert a "file ID" into visited_files // If the insertion fails, we've already visited this file (i.e. a symlink loop) // If we're not recursive, insert anyways (in case we loop back around in a future recursive segment), but continue on; the idea being that literal path components should still work const file_id_t file_id = file_id_t::file_id_from_stat(&buf); if (S_ISDIR(buf.st_mode) && (visited_files.insert(file_id).second || ! is_recursive)) { new_dir.push_back(L'/'); /* Regular matching */ if (whole_match) { const wchar_t *new_wc = L""; if (next_slash) { new_wc=next_slash+1; /* Accept multiple '/' as a single directory separator */ while (*new_wc==L'/') { new_wc++; } } new_res = wildcard_expand_internal(new_wc, new_dir.c_str(), flags, out, completion_set, visited_files); if (new_res == -1) { res = -1; break; } res |= new_res; } /* Recursive matching */ if (partial_match) { new_res = wildcard_expand_internal(wcschr(wc, ANY_STRING_RECURSIVE), new_dir.c_str(), flags | WILDCARD_RECURSIVE, out, completion_set, visited_files); if (new_res == -1) { res = -1; break; } res |= new_res; } } } } } } closedir(dir); return res; }
int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels) { unsigned long flags_old, flags_new, flags_final; int err; do { flags_old = ACCESS_ONCE(line6pcm->flags); flags_new = flags_old | channels; } while (cmpxchg(&line6pcm->flags, flags_old, flags_new) != flags_old); flags_final = flags_old; line6pcm->prev_fbuf = NULL; if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) { /* Invoked multiple times in a row so allocate once only */ if (!line6pcm->buffer_in) { line6pcm->buffer_in = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * line6pcm->max_packet_size, GFP_KERNEL); if (!line6pcm->buffer_in) { err = -ENOMEM; goto pcm_acquire_error; } flags_final |= channels & LINE6_BITS_CAPTURE_BUFFER; } } if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_STREAM)) { /* Waiting for completion of active URBs in the stop handler is a bug, we therefore report an error if capturing is restarted too soon. */ if (line6pcm->active_urb_in | line6pcm->unlink_urb_in) { dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n"); return -EBUSY; } line6pcm->count_in = 0; line6pcm->prev_fsize = 0; err = line6_submit_audio_in_all_urbs(line6pcm); if (err < 0) goto pcm_acquire_error; flags_final |= channels & LINE6_BITS_CAPTURE_STREAM; } if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) { /* Invoked multiple times in a row so allocate once only */ if (!line6pcm->buffer_out) { line6pcm->buffer_out = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * line6pcm->max_packet_size, GFP_KERNEL); if (!line6pcm->buffer_out) { err = -ENOMEM; goto pcm_acquire_error; } flags_final |= channels & LINE6_BITS_PLAYBACK_BUFFER; } } if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_STREAM)) { /* See comment above regarding PCM restart. */ if (line6pcm->active_urb_out | line6pcm->unlink_urb_out) { dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n"); return -EBUSY; } line6pcm->count_out = 0; err = line6_submit_audio_out_all_urbs(line6pcm); if (err < 0) goto pcm_acquire_error; flags_final |= channels & LINE6_BITS_PLAYBACK_STREAM; } return 0; pcm_acquire_error: /* If not all requested resources/streams could be obtained, release those which were successfully obtained (if any). */ line6_pcm_release(line6pcm, flags_final & channels); return err; }
/* This function processes the command line options ('-- and -' pararamteres), changing the structure of parameters accordingly. */ void process_flags (parameter_t* p, const int argc, char** argv) { int c; int option_index; /* The next variables have to be static since getopt_long() has to able to determine their addresses at compilation time (see info libc -> getopt_long()). */ /* dump everything to the same place as ofp */ static int energy_file = FALSE; /* do not dump event numbers by default */ static int dump_eventno = FALSE; /* dump everything to stdout */ static int config_file = FALSE; /* dump everything to the same place as ofp */ static int eventno_file = FALSE; /* by, default, run using local file deposition instead of memory (slower)*/ static int run_fast = FALSE; /* verbose output? */ static int verbose = FALSE; /* When dumping digis, do you want to dump only control? */ static int ctrl = FALSE; /* This global defines the options to take */ static struct option long_options[] = { /* These options set a flag. */ {"control-only", 0, &ctrl, 1}, {"energy-file", 0, &energy_file, 1}, {"dump-eventno", 0, &dump_eventno, 1}, {"config-file", 0, &config_file, 1}, {"eventno-file", 0, &eventno_file, 1}, {"fast-output", 0, &run_fast, 1}, {"verbose", 0, &verbose, 1}, /* These options have arguments */ {"config-weighted", 1, 0, 'c'}, {"dump", 1, 0, 'd'}, {"event-number", 1, 0, 'e'}, {"format", 1, 0, 'f'}, {"dump-energy", 1, 0, 'g'}, {"help", 0, 0, 'h'}, {"input-file", 1, 0, 'i'}, {"eventno-comment", 1, 0, 'k'}, {"layer", 1, 0, 'l'}, {"max-radius", 1, 0, 'm'}, {"normalization", 1, 0, 'n'}, {"file-prefix", 1, 0, 'o'}, {"particle", 1, 0, 'p'}, {"roi-number", 1, 0, 'r'}, {"select", 1, 0, 's'}, {"energy-comment", 1, 0, 't'}, {"load-nevents", 1, 0, 'x'}, {0, 0, 0, 0} }; while (EOF != (c=getopt_long(argc, argv, "c:i:o:k:g:he:r:d:f:p:l:s:n:m:t:x:", long_options, &option_index) ) ) { switch (c) { case 0: /* Got a nil-flagged option */ break; case 'c': /* The limits if using NORM_WEIGHTED_* normalization type */ to_config_weighted(optarg, &p->config_weighted); break; case 'd': /* What to dump? */ if ( strcasecmp(optarg, "digis" ) == 0 ) { p->dump_digis = TRUE; } else if ( strcasecmp(optarg, "rings" ) == 0 ) { p->dump_rings = TRUE; } else if ( strcasecmp(optarg, "udigis" ) == 0 ) { p->dump_uniform_digis = TRUE; } /* this is the default, do nothing */ else if ( strcasecmp(optarg, "rois" ) == 0 ) {} else { fprintf(stderr,"(param)ERROR: Can't recognize format -> %s\n", optarg); exit(EXIT_FAILURE); } break; case 'e': /* dump only event 'number' */ p->event_no = to_valid_long(optarg); p->process_all_events = FALSE; break; case 'f': /* What to dump? */ if ( strcasecmp(optarg, "snns" ) == 0 ) { p->format_snns = TRUE; } /* this is the default, do nothing */ else if ( strcasecmp(optarg, "raw" ) == 0 ) {} else { fprintf(stderr,"(param)ERROR: Can't recognize format -> %s\n", optarg); exit(EXIT_FAILURE); } break; case 'g': /* What energy values would you like printed? */ string2edump(&p->dump_energy,optarg); break; case 'i': { /* input from file 'infile' */ struct stat buf; /* Ok, open the file we're going to work with, in case of error, give up */ if (NULL==(p->ifp=fopen(optarg,"r"))) { fprintf(stderr, "(param) Can't open input file %s\n", optarg); exit(EXIT_FAILURE); } /* If opened the input filename, copy the filename to a safe place, so it can be re-used latter */ strncpy(p->ifname,optarg, MAX_FILENAME); /* get file status, includding optimal buffer block size */ stat(optarg, &buf); /* set the output file buffer to be optimal, or we'll take longer to process the output */ p->ifbuf = (char*)malloc(buf.st_blksize); if (setvbuf(p->ifp, p->ifbuf, _IOFBF, buf.st_blksize) != 0) { fprintf(stderr, "(param) Can't create input file buffer\n"); exit(EXIT_FAILURE); } break; } case 'k': { /* the string to be used when dumping the event numbers */ strncpy(p->event_comment_str, optarg, 4); break; } case 'l': /* Which layers to require? */ string2layer(&p->layer_flags,optarg); break; case 'm': /* The radius for 'unity+' normalization */ p->max_radius = to_valid_double(optarg); break; case 'n': /* Which normalization to use? */ string2normalization(&p->normalization,optarg); break; case 'o': { /* output to file 'outfile' */ strncpy(p->ofhint, optarg, MAX_FILENAME); fprintf(stderr,"(param)WARN: Using file prefix -> %s\n", p->ofhint); p->output_file = TRUE; break; } case 'p': /* What's the target? */ if ( strcasecmp(optarg, "jet" ) == 0 ) { p->particle = JET; } else if ( strcasecmp(optarg, "electron" ) == 0 ) { p->particle = ELECTRON; } else { fprintf(stderr,"(param)ERROR: A type of particle ?? -> %s\n", optarg); exit(EXIT_FAILURE); } break; case 'r': /* dump only the roi 'roi'. This option has only sense with -e comming first! */ p->roi_no = to_valid_long(optarg); p->process_all_rois = FALSE; break; case 's': /* Which layers to print to output? */ string2layer(&p->print_flags,optarg); break; case 't': /* the string to be used when dumping the RoI energy values */ strncpy(p->edump_comment_str, optarg, 4); break; case 'x': /* How many events to load per processing loop */ p->load_events = to_valid_long(optarg); break; case 'h': /* give help */ case '?': default: print_help_msg(stderr,argv[0]); exit(EXIT_SUCCESS); break; } /* end of switch on (c) */ } /* end of while on (getopt) */ /* Set the corresponding variables on parameter_t */ p->energy_file = energy_file; p->dump_eventno = dump_eventno; p->config_file = config_file; p->eventno_file = eventno_file; p->run_fast = run_fast; p->verbose = verbose; p->control_only = ctrl; /* Now we initialize the output environment which may be files or obstacks */ open_output(p); /* Now we test the coherency of some flags */ test_flags(p); /* dump configuration. It shall close the config file automatically. Do *NOT* attempt to write on it afterwards! */ dump_config(p->cfp, p); } /* end of process flags */