int input_argument_free ( void ) { int fail,n; char outfile[80],ch; printf("\nReading and writing a polynomial system ...\n"); fail = read_standard_target_system(); if(v==1) printf("-> read_target_system returns %d\n",fail); fail = copy_target_system_to_container(); if(v==1) printf("-> copy_target_system_to_container returns %d\n",fail); printf("\nThe system read :\n"); fail = print_system(); if(v==1) printf("-> print_system returns %d\n",fail); printf("\nGive name of the output file : "); scanf("%s",outfile); n = (int) strlen(outfile); fail = define_output_file_with_string(n,outfile); if(v==1) printf("-> define_output_file_with_string returns %d\n",fail); fail = print_system(); if(v==1) printf("-> print_system returns %d\n",fail); fail = write_string_to_defined_output_file(21,"\nTITLE : some system\n"); if(v==1) printf("-> write_string_to_defined_output_file returns %d\n",fail); fail = close_output_file(); if(v==1) printf("-> close_output_file returns %d\n",fail); return 0; }
void *write_thread(void *_ts) { struct ts *ts = _ts; struct packet *packet; mode_t umask_val = umask(0); dir_perm = (0777 & ~umask_val) | (S_IWUSR | S_IXUSR); set_thread_name("tsdump-write"); while ((packet = queue_get(ts->packet_queue))) { if (!packet->data_len) continue; p_dbg1(" - Got packet %d, size: %u, file_time:%lu packet_time:%lu depth:%d\n", packet->num, packet->data_len, ALIGN_DOWN(packet->ts.tv_sec, ts->rotate_secs), packet->ts.tv_sec, ts->packet_queue->items); handle_files(ts, packet); if (ts->output_fd > -1) { p_dbg2(" - Writing into fd:%d size:%d file:%s\n", ts->output_fd, packet->data_len, ts->output_filename); ssize_t written = write(ts->output_fd, packet->data, packet->data_len); if (written != packet->data_len) { p_err("Can not write data (fd:%d written %zd of %d file:%s)", ts->output_fd, written, packet->data_len, ts->output_filename); } } free_packet(packet); } close_output_file(ts, NO_UNLINK); return NULL; }
status_t rdef_compile(const char *outputFile) { clear_error(); if (outputFile == NULL || outputFile[0] == '\0') { rdef_err = B_BAD_VALUE; return rdef_err; } rsrc_file = outputFile; rdef_err = open_output_file(); if (rdef_err != B_OK) return rdef_err; for (ptr_iter_t i = input_files.begin(); (i != input_files.end()) && (rdef_err == B_OK); ++i) { char *path = (char *)*i; AddIncludeDir add(path); compile_file(path); } close_output_file(); return rdef_err; }
static void handle_files(struct ts *ts, struct packet *packet) { int file_time = ALIGN_DOWN(packet->ts.tv_sec, ts->rotate_secs); // Is this file already created? if (file_time <= ts->output_startts) return; close_output_file(ts, UNLINK_OLD); format_output_filename(ts, file_time); /* * When tsdumper2 is started, try to continue writing into "current" file. * This allows the program to be killed/restarted. * * If current file does not exist, create new file with the time of the start * (not aligned to rotate_secs). */ int append = 0; if (ts->output_fd < 0) { // First file (or error). append = file_exists(ts->output_filename); if (!append) { // Create first file *NOT ALIGNED* format_output_filename(ts, packet->ts.tv_sec); } } ts->output_fd = append ? append_output_file(ts) : create_output_file(ts); }
void generate_lr_parser (string fname, string_list predefs) { full_verbose = 1; verbose = 1; warning ("generating lr parser..."); open_output_file (fname, "lr", "c"); generate_std_includes (predefs); generate_meta_rules (); close_output_file (); };
/* -- open the output file -- */ void open_fout(void) { int i; char fnm[FILENAME_MAX]; strcpy(fnm, outfn); i = strlen(fnm) - 1; if (i < 0) { strcpy(fnm, svg || epsf > 1 ? "Out.xhtml" : OUTPUTFILE); } else if (i != 0 || fnm[0] != '-') { if (fnm[i] == '=' && in_fname) { char *p; if ((p = strrchr(in_fname, DIRSEP)) == NULL) p = in_fname; else p++; strcpy(&fnm[i], p); strext(fnm, svg || epsf > 1 ? "xhtml" : "ps"); } else if (fnm[i] == DIRSEP) { strcpy(&fnm[i + 1], svg || epsf > 1 ? "Out.xhtml" : OUTPUTFILE); } #if 0 /*fixme: fnm may be a directory*/ else ... #endif } if (svg == 1 && (i != 0 || fnm[0] != '-')) { cutext(fnm); i = strlen(fnm) - 1; if (strncmp(fnm, outfnam, i) != 0) nepsf = 0; sprintf(&fnm[i + 1], "%03d.svg", ++nepsf); } else if (strcmp(fnm, outfnam) == 0) { return; /* same output file */ } close_output_file(); strcpy(outfnam, fnm); if (i != 0 || fnm[0] != '-') { if ((fout = fopen(fnm, "w")) == NULL) { error(1, NULL, "Cannot create output file %s - abort", fnm); exit(EXIT_FAILURE); } } else { fout = stdout; } }
/* Write the filesystem image to a file */ void write_ext4_image(int fd, int gz, int sparse, int crc, int wipe) { int ret = 0; struct output_file *out = open_output_fd(fd, gz, sparse, count_sparse_chunks(), crc, wipe); if (!out) return; for_each_data_block(ext4_write_data_block, ext4_write_data_file, ext4_write_fill_block, out); pad_output_file(out, info.len); close_output_file(out); }
/** * \brief Remove storage plugin. * * This function is called when we don't want to use this storage plugin * anymore. All it does is that it cleans up after the storage plugin. * * \param[in] config the plugin specific configuration structure * \return 0 on success, negative value otherwise */ int storage_close(void **config) { struct ipfix_config *conf; conf = (struct ipfix_config *) *config; close_output_file(conf); if (conf->bcounter == 0) { /* current output file is empty, get rid of it */ unlink(conf->file); } xmlFree(conf->xml_file); free(conf->file); free(conf); *config = NULL; return 0; }
void generate_leftcorner_parser (string basename, string_list predefs) { compute_leftcorner_relations (); generate_goal_for_rules (); generate_goal_relation (); warning ("generating left corner parser..."); open_output_file (basename, "leftcorner", "c"); generate_std_includes (predefs); code_lattices (); code_lexicon (); generate_meta_rules (); generate_rule_declarations (); code_nodenrs (basename); if (editor) generate_enter_templates (); warning ("coding syntax rules..."); code_goal_for_rules (); code_goal_relation (); generate_parser_routines (); warning ("coding postamble and main..."); generate_start_rule (predefs); generate_module_interface (basename, predefs); generate_main (basename); close_output_file (); };
void cleanup (struct shenc * shenc) { double time; if (shenc->enc_framerate) { time = (double)framerate_elapsed_time (shenc->enc_framerate); time /= 1000000; fprintf (stderr, "Elapsed time (encode): %0.3g s\n", time); fprintf (stderr, "Encoded %d frames (%.2f fps)\n", shenc->enc_framerate->nr_handled, framerate_mean_fps (shenc->enc_framerate)); framerate_destroy (shenc->enc_framerate); } if (shenc->encoder != NULL) shcodecs_encoder_close(shenc->encoder); close_input_file(&shenc->ainfo); close_output_file(&shenc->ainfo); free (shenc); }
static void do_export (vbi_pgno pgno, vbi_subno subno, double timestamp) { vbi_page *pg; vbi_bool success; if (option_delay > 1) { --option_delay; return; } if (pgno >= 0x100) { if (0 != option_override_cs) { pg = vbi_decoder_get_page (vbi, NULL /* current network */, pgno, subno, VBI_HEADER_ONLY, option_header_only, VBI_PADDING, option_padding, VBI_PANELS, option_panels, VBI_NAVIGATION, option_navigation, VBI_HYPERLINKS, option_hyperlinks, VBI_PDC_LINKS, option_pdc_links, VBI_WST_LEVEL, VBI_WST_LEVEL_3p5, VBI_OVERRIDE_CHARSET_0, option_override_cs, VBI_END); } else { pg = vbi_decoder_get_page (vbi, NULL /* current network */, pgno, subno, VBI_HEADER_ONLY, option_header_only, VBI_PADDING, option_padding, VBI_PANELS, option_panels, VBI_NAVIGATION, option_navigation, VBI_HYPERLINKS, option_hyperlinks, VBI_PDC_LINKS, option_pdc_links, VBI_WST_LEVEL, VBI_WST_LEVEL_3p5, VBI_DEFAULT_CHARSET_0, option_default_cs, VBI_END); } } else { pg = vbi_decoder_get_page (vbi, NULL /* current network */, pgno, subno, VBI_PADDING, option_padding, VBI_DEFAULT_FOREGROUND, option_default_fg, VBI_DEFAULT_BACKGROUND, option_default_bg, VBI_ROW_CHANGE, option_row_update, VBI_END); } assert (NULL != pg); if (option_dump_pg) { page_dump (pg); } switch (option_target) { char *file_name; void *buffer; void *buffer2; FILE *fp; size_t size; ssize_t ssize; case 1: buffer = malloc (1 << 20); if (NULL == buffer) no_mem_exit (); ssize = vbi_export_mem (ex, buffer, 1 << 20, pg); success = (ssize >= 0); if (success) { ssize_t ssize2; fp = open_output_file (pgno, subno); if (1 != fwrite (buffer, ssize, 1, fp)) write_error_exit (/* msg: errno */ NULL); close_output_file (fp); /* Test. */ ssize2 = vbi_export_mem (ex, buffer, 0, pg); assert (ssize == ssize2); assert (ssize > 0); ssize2 = vbi_export_mem (ex, buffer, ssize - 1, pg); assert (ssize == ssize2); } free (buffer); break; case 2: buffer = NULL; buffer2 = vbi_export_alloc (ex, &buffer, &size, pg); /* Test. */ assert (buffer == buffer2); success = (NULL != buffer); if (success) { fp = open_output_file (pgno, subno); if (1 != fwrite (buffer, size, 1, fp)) write_error_exit (/* msg: errno */ NULL); close_output_file (fp); free (buffer); } break; case 3: /* This is the default target. The other cases are only implemented for tests and will be removed when I wrote proper unit tests. */ fp = open_output_file (pgno, subno); /* For proper timing of subtitles. */ vbi_export_set_timestamp (ex, timestamp); success = vbi_export_stdio (ex, fp, pg); close_output_file (fp); break; case 5: file_name = output_file_name (pgno, subno); success = vbi_export_file (ex, file_name, pg); free (file_name); break; default: error_exit ("Invalid target %u.", option_target); break; } if (!success) { error_exit (_("Export of page %x failed: %s"), pgno, vbi_export_errstr (ex)); } if (option_pdc_enum) { pdc_dump (pg); } vbi_page_delete (pg); pg = NULL; }
static void do_export (vbi_pgno pgno, vbi_subno subno) { vbi_page page; vbi_bool success; if (option_delay > 1) { --option_delay; return; } success = vbi_fetch_vt_page (vbi, &page, pgno, subno, VBI_WST_LEVEL_3p5, /* n_rows */ 25, /* navigation */ TRUE); if (!success) { /* Shouldn't happen. */ error_exit (_("Unknown error.")); } if (option_dump_pg) { page_dump (&page); } switch (option_target) { char *file_name; void *buffer; void *buffer2; FILE *fp; size_t size; ssize_t ssize; case 1: buffer = malloc (1 << 20); if (NULL == buffer) no_mem_exit (); ssize = vbi_export_mem (ex, buffer, 1 << 20, &page); success = (ssize >= 0); if (success) { ssize_t ssize2; fp = open_output_file (pgno, subno); if (1 != fwrite (buffer, ssize, 1, fp)) write_error_exit (/* msg: errno */ NULL); close_output_file (fp); /* Test. */ ssize2 = vbi_export_mem (ex, buffer, 0, &page); assert (ssize == ssize2); assert (ssize > 0); ssize2 = vbi_export_mem (ex, buffer, ssize - 1, &page); assert (ssize == ssize2); } free (buffer); break; case 2: buffer = NULL; buffer2 = vbi_export_alloc (ex, &buffer, &size, &page); /* Test. */ assert (buffer == buffer2); success = (NULL != buffer); if (success) { fp = open_output_file (pgno, subno); if (1 != fwrite (buffer, size, 1, fp)) write_error_exit (/* msg: errno */ NULL); close_output_file (fp); free (buffer); } break; case 3: /* This is the default target. The other cases are only implemented for tests and will be removed when I wrote proper unit tests. */ fp = open_output_file (pgno, subno); success = vbi_export_stdio (ex, fp, &page); close_output_file (fp); break; case 5: file_name = output_file_name (pgno, subno); success = vbi_export_file (ex, file_name, &page); free (file_name); break; default: error_exit ("Invalid target %u.", option_target); break; } if (!success) { error_exit (_("Export of page %x failed: %s"), pgno, vbi_export_errstr (ex)); } vbi_unref_page (&page); }
void cascade_one_level_down(int myid, int numbprocs, char *infile, char *outfile, WSET *ws, int num_group, int stages, int cnt_stage, int cnt_step, IDLE_ELEMENT **ie, LISTELEMENT **listpointer, int *TaskCount, int NUM_GROUP, int *dimension, int *cnt_index, int update_flag) { int n,/* dimension */ nbsols, dim, deg, fail, i, n1, n2, cd; double vcp[34]; if(myid == 0) { printf("manager is in inside of cascade_one_level_down\n"); read_dimension_of_system((int)strlen(infile),infile,&n); } dimension_broadcast(myid,&n); if(myid == 0) { fail = syscon_clear_symbol_table(); fail = read_named_start_without_solutions((int)strlen(infile),infile); /*fail = copy_start_system_to_container();*/ fail = copy_start_system_to_container(); fail = syscon_sort_embed_symbols(&dim); printf("the top dimension is %d\n",dim); fail = copy_container_to_start_system(); fail = solcon_scan_solution_banner(); fail = solcon_read_solution_dimensions(&nbsols,dimension); } else /* initialize system container */ fail = syscon_initialize_number_of_standard_polynomials(n); monomials_broadcast(myid,n); /* broadcast container */ if(myid != 0) /* copy result of broadcast */ { fail = copy_container_to_start_system(); fail = syscon_clear_standard_system(); /* clear system container */ } fail = create_cascade_homotopy(); MPI_Barrier(MPI_COMM_WORLD); if(myid == 0) { if(v>3) printf("# paths to track : %d\n",nbsols); fail = define_output_file_with_string ((int)strlen(outfile), outfile); fail = write_standard_target_system(); fail = write_standard_start_system(); /*fail = tune_continuation_parameters(); printf("\n");*/ fail = retrieve_continuation_parameters(vcp); write_solution_banner_to_defined_output_file(nbsols,n); printf("\nSee the output file for results...\n\n"); } MPI_Bcast(&nbsols,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(vcp,34,MPI_DOUBLE,0,MPI_COMM_WORLD); if(myid != 0) { fail = set_continuation_parameters(vcp); } if(myid == 0) { n1=0; n2=0; cd=n; send_collect(ws, num_group, stages, cnt_stage, numbprocs, cnt_step, ie, listpointer, TaskCount, NUM_GROUP, cnt_index, update_flag, n1, n2, cd); if(update_flag) *cnt_index=*cnt_index+1; if(v>3) { printf("after send_collect \n"); printf("%d JOBs in listpointer. \n", length(*listpointer)); printf("%d idles\n", num_idle(*ie)); printf("indexing........ with cnt_index=%d\n", *cnt_index); } } else { if(v>3) printf("node %d will run run_slave \n", myid); fflush; run_slave(myid); } MPI_Barrier(MPI_COMM_WORLD); if(myid == 0) { if(v>3) printf("manager clear data \n"); fail = clear_data(); if(fail>0) printf("manager fail to clear data.\n"); fflush; fail = solcon_close_solution_input_file(0); if(fail>0) printf("fail to close solution input file.\n"); fail = solcon_clear_standard_solutions( ); if(fail>0) printf("fail to clear solution container.\n"); fail = close_output_file(); if(fail>0) printf("fail to close output file. \n"); fflush; } else { if(v>3) printf("node %d clear data \n", myid); fail = clear_data(); if(fail>0) printf("node %d fail to clear data.\n", myid); fflush; } }
void start_a_diagonal_homotopy(int myid, int numbprocs, char *name_1, char *name_2, char *outfile, WSET *ws, int num_group, int stages, int cnt_stage, int cnt_step, IDLE_ELEMENT **ie, LISTELEMENT **listpointer, int *TaskCount, int NUM_GROUP, int NUM_VARS, int *cnt_index, int *expected, int *dim, int update_flag) { int n, deg, n1, n2, dim1, dim2, deg1, deg2, cd, nbsols, fail, i, slv, count; double vcp[34]; if(myid==0) { printf("manager is in inside of start_a_diagonal_homotopy\n"); fail = read_two_witness_sets_from_file(&n1,&n2,&dim1,&dim2, °1,°2,name_1,name_2,&cd); n = cd; /* dimension */ nbsols = deg1*deg2; printf("#paths to track: %d\n", nbsols); fail = define_output_file_with_string ((int)strlen(outfile), outfile); fail = standard_diagonal_homotopy(dim1,dim2); if(fail == 0) { fail = write_standard_target_system(); fail = write_standard_start_system(); } /*fail = tune_continuation_parameters(); printf("\n");*/ fail = retrieve_continuation_parameters(vcp); write_solution_banner_to_defined_output_file(nbsols,n); printf("\nSee the output file %s for results...\n\n", outfile); *expected = dim1+dim2-NUM_VARS; printf("expected dimension=%d\n", *expected); } dimension_broadcast(myid,&n); MPI_Bcast(&nbsols,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(vcp,34,MPI_DOUBLE,0,MPI_COMM_WORLD); if(myid != 0) { fail = set_continuation_parameters(vcp); } fail = homotopy_broadcast(myid,n); fail = create_homotopy_with_given_gamma (-0.824263733224601,0.566206056211557); if(myid == 0) { send_collect(ws, num_group, stages, cnt_stage, numbprocs, cnt_step, ie, listpointer, TaskCount, NUM_GROUP, cnt_index, update_flag, n1, n2, cd); if(v>3) { printf("after send_collect \n"); printf("%d JOBs in listpointer. \n", length(*listpointer)); printf("%d idles\n", num_idle(*ie)); printf("indexing........ with cnt_index=%d\n", *cnt_index); } } else { if(v>3) printf("node %d will run run_slave \n", myid); fflush; run_slave(myid); } MPI_Barrier(MPI_COMM_WORLD); if(myid == 0) { if(v>3) printf("manager clear data \n"); fail = clear_data(); if(fail>0) printf("manager fail to clear data.\n"); fail = clear_homotopy(); if(fail>0) printf("manager fail to clear homotopy.\n"); fail = solcon_close_solution_input_file(1); if(fail>0) printf("fail to close witness set 1.\n"); fail = solcon_close_solution_input_file(2); if(fail>0) printf("fail to close witness set 2.\n"); fail = solcon_clear_standard_solutions( ); if(fail>0) printf("fail to clear solution container.\n"); fail = close_output_file(); if(fail>0) printf("fail to close output file. \n"); fail = read_witness_set_from_file((int)strlen(outfile), outfile,&n,dim,°); fail = solcon_clear_standard_solutions(); fail = syscon_clear_standard_system( ); printf("end of start_a_diagonal_homotopy\n"); fflush; } else { if(v>3) printf("node %d clear data.\n", myid); fail = clear_data(); if(fail>0) printf("node %d fail to clear data.\n", myid); fail = clear_homotopy(); if(fail>0) printf("node %d fail to clear homotopy.\n", myid); } }
int main(int argc, char * argv[], char * envp[]) { ParseDelimitedText * parser; int input_file_fd; char input_file_buffer[PDT_BLK_SIZE]; size_t bytes_read; /* Initalize the classes we're using */ class_Array(); class_String(); class_PDTFormat(); class_PDTColumn(); class_PDTFormatFile(); class_ParseDelimitedText(); /* Parse command line parameters */ set_params(argc, argv); /* Load the format file */ format = new_PDTFormat(); format->m->read_file(format, format_file->string, format_file->length); /* Open the files */ input_file_fd = open_input_file(); output_file_fd = open_output_file(); /* Set the parser's options */ parser = new_ParseDelimitedText(0); parser->m->apply_format(parser, format); parser->m->set_block_size(parser, PDT_BLK_SIZE); parser->m->set_field_callback(parser, fieldcb); parser->m->set_record_callback(parser, recordcb); /* Initialize Globals */ record = new_Array(); record->auto_free = null_String->m->Array_free; format->columns->m->reset_each(format->columns); while(format->columns->m->each(format->columns) != null_ArrayElement) { record->m->append(record, new_String("", 0)); } field_count = 0; valid = 1; output_buffer = new_String("", 0); output_buffer->m->extend(output_buffer, 8191); /* Convert the file to standard form */ while(parser->stop == 0 && (bytes_read = read(input_file_fd, input_file_buffer, PDT_BLK_SIZE)) != 0) { parser->m->parse(parser, input_file_buffer, bytes_read); } parser->m->finish(parser); if(output_file->length != 0) { write_output_file(); } /* Cleanup */ close_input_file(input_file_fd); close_output_file(output_file_fd); parser->m->free(parser); record->m->free(record); format->m->free(format); output_buffer->m->free(output_buffer); return (valid) ? SHELL_TRUE : SHELL_FALSE; }