void split(int num_split, gzFile *files[]) { int file = -1; char *buffer, *r; buffer = malloc(MAXLINELEN*sizeof(*buffer)); while(1) { r=fgets(buffer, MAXLINELEN, stdin); if(r==NULL) return; if(!strcmp(buffer, PAGE_START)) { file = random()%num_split; } if(file == -1) { int n; for(n = 0; n < num_split; n++) gzputs(files[n], buffer); } else { gzputs(files[file], buffer); } if(!strcmp(buffer, PAGE_END)) { file = -1; } } free(buffer); }
static int attr_callback(void *user_data, const char *attr, const char *val) { TagsContext *ctx = (TagsContext *) user_data; if (!strcmp(attr, "name")) ctx->name = val; else if (!strcmp(attr, "version")) { gzputs(ctx->packages, "##----------------------------------------\n"); gzputs(ctx->packages, "=Pkg: "); gzprintf(ctx->packages, "%s %s %d %s\n", join2(&ctx->pctx->jd, "rubygem", "-", ctx->name), val, 0, "x86_64"); gzputs(ctx->packages_en, "##----------------------------------------\n"); gzputs(ctx->packages_en, "=Pkg: "); gzprintf(ctx->packages_en, "%s %s %d %s\n", join2(&ctx->pctx->jd, "rubygem", "-", ctx->name), val, 0, "x86_64"); } else if (!strcmp(attr, "summary")) { gzputs(ctx->packages_en, "=Sum: "); gzputs(ctx->packages_en, val); gzputs(ctx->packages_en, "\n"); } else if (!strcmp(attr, "description")) { gzputs(ctx->packages_en, "+Des:\n"); gzputs(ctx->packages_en, val); gzputs(ctx->packages_en, "\n-Des:\n"); } return 0; }
int32_t SDDS_GZipWriteDescription(char *text, char *contents, gzFile *gzfp) { if (!gzfp) return 0; if (!text && !contents) return 1; gzputs(gzfp,"&description "); SDDS_GZipPrintNamelistField(gzfp, "text", text); SDDS_GZipPrintNamelistField(gzfp, "contents", contents); gzputs(gzfp,"&end\n"); return 1; }
int32_t SDDS_GZipWriteDataMode(DATA_MODE *data_mode, gzFile *gzfp) { if (!gzfp || data_mode->mode<0 || data_mode->mode>SDDS_NUM_DATA_MODES) return(0); gzputs(gzfp,"&data "); SDDS_GZipPrintNamelistField(gzfp, "mode", SDDS_data_mode[data_mode->mode-1]); if (data_mode->lines_per_row>1) gzprintf(gzfp, "lines_per_row=%" PRId32 ", ", data_mode->lines_per_row); if (data_mode->no_row_counts) gzprintf(gzfp, "no_row_counts=1, "); gzputs(gzfp,"&end\n"); return(1); }
int32_t SDDS_GZipWriteAssociateDefinition(ASSOCIATE_DEFINITION *associate_definition, gzFile *gzfp) { if (!gzfp) return(0); gzputs(gzfp,"&associate "); SDDS_GZipPrintNamelistField(gzfp, "name", associate_definition->name); SDDS_GZipPrintNamelistField(gzfp, "filename", SDDS_BlankToNull(associate_definition->filename)); SDDS_GZipPrintNamelistField(gzfp, "contents", SDDS_BlankToNull(associate_definition->contents)); SDDS_GZipPrintNamelistField(gzfp, "path", SDDS_BlankToNull(associate_definition->path)); SDDS_GZipPrintNamelistField(gzfp, "description", SDDS_BlankToNull(associate_definition->description)); gzprintf(gzfp, "sdds=%" PRId32 , associate_definition->sdds); gzputs(gzfp," &end\n"); return(1); }
int QtXmlWrapper::dosavefile(const char *filename, int compression, const char *xmldata) const { if(compression == 0) { FILE *file; file = fopen(filename, "w"); if(file == NULL) return -1; fputs(xmldata, file); fclose(file); } else { if(compression > 9) compression = 9; if(compression < 1) compression = 1; char options[10]; snprintf(options, 10, "wb%d", compression); gzFile gzfile; gzfile = gzopen(filename, options); if(gzfile == NULL) return -1; gzputs(gzfile, xmldata); gzclose(gzfile); } return 0; }
static TACommandVerdict gzputs_cmd(TAThread thread,TAInputStream stream) { void* file; char* s; int res, errnum; file = readPointer(&stream); s = readString(&stream); START_TARGET_OPERATION(thread); res = gzputs(file, s); END_TARGET_OPERATION(thread); gzerror(file, &errnum); writeInt(thread, errnum); writeInt(thread, errno); writeInt(thread, res); sendResponse(thread); return taDefaultVerdict; }
int znzputs(const char * str, znzFile file) { if (file==NULL) { return 0; } #ifdef HAVE_ZLIB if (file->zfptr!=NULL) return gzputs(file->zfptr,str); #endif return fputs(str,file->nzfptr); }
int32_t SDDS_GZipWriteParameterDefinition(PARAMETER_DEFINITION *parameter_definition, gzFile *gzfp) { if (!gzfp || parameter_definition->type<=0 || parameter_definition->type>SDDS_NUM_TYPES) return(0); gzputs(gzfp,"¶meter "); SDDS_GZipPrintNamelistField(gzfp, "name", parameter_definition->name); SDDS_GZipPrintNamelistField(gzfp, "symbol", SDDS_BlankToNull(parameter_definition->symbol)); SDDS_GZipPrintNamelistField(gzfp, "units", SDDS_BlankToNull(parameter_definition->units)); SDDS_GZipPrintNamelistField(gzfp, "description", SDDS_BlankToNull(parameter_definition->description)); SDDS_GZipPrintNamelistField(gzfp, "format_string", SDDS_BlankToNull(parameter_definition->format_string)); SDDS_GZipPrintNamelistField(gzfp, "type", SDDS_type_name[parameter_definition->type-1]); SDDS_GZipPrintNamelistField(gzfp, "fixed_value", parameter_definition->fixed_value); gzputs(gzfp,"&end\n"); return(1); }
int32_t SDDS_GZipWriteColumnDefinition(COLUMN_DEFINITION *column_definition, gzFile *gzfp) { if (!gzfp || column_definition->type<=0 || column_definition->type>SDDS_NUM_TYPES) return(0); gzputs(gzfp,"&column "); SDDS_GZipPrintNamelistField(gzfp, "name", column_definition->name); SDDS_GZipPrintNamelistField(gzfp, "symbol", SDDS_BlankToNull(column_definition->symbol)); SDDS_GZipPrintNamelistField(gzfp, "units", SDDS_BlankToNull(column_definition->units)); SDDS_GZipPrintNamelistField(gzfp, "description", SDDS_BlankToNull(column_definition->description)); SDDS_GZipPrintNamelistField(gzfp, "format_string", SDDS_BlankToNull(column_definition->format_string)); SDDS_GZipPrintNamelistField(gzfp, "type", SDDS_type_name[column_definition->type-1]); gzputs(gzfp," &end\n"); return(1); }
int32_t SDDS_GZipWriteArrayDefinition(ARRAY_DEFINITION *array_definition, gzFile *gzfp) { if (!gzfp || array_definition->type<=0 || array_definition->type>SDDS_NUM_TYPES) return(0); gzputs(gzfp,"&array "); SDDS_GZipPrintNamelistField(gzfp, "name", array_definition->name); SDDS_GZipPrintNamelistField(gzfp, "symbol", SDDS_BlankToNull(array_definition->symbol)); SDDS_GZipPrintNamelistField(gzfp, "units", SDDS_BlankToNull(array_definition->units)); SDDS_GZipPrintNamelistField(gzfp, "description", SDDS_BlankToNull(array_definition->description)); SDDS_GZipPrintNamelistField(gzfp, "format_string", SDDS_BlankToNull(array_definition->format_string)); SDDS_GZipPrintNamelistField(gzfp, "group_name", SDDS_BlankToNull(array_definition->group_name)); SDDS_GZipPrintNamelistField(gzfp, "type", SDDS_type_name[array_definition->type-1]); if (array_definition->dimensions!=1) /* 1 is default */ gzprintf(gzfp, "dimensions=%" PRId32 ", ", array_definition->dimensions); gzputs(gzfp," &end\n"); return(1); }
int gzw_puts (gzwRequest gzwr, const char *buf) { int len; if (gzwr.gzenabled) { len=gzputs(gzwr.gzfile,buf); } else { len=fputs(buf,gzwr.file); } return len; }
void gt_xgzfputs(const char *str, gzFile file) { int errnum; if (gzputs(file, str) == -1) { fprintf(stderr, "cannot put string to compressed file: %s\n", gzerror(file, &errnum)); exit(EXIT_FAILURE); } }
int main(void) { gzFile gz; if (NULL == (gz = gzopen("/dev/null", "w"))) return(1); gzputs(gz, "foo"); gzclose(gz); return(0); }
void GzipWriter::write(const char* format, ...) throw (Exception) { va_list arguments; va_start(arguments, format); if (vsprintf(buffer, format, arguments) < 0) { throw Exception(__FILE__, __LINE__, "Error while writing '%s' file.", file_name); } va_end(arguments); if (gzputs(outfile, buffer) < 0) { throw Exception(__FILE__, __LINE__, "Error while writing '%s' file.", file_name); } }
/** * Save paths to a file. * @param gzout gzFile to write to * @param path path of output file * @param save_path_seq if true, save seq= and juncpos= for links, requires * exactly one colour in the graph * @param hdrs is array of JSON headers of input files */ void gpath_save(gzFile gzout, const char *path, size_t nthreads, bool save_path_seq, const char *cmdstr, cJSON *cmdhdr, cJSON **hdrs, size_t nhdrs, const ZeroSizeBuffer *contig_hists, size_t ncols, dBGraph *db_graph) { ctx_assert(nthreads > 0); ctx_assert(gpath_set_has_nseen(&db_graph->gpstore.gpset)); ctx_assert(ncols == db_graph->gpstore.gpset.ncols); ctx_assert(!save_path_seq || db_graph->num_of_cols == 1); // save_path => 1 colour char npaths_str[50]; ulong_to_str(db_graph->gpstore.num_paths, npaths_str); status("Saving %s paths to: %s", npaths_str, path); status(" using %zu threads", nthreads); // Write header cJSON *json = gpath_save_mkhdr(path, cmdstr, cmdhdr, hdrs, nhdrs, contig_hists, ncols, db_graph); json_hdr_gzprint(json, gzout); cJSON_Delete(json); // Print comments about the format gzputs(gzout, ctp_explanation_comment); // Multithreaded GPathSaver *wrkrs = ctx_calloc(nthreads, sizeof(GPathSaver)); pthread_mutex_t outlock; size_t i; if(pthread_mutex_init(&outlock, NULL) != 0) die("Mutex init failed"); for(i = 0; i < nthreads; i++) { wrkrs[i] = (GPathSaver){.threadid = i, .nthreads = nthreads, .save_seq = save_path_seq, .gzout = gzout, .outlock = &outlock, .db_graph = db_graph}; } // Iterate over kmers writing paths util_run_threads(wrkrs, nthreads, sizeof(*wrkrs), nthreads, gpath_save_thread); pthread_mutex_destroy(&outlock); ctx_free(wrkrs); status("[GPathSave] Graph paths saved to %s", path); }
VISIBLE int Qputs (QFile *file, const char *buf) { if (file->sub) // can't write to a sub-file return -1; if (file->file) return fputs (buf, file->file); #ifdef HAVE_ZLIB else return gzputs (file->gzfile, buf); #else return 0; #endif }
int ZIPFAM::WriteBuffer(PGLOBAL g) { /*********************************************************************/ /* Prepare the write buffer. */ /*********************************************************************/ strcat(strcpy(To_Buf, Tdbp->GetLine()), CrLf); /*********************************************************************/ /* Now start the writing process. */ /*********************************************************************/ if (gzputs(Zfile, To_Buf) < 0) return Zerror(g); return RC_OK; } // end of WriteBuffer
void QfileQts::gerar_qts(string destino){ gzFile gzArquivo; ifstream iArquivo; char c; string tmp = destino + substituir_espaco(Titulo)+".qts"; gzArquivo = gzopen(tmp.c_str(),"wb"); tmp = destino + "inf_tema.xml"; iArquivo.open(tmp.c_str()); while(iArquivo.good()){ c = iArquivo.get(); if (iArquivo.good()) gzputc(gzArquivo,c); } iArquivo.close(); remove(tmp.c_str()); gzputs(gzArquivo,separador); tmp = Arquivo; iArquivo.open(tmp.c_str()); while(iArquivo.good()){ c = iArquivo.get(); if (iArquivo.good()) gzputc(gzArquivo,c); } iArquivo.close(); tmp = Thumb; iArquivo.open(tmp.c_str()); while(iArquivo.good()){ c = iArquivo.get(); if (iArquivo.good()) gzputc(gzArquivo,c); } iArquivo.close(); gzclose(gzArquivo); }
void db_nodes_gzprint(const dBNode *nodes, size_t num, const dBGraph *db_graph, gzFile out) { size_t i, kmer_size = db_graph->kmer_size; Nucleotide nuc; BinaryKmer bkmer; char tmp[MAX_KMER_SIZE+1]; bkmer = db_node_oriented_bkmer(db_graph, nodes[0]); binary_kmer_to_str(bkmer, kmer_size, tmp); gzputs(out, tmp); for(i = 1; i < num; i++) { nuc = db_node_get_last_nuc(nodes[i], db_graph); gzputc(out, dna_nuc_to_char(nuc)); } }
void logme(LogType type, const char *format, ... ) { static const char* logtypestr[] = { "", "ERROR", "WARNING", "INFO", "CHAT", "DEBUG" }; char buf[1024] = ""; char out[2048] = ""; char *p; time_t t = time(0); va_list ap; char *timestring = ctime(&t); int i; /* get rid of the '\n' - ctime() must be on the top ten of worst * standard functions */ timestring[strlen(timestring)-1] = '\0'; va_start(ap, format); vsprintf(buf, format, ap); va_end(ap); /* make sure te buf ends with a \n */ if (buf[strlen(buf) - 1] != '\n') strcat(buf, "\n"); /* write them out line by line */ for (p = buf, i = 0; i < strlen(p); ) { if (p[i] == '\n') { p[i] = '\0'; sprintf(out, "%s:%s:%s\n", timestring, logtypestr[type], p); p = &p[i]; i = 0; if (logfile) fprintf(logfile, out); #if defined(ZLIB_VERSION) else if (gzlogfile) gzputs(gzlogfile, out); #endif else fprintf(stderr, out); } else { i++; } } }
TransRec::SavedAnnotation TransRec::writeAnnotation(const Annotation& annotation, bool compress) { static std::unordered_map<std::string, bool> fileWritten; SavedAnnotation saved = { folly::sformat("{}/tc_annotations.txt{}", RuntimeOption::EvalDumpTCPath, compress ? ".gz" : ""), 0, 0 }; auto const fileName = saved.fileName.c_str(); auto result = fileWritten.find(saved.fileName); if (result == fileWritten.end()) { unlink(fileName); fileWritten[saved.fileName] = true; } FILE* file = fopen(fileName, "a"); if (!file) return saved; saved.offset = lseek(fileno(file), 0, SEEK_END); if (saved.offset == (off_t)-1) { fclose(file); return saved; } auto const& content = annotation.second; if (compress) { gzFile compressedFile = gzdopen(fileno(file), "a"); if (!compressedFile) { fclose(file); return saved; } auto rv = gzputs(compressedFile, content.c_str()); if (rv > 0) saved.length = rv; gzclose(compressedFile); } else { if (fputs(content.c_str(), file) >= 0) { saved.length = content.length(); } fclose(file); } return saved; }
static void d_printf(const char *fmt, ...) { static char s[RSSMAXBUFSIZE]; va_list ap; int r; va_start(ap, fmt); r = vsnprintf(s, sizeof(s), fmt, ap); va_end(ap); if (r < 0 || r >= sizeof(s)) printf("error d_printf: vsnprintf: r %d (%d)", r, (int)sizeof(s)); if (gz != NULL) { r = gzputs(gz, s); if (r != strlen(s)) printf("error d_printf: gzputs: r %d (%d)", r, (int)strlen(s)); } else fprintf(stdout, "%s", s); }
bool AbstractBootstrapper::zipFiles( const QString& inFileName, const QString& outFileName ) const { QDir temp = QDir::temp(); temp.remove( outFileName ); gzFile outFile = gzopen( outFileName.toLocal8Bit(), "wb" ); if ( !outFile ) return false; QFile inFile( inFileName ); if ( !inFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) return false; if ( gzputs( outFile, inFile.readAll().data() ) < 1 ) return false; gzclose( outFile ); inFile.close(); return true; }
// Print JSON header to gzout static void bubble_caller_print_header(gzFile gzout, const char* out_path, BubbleCallingPrefs prefs, cJSON **hdrs, size_t nhdrs, const dBGraph *db_graph) { size_t i; // Construct cJSON cJSON *json = cJSON_CreateObject(); cJSON_AddStringToObject(json, "file_format", "CtxBubbles"); cJSON_AddNumberToObject(json, "format_version", BUBBLE_FORMAT_VERSION); // Add standard cortex headers json_hdr_make_std(json, out_path, hdrs, nhdrs, db_graph); // Add parameters used in bubble calling to the header json_hdr_augment_cmd(json, "bubbles", "max_flank_kmers", cJSON_CreateInt(prefs.max_flank_len)); json_hdr_augment_cmd(json, "bubbles", "max_allele_kmers", cJSON_CreateInt(prefs.max_allele_len)); cJSON *haploids = cJSON_CreateArray(); for(i = 0; i < prefs.num_haploid; i++) cJSON_AddItemToArray(haploids, cJSON_CreateInt(prefs.haploid_cols[i])); json_hdr_augment_cmd(json, "bubbles", "haploid_colours", haploids); // Write header to file json_hdr_gzprint(json, gzout); // Print comments about the format gzputs(gzout, "\n"); gzputs(gzout, "# This file was generated with McCortex\n"); gzputs(gzout, "# written by Isaac Turner <*****@*****.**>\n"); gzputs(gzout, "# url: "CORTEX_URL"\n"); gzputs(gzout, "# \n"); gzputs(gzout, "# Comment lines begin with a # and are ignored, but must come after the header\n"); gzputs(gzout, "\n"); cJSON_Delete(json); }
static void _kqtime_statsWorkerThreadMain(KQTimeStatsWorker* worker) { g_assert(worker); gboolean doExit = FALSE; GHashTable* descs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); while (!doExit) { /* wait for command */ KQTimeCommand* command = g_async_queue_pop(worker->commands); if (!command) { continue; } log("kqtime: got command %s for fd %d\n", _kqtime_commandTypeToString(command->type), command->fd); switch (command->type) { case KQTIME_CMD_ADDFD: { KQTimeFDCommand* fdCommand = (KQTimeFDCommand*) command; g_hash_table_replace(descs, GINT_TO_POINTER(command->fd), fdCommand->fdName); break; } case KQTIME_CMD_DELFD: { g_hash_table_remove(descs, GINT_TO_POINTER(command->fd)); break; } case KQTIME_CMD_COLLECT: { guint n = g_hash_table_size(descs); if (n == 0) { log("kqtime: skipping stats collection on empty hash table\n"); break; } GString* status = g_string_new(NULL); struct timeval start; struct timeval end; gettimeofday(&start, NULL); g_hash_table_foreach(descs, (GHFunc)_kqtime_collectStats, status); gettimeofday(&end, NULL); GString* output = g_string_new(NULL); g_string_printf(output, "KQTIME-STATS;start=%lu.%06lu,end=%lu.%06lu,num_fds=%u;%s\n", (gulong) start.tv_sec, (gulong) start.tv_usec, (gulong) end.tv_sec, (gulong) end.tv_usec, n, status->str); if(worker->logFile) { fputs(output->str, worker->logFile); } else if(worker->gzLogFile) { gzputs(worker->gzLogFile, output->str); } g_string_free(output, TRUE); g_string_free(status, TRUE); break; } case KQTIME_CMD_LOG: { KQTimeLogCommand* logCommand = (KQTimeLogCommand*) command; gchar* fdName = g_hash_table_lookup(descs, GINT_TO_POINTER(logCommand->base.fd)); GString* output = g_string_new(NULL); g_string_printf(output, "KQTIME-%s;start=%lu.%06lu,end=%lu.%06lu,fd=%d;%s;\n", logCommand->isInbound ? "IN" : "OUT", (gulong) logCommand->tagTime.tv_sec, (gulong) logCommand->tagTime.tv_usec, (gulong) logCommand->matchTime.tv_sec, (gulong) logCommand->matchTime.tv_usec, logCommand->base.fd, fdName ? (gchar*)fdName : "NULL"); if(worker->logFile) { fputs(output->str, worker->logFile); } else if(worker->gzLogFile) { gzputs(worker->gzLogFile, output->str); } g_string_free(output, TRUE); break; } case KQTIME_CMD_EXIT: { doExit = TRUE; break; } default: { break; } } g_free(command); } g_hash_table_destroy(descs); }
int ngs_score (ngs_params * p) { int i = 0; size_t j = 0; size_t length = 0; int input_buffer_count = 0; char input_buffer[BUFFSIZE][MAX_LINE_LENGTH]; gzFile input_fastq; gzFile output_fastq; /* Open the fastQ input stream */ if ((input_fastq = gzopen (p->seqfile_name1, "rb")) == Z_NULL) { fprintf (stderr, "\n\nError: cannot open the input fastQ file: " "%s.\n\n", p->seqfile_name1); abort (); } /* Open the fastQ output stream */ if ((output_fastq = gzopen (p->outfile_name1, "wb")) == Z_NULL) { fprintf (stderr, "\n\nError: cannot open the output fastQ file: " "%s.\n", p->outfile_name1); abort (); } /* Set up interrupt trap */ signal (SIGINT, INThandler); /* Read through fastQ input sequence file */ while (1) { input_buffer_count = 0; /* Fill up the input buffer */ while (input_buffer_count < BUFFSIZE) { if (gzgets (input_fastq, input_buffer[input_buffer_count], MAX_LINE_LENGTH) == Z_NULL) break; ++input_buffer_count; } /* Dump the buffer to the output stream */ for (i = 0; i < input_buffer_count; ++i) { if (i % 4 == 3) { j = 0; length = strlen (input_buffer[i]) - 1; if (p->flag & SCORE_ILLUMINA) { /* Only do Sanger to Illumina conversion */ while (j < length) { int score = input_buffer[i][j] + 31; if (score > SCHAR_MAX) { fputs ("\n\nError: the original Phred scores are " "not in standard Sanger format.\n\n", stderr); exit (EXIT_FAILURE); } else gzputc (output_fastq, score); ++j; } gzputc (output_fastq, '\n'); if (p->flag & SCORE_ASCII) { /* Do both numerical and Sanger to Illumina conversion here */ const char delim = ' '; char *tok = NULL; int score = 0; tok = strtok (input_buffer[i], &delim); score = atoi (tok); gzputc (output_fastq, score); while (tok != NULL) { tok = strtok (NULL, &delim); score = atoi (tok); gzputc (output_fastq, score + 31); } gzputc (output_fastq, '\n'); } } else { /* Only do Illumina to Sanger conversion */ while (j < length) { int score = 0; score = input_buffer[i][j] - 31; if ((score > SCHAR_MAX) || (score < 33)) { fputs ("\n\nError: the original Phred scores are " "not in Illumina format.\n\n", stderr); abort (); } else gzputc (output_fastq, input_buffer[i][j] - 31); ++j; } gzputc (output_fastq, '\n'); if (p->flag & SCORE_ASCII) { /* Do both numerical and Illumina to Sanger conversion here */ const char delim = ' '; char *tok = NULL; int score = 0; tok = strtok (input_buffer[i], &delim); score = atoi (tok); gzputc (output_fastq, score); while (tok != NULL) { tok = strtok (NULL, &delim); score = atoi (tok); gzputc (output_fastq, score - 31); } gzputc (output_fastq, '\n'); } } } else gzputs (output_fastq, input_buffer[i]); } /* If we are at the end of the file */ if (input_buffer_count < BUFFSIZE) break; } /* Close the fastQ input and output streams */ gzclose (input_fastq); gzclose (output_fastq); return 0; }
static FILE* logs_open_file(char *path, int ff) { char fullname[PATH_MAX]; #ifdef HAVE_LIBZ int zlibmode = 0; #endif if (ff != LOG_FORMAT_IRSSI && ff != LOG_FORMAT_SIMPLE && ff != LOG_FORMAT_XML && ff != LOG_FORMAT_RAW) { if (ff == LOG_FORMAT_NONE) debug("[logs] opening log file %s with ff == LOG_FORMAT_NONE CANCELLED\n", __(path), ff); else debug("[logs] opening log file %s with ff == %d CANCELED\n", __(path), ff); return NULL; } debug("[logs] opening log file %s ff:%d\n", __(path), ff); if (!path) { errno = EACCES; /* = 0 ? */ return NULL; } { /* check if such file was already open SLOW :( */ list_t l; for (l=log_logs; l; l = l->next) { logs_log_t *ll = l->data; log_window_t *lw; if (!ll || !(lw = ll->lw)) continue; /* debug_error("here: %x [%s, %s] [%d %d]\n", lw->file, lw->path, path, lw->logformat, ff); */ if (lw->file && lw->logformat == ff && !xstrcmp(lw->path, path)) { FILE *f = lw->file; lw->file = NULL; /* simulate fclose() on this */ return f; /* simulate fopen() here */ } } } if (mkdir_recursive(path, 0)) { print("directory_cant_create", path, strerror(errno)); return NULL; } g_strlcpy(fullname, path, PATH_MAX); if (ff == LOG_FORMAT_IRSSI) g_strlcat(fullname, ".log", PATH_MAX); else if (ff == LOG_FORMAT_SIMPLE) g_strlcat(fullname, ".txt", PATH_MAX); else if (ff == LOG_FORMAT_XML) g_strlcat(fullname, ".xml", PATH_MAX); else if (ff == LOG_FORMAT_RAW) g_strlcat(fullname, ".raw", PATH_MAX); #ifdef HAVE_LIBZ /* z log.c i starego ekg1. Wypadaloby zaimplementowac... */ /* nawet je¶li chcemy gzipowane logi, a istnieje nieskompresowany log, * olewamy kompresjê. je¶li loga nieskompresowanego nie ma, dodajemy * rozszerzenie .gz i balujemy. */ if (config_log & 4) { struct stat st; if (stat(fullname, &st) == -1) { gzFile f; if (!(f = gzopen(path, "a"))) return NULL; gzputs(f, buf); gzclose(f); zlibmode = 1; } } if (zlibmode) { /* XXX, ustawic jakas flage... */ g_strlcat(fullname, ".gz", PATH_MAX); } #endif /* if xml, prepare xml file */ if (ff == LOG_FORMAT_XML) { FILE *fdesc = fopen(fullname, "r+"); if (!fdesc) { if (!(fdesc = fopen(fullname, "w+"))) return NULL; /* XXX: what about old, locale-encoded logs? */ fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fdesc); fputs("<!DOCTYPE ekg2log PUBLIC \"-//ekg2log//DTD ekg2log 1.0//EN\" ", fdesc); fputs("\"http://www.ekg2.org/DTD/ekg2log.dtd\">\n", fdesc); fputs("<ekg2log xmlns=\"http://www.ekg2.org/DTD/\">\n", fdesc); fputs("</ekg2log>\n", fdesc); } return fdesc; } return fopen(fullname, "a+"); }
static int database_dump_file (notmuch_database_t *notmuch, gzFile output, const char *query_str, int output_format) { notmuch_query_t *query; notmuch_messages_t *messages; notmuch_message_t *message; notmuch_tags_t *tags; if (! query_str) query_str = ""; query = notmuch_query_create (notmuch, query_str); if (query == NULL) { fprintf (stderr, "Out of memory\n"); return EXIT_FAILURE; } /* Don't ask xapian to sort by Message-ID. Xapian optimizes returning the * first results quickly at the expense of total time. */ notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED); char *buffer = NULL; size_t buffer_size = 0; for (messages = notmuch_query_search_messages (query); notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) { int first = 1; const char *message_id; message = notmuch_messages_get (messages); message_id = notmuch_message_get_message_id (message); if (output_format == DUMP_FORMAT_BATCH_TAG && strchr (message_id, '\n')) { /* This will produce a line break in the output, which * would be difficult to handle in tools. However, it's * also impossible to produce an email containing a line * break in a message ID because of unfolding, so we can * safely disallow it. */ fprintf (stderr, "Warning: skipping message id containing line break: \"%s\"\n", message_id); notmuch_message_destroy (message); continue; } if (output_format == DUMP_FORMAT_SUP) { gzprintf (output, "%s (", message_id); } for (tags = notmuch_message_get_tags (message); notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { const char *tag_str = notmuch_tags_get (tags); if (! first) gzputs (output, " "); first = 0; if (output_format == DUMP_FORMAT_SUP) { gzputs (output, tag_str); } else { if (hex_encode (notmuch, tag_str, &buffer, &buffer_size) != HEX_SUCCESS) { fprintf (stderr, "Error: failed to hex-encode tag %s\n", tag_str); return EXIT_FAILURE; } gzprintf (output, "+%s", buffer); } } if (output_format == DUMP_FORMAT_SUP) { gzputs (output, ")\n"); } else { if (make_boolean_term (notmuch, "id", message_id, &buffer, &buffer_size)) { fprintf (stderr, "Error quoting message id %s: %s\n", message_id, strerror (errno)); return EXIT_FAILURE; } gzprintf (output, " -- %s\n", buffer); } notmuch_message_destroy (message); } notmuch_query_destroy (query); return EXIT_SUCCESS; }
static int deps_end_callback(void *user_data) { TagsContext *ctx = (TagsContext *) user_data; gzputs(ctx->packages, "-Req:\n"); }