static void l_output(char *infile, char *define, int extend, char *outfile) { char *include; definition *def; int foundprogram; char *outfilename; open_input(infile, define); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); f_print(fout, "#include <rpc/rpc.h>\n"); f_print(fout, "#include <sys/time.h>\n"); if (infile && (include = extendfile(infile, ".h"))) { f_print(fout, "#include \"%s\"\n", include); free(include); } foundprogram = 0; while ((def = get_definition())) { foundprogram |= (def->def_kind == DEF_PROGRAM); } if (extend && !foundprogram) { (void)unlink(outfilename); return; } write_stubs(); }
/* * Compile into an RPC service */ static void s_output(int argc, char *argv[], char *infile, char *define, int extend, char *outfile, int nomain) { char *include; definition *def; int foundprogram; char *outfilename; open_input(infile, define); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); f_print(fout, "#include <stdio.h>\n"); f_print(fout, "#include <rpc/rpc.h>\n"); if (infile && (include = extendfile(infile, ".h"))) { f_print(fout, "#include \"%s\"\n", include); free(include); } foundprogram = 0; while ((def = get_definition())) { foundprogram |= (def->def_kind == DEF_PROGRAM); } if (extend && !foundprogram) { (void)unlink(outfilename); return; } if (nomain) { write_programs(NULL); } else { write_most(); do_registers(argc, argv); write_rest(); write_programs("static"); } }
static apr_status_t output_finish(h2_task *task) { if (!task->output.opened) { return open_output(task); } return APR_SUCCESS; }
static void c_output(const char *infile, const char *define, int extend, const char *outfile) { definition *def; char *include; const char *outfilename; long tell; c_initialize(); open_input(infile, define); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); add_warning(); if (infile && (include = extendfile(infile, ".h"))) { f_print(fout, "#include \"%s\"\n", include); free(include); /* .h file already contains rpc/rpc.h */ } else f_print(fout, "#include <rpc/rpc.h>\n"); tell = ftell(fout); while ( (def = get_definition()) ) emit(def); if (extend && tell == ftell(fout)) unlink(outfilename); }
void output_synthetic(hwloc_topology_t topology, const char *filename, int overwrite, int logical __hwloc_attribute_unused, int legend __hwloc_attribute_unused, int verbose_mode __hwloc_attribute_unused) { FILE *output; hwloc_obj_t obj = hwloc_get_root_obj(topology); int arity; if (!obj->symmetric_subtree) { fprintf(stderr, "Cannot output assymetric topology in synthetic format.\n"); fprintf(stderr, "Adding --no-io may help making the topology symmetric.\n"); return; } output = open_output(filename, overwrite); if (!output) { fprintf(stderr, "Failed to open %s for writing (%s)\n", filename, strerror(errno)); return; } arity = obj->arity; while (arity) { char types[64]; obj = obj->first_child; hwloc_obj_type_snprintf(types, sizeof(types), obj, 1); fprintf(output, "%s:%u ", types, arity); arity = obj->arity; } fprintf(output, "\n"); if (output != stdout) fclose(output); }
//! need to be tested void read_output_thisband( const char *filename, float *data_thisband,//!one dimentional ncells array const int nyears, const int nbands, const int ncells, const int start_year, const int year, //! first band is band 1. const int band) { int this_year=year-start_year; int start_pos= this_year*nbands*ncells+(band-1)*nbands*ncells; if(start_pos<0 || start_pos>nyears*nbands*ncells) { printf("[ERROR]: postion error."); exit(EXIT_FAILURE); } FILE *fp=open_output( filename, nyears, nbands, ncells, sizeof(float)); fseek(fp, start_pos, SEEK_SET); fread(data_thisband, sizeof(float), ncells, fp); fclose(fp); }
static int local_init (struct shdec * dec, char *input_filename, char *output_filename) { /* Open input/output stream */ dec->input_fd = dec->output_fd = -1; if (input_filename != NULL && open_input(dec, input_filename)) return -50; if (output_filename != NULL && open_output(dec, output_filename)) return -51; /* Allocate memory for input buffer */ dec->input_buffer = malloc(dec->max_nal_size); if (dec->input_buffer == NULL) return -1; if (dec->input_fd != -1) { /* Fill input buffer */ if ((dec->si_isize = read(dec->input_fd, dec->input_buffer, dec->max_nal_size)) <= 0) { perror(input_filename); return -54; } } return 0; }
/* * generate the dispatch table */ static void t_output (char *infile, char *define, int extend, char *outfile) { definition *def; int foundprogram = 0; char *outfilename; char *incfile; open_input (infile, define); outfilename = extend ? extendfile (infile, outfile) : outfile; incfile = extendfile (infile, ".h"); open_output (infile, outfilename); add_warning (); f_print (fout, "#include \"%s\"\n", incfile); while ((def = get_definition ())) { foundprogram |= (def->def_kind == DEF_PROGRAM); } if (extend && !foundprogram) { (void) unlink (outfilename); return; } write_tables (); }
// Open both input and output in ESD int AudioESound::open_duplex() { device->duplex_channels = 2; device->duplex_bits = 16; open_input(); open_output(); return 0; }
bool open_output_for_unit(compilation_env_t *env, compilation_unit_t *unit, const char *default_extension) { if (env->outname == NULL) { env->outname = get_output_name(unit->original_name, default_extension); } return open_output(env); }
void output_synthetic(struct lstopo_output *loutput, const char *filename) { hwloc_topology_t topology = loutput->topology; FILE *output; int length; char sbuffer[1024]; char * dbuffer = NULL; unsigned nb1, nb2, nb3; if (!hwloc_get_root_obj(topology)->symmetric_subtree) { fprintf(stderr, "Cannot output assymetric topology in synthetic format.\n"); return; } nb1 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_MISC); if (nb1) { fprintf(stderr, "Ignoring %u Misc objects.\n", nb1); fprintf(stderr, "Passing --ignore Misc may remove them.\n"); } nb1 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_BRIDGE); nb2 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PCI_DEVICE); nb3 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_OS_DEVICE); if (nb1 || nb2 || nb3) { fprintf(stderr, "Ignoring %u Bridge, %u PCI device and %u OS device objects\n", nb1, nb2, nb3); fprintf(stderr, "Passing --no-io may remove them.\n"); } length = hwloc_topology_export_synthetic(topology, sbuffer, sizeof(sbuffer), lstopo_export_synthetic_flags); if (length < 0) return; if (length >= sizeof(sbuffer)) { dbuffer = malloc(length+1 /* \0 */); if (!dbuffer) return; length = hwloc_topology_export_synthetic(topology, dbuffer, length+1, lstopo_export_synthetic_flags); if (length < 0) goto out; } output = open_output(filename, loutput->overwrite); if (!output) { fprintf(stderr, "Failed to open %s for writing (%s)\n", filename, strerror(errno)); goto out; } fprintf(output, "%s\n", dbuffer ? dbuffer : sbuffer); if (output != stdout) fclose(output); out: if (dbuffer) free(dbuffer); }
bool do_copy_file(compilation_env_t *env, compilation_unit_t *unit) { if (!open_input(unit)) return false; if (!open_output(env)) return false; copy_file(env->out, unit->input); close_output(env); return close_input(unit); }
static int sun_discard_playing(void) { void (* orig_alarm_handler)(); orig_alarm_handler = signal(SIGALRM, null_proc); ualarm(10000, 10000); close_output(); ualarm(0, 0); signal(SIGALRM, orig_alarm_handler); return open_output(); }
static void print (const gchar *message, ...) { va_list args; if (output_stream == NULL) open_output(); va_start (args, message); vfprintf (output_stream, message, args); va_end (args); fputc('\n', output_stream); }
void calculate_sky_patches (int dc_direct_resolution, int dif_pts, int dir_pts, int *number_direct_coefficients) { int i,j; double alt, azi; FILE *DIFFUSE_POINTS_FILE; FILE *DIRECT_POINTS_FILE; get_dc(dc_direct_resolution,number_direct_coefficients); /* calculate daylight coefficients depending on site */ if (dir_pts) {/* print direct daylight coefficients */ DIRECT_POINTS_FILE=open_output(direct_points_file); for(i=0; i< *number_direct_coefficients ; i++){fprintf(DIRECT_POINTS_FILE," %f %f %f \n",direct_pts[i][0],direct_pts[i][1],direct_pts[i][2]);} i=close_file(DIRECT_POINTS_FILE); } if (dif_pts) {/* print diffuse daylight coefficients */ DIFFUSE_POINTS_FILE=open_output(diffuse_points_file); for(i=0; i<= 144; i++){fprintf(DIFFUSE_POINTS_FILE," %f %f 0.0 \n",diffuse_pts[i][0],diffuse_pts[i][1]);} i=close_file(DIFFUSE_POINTS_FILE); } /* print radiance file for direct suns */ if(dc_coupling_mode ==2){ if(!strcmp(direct_radiance_file,"")){ error(USER, "shadow testing turned on but no direct radiance file specified in header!"); }else{ DIFFUSE_POINTS_FILE=open_output(direct_radiance_file); for(j=0; j< *number_direct_coefficients; j++){ fprintf(DIFFUSE_POINTS_FILE,"void light solar%d\n0 \n0 \n3 1000 1000 1000\n\n",j+1); fprintf(DIFFUSE_POINTS_FILE,"solar%d source sun\n0\n0\n",j+1); alt = radians(90 - direct_pts[j][1]); azi = -radians(direct_pts[j][2] + 90); fprintf(DIFFUSE_POINTS_FILE,"4 %f %f %f 0.533\n\n",sin(alt)*cos(azi),sin(alt)*sin(azi),cos(alt)); } i=close_file(DIFFUSE_POINTS_FILE); } } }
int mpl_postsolve(MPL *mpl, char *file) { if (!(mpl->phase == 3 && !mpl->flag_p)) fault("mpl_postsolve: invalid call sequence"); /* set up error handler */ if (setjmp(mpl->jump)) goto done; /* perform postsolving */ open_output(mpl, file, "a"); postsolve_model(mpl); close_output(mpl); /* postsolving phase has been finished */ print("Model has been successfully processed"); done: /* return to the calling program */ return mpl->phase; }
void spy_dump (spy_t s) { tabstop t; open_output(); spy_accumulate_children_stats(s); if (mode == SPY_DISPLAY_SAMPLES) { display_samples(s); } else { init_tabstop(&t); set_tabstop(s, &t); dump_header(&t); spy_dump_internal(s, &t); } }
int AudioALSA::write_buffer(char *buffer, int size) { // Don't give up and drop the buffer on the first error. int attempts = 0; int done = 0; int samples = size / (device->out_bits / 8) / device->get_ochannels(); if(!get_output()) return 0; while(attempts < 2 && !done && !interrupted) { // Buffers written must be equal to period_time // Update timing snd_pcm_sframes_t delay; snd_pcm_delay(get_output(), &delay); snd_pcm_avail_update(get_output()); device->Thread::enable_cancel(); if(snd_pcm_writei(get_output(), buffer, samples) < 0) { device->Thread::disable_cancel(); printf("AudioALSA::write_buffer underrun at sample %" PRId64 "\n", device->current_position()); // snd_pcm_resume(get_output()); close_output(); open_output(); attempts++; } else { device->Thread::disable_cancel(); done = 1; } } if(done) { timer_lock->lock("AudioALSA::write_buffer"); this->delay = delay; timer->update(); samples_written += samples; timer_lock->unlock(); } return 0; }
/* ** ** main function ** */ int main( int argc, char *argv[] ) { #ifdef AMIGA STRPTR version_string = "$VER: 0.6.3 hsc (30.8.1995)"; #endif BOOL ok = FALSE; /* set program information */ set_prginfo( "hsc", "Tommy-Saftwörx", 0, 6, 3, "HTML Sucks Completely", "This is FreeWare!" ); #ifdef UMEM_TRACKING /* display a memory tracking report */ /* at end of execution */ atexit( atexit_uglymemory ); #endif /* use cleanup() as additional exit func */ atexit( cleanup ); /* ** main procedure */ if ( args_ok( argc, argv ) ) { /* display programm-info if requested */ if ( verbose ) fprintf_prginfo( stderr ); if ( open_error() /* init error file */ && open_output() /* open output file */ && config_ok() ) /* read config */ { /* include file parsed in args */ ok = include_hsc( inpfilename, outfile, IH_PARSE_END ); } } /* TODO: set return value 0,5,10,20 */ /* ->define symbols like RC_FAIL, vars like any_warn */ if ( ok ) return( 0 ); /* successful */ else return( 20 ); }
int mpl_generate(MPL *mpl, char *file) { if (!(mpl->phase == 1 || mpl->phase == 2)) fault("mpl_generate: invalid call sequence"); /* set up error handler */ if (setjmp(mpl->jump)) goto done; /* generate model */ mpl->phase = 3; open_output(mpl, file, "w"); generate_model(mpl); close_output(mpl); /* build problem instance */ build_problem(mpl); /* generation phase has been finished */ print("Model has been successfully generated"); done: /* return to the calling program */ return mpl->phase; }
static exit_values_ty indent_multiple_files(void) { exit_values_ty exit_status = total_success; int i; /* When multiple input files are specified, make a backup copy * and then output the indented code into the same filename. */ for (i = 0; input_files; i++, input_files--) { exit_values_ty status; struct stat file_stats; in_name = in_file_names[i]; out_name = in_file_names[i]; current_input = read_file(in_file_names[i], &file_stats); open_output(out_name, "r+"); make_backup(current_input, &file_stats); /* Aborts on failure. */ /* We have safely made a backup so the open file can be truncated. */ reopen_output_trunc(out_name); reset_parser(); status = indent (current_input); if (status > exit_status) { exit_status = status; } if (settings.preserve_mtime) { close_output(&file_stats, out_name); } else { close_output(NULL, out_name); } } return exit_status; }
void output_synthetic(hwloc_topology_t topology, const char *filename, int overwrite, int logical __hwloc_attribute_unused, int legend __hwloc_attribute_unused, int verbose_mode __hwloc_attribute_unused) { FILE *output; int length; char sbuffer[1024]; char * dbuffer = NULL; if (!hwloc_get_root_obj(topology)->symmetric_subtree) { fprintf(stderr, "Cannot output assymetric topology in synthetic format.\n"); fprintf(stderr, "Adding --no-io may help making the topology symmetric.\n"); return; } length = hwloc_topology_export_synthetic(topology, sbuffer, sizeof(sbuffer), lstopo_export_synthetic_flags); if (length < 0) return; if (length >= sizeof(sbuffer)) { dbuffer = malloc(length+1 /* \0 */); if (!dbuffer) return; length = hwloc_topology_export_synthetic(topology, dbuffer, length+1, lstopo_export_synthetic_flags); if (length < 0) goto out; } output = open_output(filename, overwrite); if (!output) { fprintf(stderr, "Failed to open %s for writing (%s)\n", filename, strerror(errno)); goto out; } fprintf(output, "%s\n", dbuffer ? dbuffer : sbuffer); if (output != stdout) fclose(output); out: if (dbuffer) free(dbuffer); }
/* ** ** main function ** */ int main( int argc, char *argv[] ) { BOOL ok = FALSE; /* set program information */ set_prginfo( "hsc", "Tommy-Saftwörx", 0, 9, 2, "HTML Sucks Completely", "This is FreeWare." ); #ifdef UMEM_TRACKING /* display a memory tracking report */ /* at end of execution */ atexit( atexit_uglymemory ); #endif /* use cleanup() as additional exit func */ atexit( cleanup ); /* ** main procedure */ if ( args_ok( argc, argv ) ) { /* display programm-info if requested */ if ( verbose ) fprintf_prginfo( stderr ); if ( open_error() /* init error file */ && open_output() /* open output file */ && config_ok() /* read config */ && include_ok() ) /* read include files */ { /* include file parsed in args */ ok = include_hsc_file( inpfilename, outfile, IH_PARSE_END ); } } return( return_code ); }
void spy_dump_internal (spy_t s, tabstop *t) { long average = 0; long median = 0; long std_var; long n_samples; if (s->n == 0) return; n_samples = s->n > s->n_samples ? s->n_samples : s->n; open_output(); average = spy_average(s); median = spy_median(s); std_var = spy_std_variation(s); if (!(mode & SPY_DISPLAY_CYCLES)) { print_fill(s->name, t->name); print_fill(r_dtoa(cycle_to_usec(s->min)), t->min); print_fill(r_dtoa(cycle_to_usec(s->max)), t->max); print_fill(r_dtoa(cycle_to_usec(average)), t->mean); print_fill(r_dtoa(cycle_to_usec(median)), t->median); print_fill(r_dtoa(cycle_to_usec(s->cumulative)), t->total); print_fill(itoa(s->n), t->hits); putc('\n', out); } else { fprintf(out, "%-9s: %5ld(%5.2f), %5ld(%5.2f), %5ld(%5.2f), %5ld(%5.2f), %5ld(%5.2f), %5ld.\n", s->name, s->min, cycle_to_usec(s->min), s->max, cycle_to_usec(s->max), average, cycle_to_usec(average), median, cycle_to_usec(median), s->cumulative, cycle_to_usec(s->cumulative), s->n); } close_output(); }
void spy_dump_all () { int i; unsigned long total = 0; tabstop t; spy_t s; open_output(); init_tabstop(&t); for (i = 0; i < nspys; i++) { s = &spys[i]; spy_accumulate_children_stats(s); if (s->n == 0) continue; if (mode != SPY_DISPLAY_SAMPLES) set_tabstop(s, &t); total += spys[i].cumulative; } if (mode == SPY_DISPLAY_SAMPLES) { for (i = 0; i < nspys; i++) { s = &spys[i]; if (s->n == 0) continue; display_samples(s); } } else { dump_header(&t); for (i = 0; i < nspys; i++) { s = &spys[i]; if (s->n == 0) continue; spy_dump_internal(s, &t); } if (mode & SPY_DISPLAY_TOTAL) { fprintf(out, "total: %s.\n", r_dtoa(cycle_to_usec(total))); } } }
int main(int argc, char **argv) { int i; if(argc == 1) { usage(); return 1; } parse_options(argc,argv); if(!quiet) version(); if(optind >= argc) { fprintf(stderr, _("ERROR: No input files specified. Use -h for help\n")); return 1; } if(argc - optind > 1 && outfilename && !raw) { fprintf(stderr, _("ERROR: Can only specify one input file if output filename is specified\n")); return 1; } if(outfilename && raw) { FILE *infile, *outfile; char *infilename; if(!strcmp(outfilename, "-")) { free(outfilename); outfilename = NULL; } outfile = open_output(outfilename); if(!outfile) return 1; for(i=optind; i < argc; i++) { if(!strcmp(argv[i], "-")) { infilename = NULL; infile = open_input(NULL); } else { infilename = argv[i]; infile = open_input(argv[i]); } if(!infile) { fclose(outfile); free(outfilename); return 1; } if(decode_file(infile, outfile, infilename, outfilename)) { fclose(outfile); return 1; } } fclose(outfile); } else { for(i=optind; i < argc; i++) { char *in, *out; FILE *infile, *outfile; if(!strcmp(argv[i], "-")) in = NULL; else in = argv[i]; if(outfilename) { if(!strcmp(outfilename, "-")) out = NULL; else out = outfilename; } else { char *end = strrchr(argv[i], '.'); end = end?end:(argv[i] + strlen(argv[i]) + 1); out = malloc(strlen(argv[i]) + 10); strncpy(out, argv[i], end-argv[i]); out[end-argv[i]] = 0; if(raw) strcat(out, ".raw"); else strcat(out, ".wav"); } infile = open_input(in); if(!infile) { if(outfilename) free(outfilename); return 1; } outfile = open_output(out); if(!outfile) { fclose(infile); return 1; } if(decode_file(infile, outfile, in, out)) { fclose(outfile); return 1; } if(!outfilename) free(out); fclose(outfile); } } if(outfilename) free(outfilename); return 0; }
void *recorder_thread(void *ptr) { struct camera *cam = (struct camera *)ptr; struct motion_detection md; AVPacket packet; AVFrame *frame; int got_frame, ret; unsigned int cnt = 0; time_t first_activity = 0; time_t last_activity = 0; if(open_camera(cam) < 0) return NULL; if(open_output(cam) < 0) return NULL; av_dump_format(cam->context, 0, cam->context->filename, 0); av_dump_format(cam->output_context, 0, cam->output_context->filename, 1); md.cam = cam; md.prev = cvCreateImage(cvSize(cam->codec->width, cam->codec->height), IPL_DEPTH_8U, 1); md.cur = cvCreateImage(cvSize(cam->codec->width, cam->codec->height), IPL_DEPTH_8U, 1); md.silh = cvCreateImage(cvSize(cam->codec->width, cam->codec->height), IPL_DEPTH_8U, 1); cvZero(md.prev); cvZero(md.cur); cvZero(md.silh); md.img_convert_ctx = sws_getContext( cam->codec->width, cam->codec->height, cam->codec->pix_fmt, cam->codec->width, cam->codec->height, PIX_FMT_GRAY8, SWS_BICUBIC, NULL, NULL, NULL); md.buffer = (uint8_t*)av_malloc(3 * cam->codec->width * cam->codec->height); int got_key_frame = 0, first_detection = 1; frame = avcodec_alloc_frame(); if(!frame) { av_err_msg("avcodec_alloc_frame", 0); return NULL; } while(1) { cam->last_io = time(NULL); if((ret = av_read_frame(cam->context, &packet)) < 0) { if(ret == AVERROR_EOF) break; else av_err_msg("av_read_frame", ret); } if(packet.stream_index == cam->video_stream_index) { // start on keyframe if(!got_key_frame && !(packet.flags & AV_PKT_FLAG_KEY)) { continue; } got_key_frame = 1; avcodec_get_frame_defaults(frame); got_frame = 0; cnt = (cnt + 1) % cam->analize_frames; if(cnt == 0) { if((ret = avcodec_decode_video2(cam->codec, frame, &got_frame, &packet)) < 0) av_err_msg("avcodec_decode_video2", ret); if(got_frame) { if(detect_motion(&md, frame)) { if(first_activity == 0) first_activity = time(NULL); last_activity = time(NULL); } else { if(first_activity > 0 && time(NULL) - last_activity > cam->motion_delay) { if(!first_detection) db_create_event(cam->id, first_activity, last_activity); else first_detection = 0; first_activity = 0; } } } if(time(NULL) - cam->last_screenshot > 60 && (packet.flags & AV_PKT_FLAG_KEY)) { char fname[128]; snprintf(fname, sizeof(fname), "%s/%s/screenshot.png", store_dir, cam->name); cvSaveImage(fname, md.cur, 0); cam->last_screenshot = time(NULL); } } packet.stream_index = cam->output_stream->id; if((ret = av_write_frame(cam->output_context, &packet)) < 0) av_err_msg("av_write_frame", ret); pthread_mutex_lock(&cam->consumers_lock); for(l1 *p = cam->cam_consumers_list; p != NULL; p = p->next) { struct cam_consumer *consumer = (struct cam_consumer *)p->value; if(!consumer->screen->active) continue; if(consumer->screen->tmpl_size == 1) { packet.stream_index = 0; if((ret = av_write_frame(consumer->screen->rtp_context, &packet)) < 0) av_err_msg("av_write_frame", ret); } else { if(!got_frame) { if((ret = avcodec_decode_video2(cam->codec, frame, &got_frame, &packet)) < 0) { av_err_msg("avcodec_decode_video2", ret); break; } } if(got_frame) copy_frame_to_consumer(frame, cam->codec->height, consumer); } } pthread_mutex_unlock(&cam->consumers_lock); } av_free_packet(&packet); if(!cam->active) { break; } if(time(NULL) - cam->file_started_at > 60 * 60) { db_update_videofile(cam); close_output(cam); open_output(cam); got_key_frame = 0; } } db_update_videofile(cam); close_output(cam); if((ret = avcodec_close(cam->codec)) < 0) av_err_msg("avcodec_close", ret); avformat_close_input(&cam->context); av_free(frame); cvReleaseImage(&md.prev); cvReleaseImage(&md.cur); cvReleaseImage(&md.silh); av_free(md.buffer); sws_freeContext(md.img_convert_ctx); return NULL; }
void output_console(struct lstopo_output *loutput, const char *filename) { hwloc_topology_t topology = loutput->topology; unsigned topodepth; int verbose_mode = loutput->verbose_mode; int logical = loutput->logical; FILE *output; output = open_output(filename, loutput->overwrite); if (!output) { fprintf(stderr, "Failed to open %s for writing (%s)\n", filename, strerror(errno)); return; } topodepth = hwloc_topology_get_depth(topology); /* * if verbose_mode == 0, only print the summary. * if verbose_mode == 1, only print the topology tree. * if verbose_mode > 1, print both. */ if (lstopo_show_only != (hwloc_obj_type_t)-1) { if (verbose_mode > 1) fprintf(output, "Only showing %s objects\n", hwloc_obj_type_string(lstopo_show_only)); output_only (topology, hwloc_get_root_obj(topology), output, logical, verbose_mode); } else if (verbose_mode >= 1) { output_topology (topology, hwloc_get_root_obj(topology), NULL, output, 0, logical, verbose_mode); fprintf(output, "\n"); } if ((verbose_mode > 1 || !verbose_mode) && lstopo_show_only == (hwloc_obj_type_t)-1) { hwloc_lstopo_show_summary(output, topology); } if (verbose_mode > 1 && lstopo_show_only == (hwloc_obj_type_t)-1) { const struct hwloc_distances_s * distances; unsigned depth; for (depth = 0; depth < topodepth; depth++) { distances = hwloc_get_whole_distance_matrix_by_depth(topology, depth); if (!distances || !distances->latency) continue; fprintf(output, "relative latency matrix between %ss (depth %u) by %s indexes:\n", hwloc_obj_type_string(hwloc_get_depth_type(topology, depth)), depth, logical ? "logical" : "physical"); hwloc_utils_print_distance_matrix(output, topology, hwloc_get_root_obj(topology), distances->nbobjs, depth, distances->latency, logical); } } if (verbose_mode > 1 && lstopo_show_only == (hwloc_obj_type_t)-1) { hwloc_const_bitmap_t complete = hwloc_topology_get_complete_cpuset(topology); hwloc_const_bitmap_t topo = hwloc_topology_get_topology_cpuset(topology); hwloc_const_bitmap_t allowed = hwloc_topology_get_allowed_cpuset(topology); if (!hwloc_bitmap_isequal(topo, complete)) { hwloc_bitmap_t unknown = hwloc_bitmap_alloc(); char *unknownstr; hwloc_bitmap_copy(unknown, complete); hwloc_bitmap_andnot(unknown, unknown, topo); hwloc_bitmap_asprintf(&unknownstr, unknown); fprintf (output, "%d processors not represented in topology: %s\n", hwloc_bitmap_weight(unknown), unknownstr); free(unknownstr); hwloc_bitmap_free(unknown); } if (!hwloc_bitmap_isequal(topo, allowed)) { hwloc_bitmap_t disallowed = hwloc_bitmap_alloc(); char *disallowedstr; hwloc_bitmap_copy(disallowed, topo); hwloc_bitmap_andnot(disallowed, disallowed, allowed); hwloc_bitmap_asprintf(&disallowedstr, disallowed); fprintf(output, "%d processors represented but not allowed: %s\n", hwloc_bitmap_weight(disallowed), disallowedstr); free(disallowedstr); hwloc_bitmap_free(disallowed); } if (!hwloc_topology_is_thissystem(topology)) fprintf (output, "Topology not from this system\n"); } if (output != stdout) fclose(output); }
/* Open an audio output module, trying modules in list (comma-separated). */ audio_output_t* open_output_module( const char* names ) { mpg123_module_t *module = NULL; audio_output_t *ao = NULL; int result = 0; char *curname, *modnames; if(param.usebuffer || names==NULL) return NULL; /* Use internal code. */ if(param.outmode != DECODE_AUDIO) return open_fake_module(); modnames = strdup(names); if(modnames == NULL) { error("Error allocating memory for module names."); return NULL; } /* Now loop over the list of possible modules to find one that works. */ curname = strtok(modnames, ","); while(curname != NULL) { char* name = curname; curname = strtok(NULL, ","); if(param.verbose > 1) fprintf(stderr, "Trying output module %s.\n", name); /* Open the module, initial check for availability+libraries. */ module = open_module( "output", name ); if(module == NULL) continue; /* Check if module supports output */ if(module->init_output == NULL) { error1("Module '%s' does not support audio output.", name); close_module(module); continue; /* Try next one. */ } /* Allocation+initialization of memory for audio output type. */ ao = alloc_audio_output(); if(ao==NULL) { error("Failed to allocate audio output structure."); close_module(module); break; /* This is fatal. */ } /* Call the init function */ ao->device = param.output_device; ao->flags = param.output_flags; /* Should I do funny stuff with stderr file descriptor instead? */ if(curname == NULL) { if(param.verbose > 1) fprintf(stderr, "Note: %s is the last output option... showing you any error messages now.\n", name); } else ao->auxflags |= MPG123_OUT_QUIET; /* Probing, so don't spill stderr with errors. */ ao->is_open = FALSE; ao->module = module; /* Need that to close module later. */ result = module->init_output(ao); if(result == 0) { /* Try to open the device. I'm only interested in actually working modules. */ result = open_output(ao); close_output(ao); } else error2("Module '%s' init failed: %i", name, result); if(result!=0) { /* Try next one... */ close_module(module); free(ao); ao = NULL; } else { /* All good, leave the loop. */ if(param.verbose > 1) fprintf(stderr, "Output module '%s' chosen.\n", name); ao->auxflags &= ~MPG123_OUT_QUIET; break; } } free(modnames); if(ao==NULL) error1("Unable to find a working output module in this list: %s", names); return ao; }
void parse(const char *filename) { FILE *f, *h, *cpp; const char *ext, *basename; char *input; long len; /* make sure the extension is .async */ ext = strrchr(filename, '.'); if(ext == 0 || strcmp(".async", ext) != 0) { return; } /* open the input file */ f = fopen(filename, "rb"); if(f == 0) { fprintf(stderr, "%s:0: error: cannot open file\n", filename); return; } /* open the output files */ basename = strrchr(filename, '/'); if(basename == 0) { basename = strrchr(filename, '\\'); if(basename == 0) { basename = filename; } else { basename++; } } else { basename++; } len = static_cast<long>(strlen(basename) - size_t(6)); // strlen(".async") == 6 h = open_output(basename, len, ".h"); cpp = open_output(basename, len, ".c++"); if(h == 0 || cpp == 0) { if(h != 0) { fclose(h); } if(cpp != 0) { fclose(cpp); } fclose(f); return; } input = read_input(filename, f); if(input != 0) { // mo_event.h needs to be included from within the .async file! //fprintf(h, "#include <mo_event.h>\n"); // auto-include the header fprintf(cpp, "#include \"%.*s.h\"\n", static_cast<int>(len), basename); remove_cr(input); convert_file(filename, input, h, cpp); delete [] input; // Need extra newline at end of file to keep compiler from complaining. fprintf(h, "\n" ); } fclose(f); fclose(h); fclose(cpp); }