static Proto* load(const char* filename) { Proto* tf; ZIO z; char source[512]; FILE* f; int c,undump; if (filename==NULL) { f=stdin; filename="(stdin)"; } else f=efopen(filename,"r"); c=ungetc(fgetc(f),f); if (ferror(f)) { fprintf(stderr,"luac: cannot read from "); perror(filename); exit(1); } undump=(c==ID_CHUNK); if (undump && f!=stdin) { fclose(f); f=efopen(filename,"rb"); } sprintf(source,"@%.*s",Sizeof(source)-2,filename); luaZ_Fopen(&z,f,source); tf = undump ? luaU_undump(L,&z) : luaY_parser(L,&z); if (f!=stdin) fclose(f); return tf; }
char ttyin(void) { char buf[BUFSIZ]; FILE *efopen(); static FILE *tty = NULL; if (tty == NULL) { tty = efopen("/dev/tty", "r"); } else if (fgets(buf, BUFSIZ, tty) == NULL || buf[0] =='q') { exit(0); } else { return buf[0]; } }
int main(int argc, char **argv) { /* Segy data constans */ int ntr=0; /* number of traces */ char *outpar=NULL; /* name of file holding output */ FILE *outparfp=stdout; /* ... its file pointer */ initargs(argc, argv); requestdoc(1); /* Get information from the first header */ if (!gettr(&tr)) err("can't get first trace"); if (!getparstring("outpar", &outpar)) outpar = "/dev/stdout" ; outparfp = efopen(outpar, "w"); checkpars(); /* Loop over traces getting a count */ do { ++ntr; } while(gettr(&tr)); fprintf(outparfp, "%d", ntr); return(CWP_Exit()); }
int afa_out (Options * options, Alignment * alignment) { int i, pos; char * seq; FILE * fptr; char filename[BUFFLEN]; sprintf (filename, "%s.patched.afa", options->outname); fptr = efopen (filename, "w"); if (!fptr) return 1; for (i=0; i<alignment->number_of_seqs; i++) { fprintf ( fptr, ">%s\n", alignment->name[i]); seq = alignment->sequence[i]; for (pos=0; pos<alignment->length; pos++) { if ( seq [pos] == '.' ) { /* seaview doesn't like dots */ fprintf ( fptr, "-"); } else { fprintf ( fptr, "%c", seq [pos]); } if ( pos%50 == 49 ) fprintf (fptr, "\n"); } if ( pos%50 ) fprintf (fptr, "\n"); } fclose (fptr); return 0; }
/* Lê o ficheiro de configuração dos jogadores * Numero de baralhos e jogadores */ Config *read_config(char *filename) { char buffer[MAX_LINE_LEN]; Config *config = NULL; config = (Config *) ecalloc((size_t) 1, sizeof(Config)); FILE *config_file = efopen(filename, "r"); // Parametros gerais de configuração: // Número de jogadores e numero de baralhos fgets(buffer, MAX_LINE_LEN, config_file); sscanf(buffer, "%d-%d", &(config->num_decks), &(config->num_players)); if (config->num_decks > 8 || config->num_decks < 4){ fprintf(stderr, "Erro: número de baralhos invalido.\n"); exit(EXIT_FAILURE); } if (config->num_players > 4 || config->num_players < 1) { fprintf(stderr, "Erro: número de jogadores invalido.\n"); exit(EXIT_FAILURE); } // Leitura dos parâmetros de configuracão de cada jogador for (int i=0; fgets(buffer, MAX_LINE_LEN, config_file) != NULL && i < config->num_players; i++) config = read_player(buffer, config, i); fclose(config_file); return config; }
int main( int argc, char **argv ) { FILE *fp; progname = *argv++; argc--; init(progname); if (argc) while (argc) { fp = efopen(*argv, "r"); plot(fp); fclose(fp); argv++; argc--; } else plot(stdin); if (!newpage) endpage(); done(); return(0); }
int main(int argc, char *argv[]){ int i; char *version; Args *args; FILE *fp; version = "0.3"; setprogname2("inspectPro"); args = getArgs(argc, argv); if(args->v) printSplash(version); if(args->h || args->e) printUsage(version); if(args->numInputFiles == 0){ fp = stdin; scanFile(fp, args); }else{ for(i=0;i<args->numInputFiles;i++){ fp = efopen(args->inputFiles[i],"rb"); scanFile(fp, args); fclose(fp); } } free(args); free(progname()); return 0; }
int main( int argc, char *argv[] ) { FILE *fp; int i; progname = argv[0]; pout = popen(OUTFILT, "w"); if (argc > 1) for (i = 1; i < argc; i++) { fp = efopen(argv[i], "r"); plot4(fp); fclose(fp); } else plot4(stdin); pglob(PEOF, 0200, NULL); return(pclose(pout)); }
char *string_file(const char *fname) { /* * read file in dynamically allocated character string */ FILE *in = NULL; char *buf = NULL, cr; int c; int buf_size = 1000, i = 0; /* read as ascii file */ in = (fname == NULL) ? (FILE *) stdin : efopen(fname, "r"); buf = (char *) emalloc(buf_size * sizeof(char)); while ((c = fgetc(in)) != EOF) { cr = c; convert_null_to_space(&cr, fname ? fname : "stdin", NULL); if (i == buf_size) { buf_size += 1000; buf = (char *) erealloc(buf, buf_size * sizeof(char)); } buf[i] = c; i++; } buf[i] = '\0'; /* close string */ if (fname != NULL) efclose(in); /* close file */ /* free unnecesary memory: */ return (char *) erealloc(buf, (i + 1) * sizeof(char)); }
int main(int argc, char*argv[]) { // the graph is just a list og from to identifier pairs, one per line if (argc != 4) { fprintf (stderr, "Usage: %s <path to graph> <from id> <to id>\n", argv[0]); exit(1); } // 57572 DOCK6 // 7049 TGFBR3 // 2263 FGFBP3 igraph_vs_t vertex_to; igraph_integer_t vertex_from; vertex_from = atol(argv[2]); // in principle, unumber of "to" vertices is arbitrary, // but that is a piece of code I will write some other time //igraph_vs_vector_small(&vertex_to, 2263, 7049, -1); igraph_vs_vector_small(&vertex_to, atol(argv[3]), -1); igraph_t graph; /*The number of vertices in the graph. If smaller than the largest integer in the file it will be ignored. It is thus safe to supply zero here. */ igraph_integer_t zero = 0; FILE * infile = efopen(argv[1], "r") ; igraph_bool_t directed = IGRAPH_UNDIRECTED; igraph_read_graph_edgelist (&graph, infile, zero, directed); /* shortest path calculation: */ /* http://igraph.org/c/doc/igraph-Structural.html#igraph_get_all_shortest_paths int igraph_get_all_shortest_paths(const igraph_t *graph, igraph_vector_ptr_t *res, igraph_vector_t *nrgeo, igraph_integer_t from, const igraph_vs_t to, igraph_neimode_t mode); */ igraph_vector_ptr_t result; igraph_vector_t nrgeo; igraph_integer_t i; // the second argument here is the number of "to" vertices igraph_vector_ptr_init (&result, 1); igraph_vector_init(&nrgeo, 0); igraph_get_all_shortest_paths (&graph, &result, &nrgeo, vertex_from, vertex_to, IGRAPH_ALL); for (i=0; i<igraph_vector_ptr_size(&result); i++) { print_vector(VECTOR(result)[i]); } igraph_vector_ptr_destroy(&result); igraph_vs_destroy(&vertex_to); igraph_destroy(&graph); if (!IGRAPH_FINALLY_STACK_EMPTY) return 1; return 0; }
int main(int argc, char **argv) { cwp_String key1, key2; /* x and y key header words */ Value val1, val2; /* ... their values */ cwp_String type1, type2;/* ... their types */ int index1, index2; /* ... their indices in hdr.h */ float x, y; /* temps to hold current x & y */ cwp_String outpar; /* name of par file */ register int npairs; /* number of pairs found */ /* Hook up getpars */ initargs(argc, argv); requestdoc(1); /* Prevent byte codes from spilling to screen */ if (isatty(STDOUT)) err("must redirect or pipe binary output"); /* Get parameters */ if (!getparstring("key1", &key1)) key1 = "sx"; if (!getparstring("key2", &key2)) key2 = "gx"; type1 = hdtype(key1); type2 = hdtype(key2); index1 = getindex(key1); index2 = getindex(key2); /* Loop over traces */ npairs = 0; while(gettr(&tr)) { gethval(&tr, index1, &val1); gethval(&tr, index2, &val2); x = vtof(type1, val1); y = vtof(type2, val2); efwrite(&x, FSIZE, 1, stdout); efwrite(&y, FSIZE, 1, stdout); ++npairs; } /* Make parfile if needed */ if (getparstring("outpar", &outpar)) fprintf(efopen(outpar, "w"), "n=%d label1=%s label2=%s\n", npairs, key1, key2); return(CWP_Exit()); }
static void treemerge( /* merge into one file */ int height, int nt, int nf, PLIST *pl, int (*pcmp)(), FILE *ofp ) { FILE *fi[NFILES], *fp; int i; if (nf <= NFILES) { for (i = 0; i < nf; i++) fi[i] = efopen(tfname(height, i + nt*NFILES), "r"); if ((fp = ofp) == NULL) fp = efopen(tfname(height + 1, nt), "w"); pmergesort(fi, nf, pl, pcmp, fp); for (i = 0; i < nf; i++) { fclose(fi[i]); unlink(tfname(height, i + nt*NFILES)); } if (ofp == NULL) { writeof(fp); fclose(fp); } } else { for (i = 0; i < (nf-1)/NFILES; i++) treemerge(height, i, NFILES, NULL, pcmp, NULL); treemerge(height, (nf-1)/NFILES, (nf-1)%NFILES + 1, pl, pcmp, NULL); treemerge(height + 1, 0, (nf-1)/NFILES + 1, NULL, pcmp, ofp); } }
ttyin() /* process response from /dev/tty (version 2) */ { char buf[BUFSIZ]; FILE *efopen(); static FILE *tty = NULL; if (tty == NULL) tty = efopen("/dev/tty", "r"); for (;;) { if (fgets(buf,BUFSIZ,tty) == NULL || buf[0] == 'q') exit(0); else if (buf[0] == '!') { system(buf+1); /* BUG here */ printf("!\n"); } else /* ordinary line */ return buf[0]; } }
int main(int argc, char **argv) { float fz[BUFSIZ]; int iz=0,jz,nz=0; unsigned int z[BUFSIZ]; char line[BUFSIZ],*lp, *outpar; FILE *infp=stdin,*outfp=stdout, *outparfp; unsigned int *uz = &(z[0]); /* Hook up getpar */ initargs(argc, argv); requestdoc(1); /* Prevent floats from dumping on screen */ switch(filestat(STDOUT)) { case BADFILETYPE: warn("stdout is illegal filetype"); pagedoc(); break; case TTY: warn("stdout can't be tty"); pagedoc(); break; default: /* rest are OK */ break; } /* Get parameters and do set up */ if (!getparstring("outpar", &outpar)) outpar = "/dev/tty" ; outparfp = efopen(outpar, "w"); while (fgets(line,BUFSIZ,infp)!=NULL) { /* set pointer to beginning of line */ lp = line; /* read hex digits from input line */ for(iz=0;sscanf(lp,"%2x",&uz[iz])==1;iz++,nz++,lp+=2); /* convert to floats */ for(jz=0;jz<iz;jz++) fz[jz] = 255-z[jz]; /* write floats */ fwrite(fz,sizeof(float),iz,outfp); } /* Make par file */ fprintf(outparfp, "total number of values=%d\n",nz); return(CWP_Exit()); }
static void doit(int undump, char* filename) { FILE* f= (filename==NULL) ? stdin : efopen(filename, undump ? "rb" : "r"); ZIO z; char source[255+2]; /* +2 for '@' and '\0' */ luaL_filesource(source,filename,sizeof(source)); zFopen(&z,f,source); if (verbose) fprintf(stderr,"%s\n",source+1); if (undump) do_undump(&z); else do_compile(&z); if (f!=stdin) fclose(f); }
static void doit(int undump, char* filename) { FILE* f= (filename==NULL) ? stdin : efopen(filename, undump ? "rb" : "r"); ZIO z; if (filename==NULL) filename="(stdin)"; zFopen(&z,f,filename); if (verbose) fprintf(stderr,"%s\n",filename); if (undump) do_undump(&z); else do_compile(&z); if (f!=stdin) fclose(f); }
void scanwma(struct fidinfo *fidinfo, struct statex *statex) { FILE *fp; fp = efopen(statex->path, "r"); if (asf_check_header(statex, fp)) read_asf_header(fidinfo, statex, fp); else fidinfo->scanned = 0; fclose(fp); }
int main(int argc, char **argv) { double sx, sy, gx, gy, factor; float mx, my; short unit; int degree; cwp_String outpar; register int npairs; /* Initialize */ initargs(argc, argv); requestdoc(1); if (!getparint("degree", °ree)) degree=0; npairs = 0; while (gettr(&tr)) { sx = tr.sx; sy = tr.sy; gx = tr.gx; gy = tr.gy; unit = tr.counit; /* If tr.scalco not set, use 1 as the value */ factor = (!tr.scalco) ? 1 : tr.scalco; /* factor < 0 means divide; factor > 0 means to multiply */ if (factor < 0) factor = -1/factor; /* if necessary, convert from seconds to degrees */ if (unit == 2 && degree == 1) factor /= 3600; mx = (float) (0.5*(sx + gx) * factor); my = (float) (0.5*(sy + gy) * factor); efwrite(&mx, FSIZE, 1, stdout); efwrite(&my, FSIZE, 1, stdout); ++npairs; } /* Make parfile if needed */ if (getparstring("outpar", &outpar)) fprintf(efopen(outpar, "w"), "n=%d\n", npairs); return(CWP_Exit()); }
int main(int argc, char **argv) { char *outpar; /* name of file holding output parfile */ FILE *outparfp; /* ... its file pointer */ int n1; /* number of floats per line */ size_t n1read; /* number of items read */ size_t n2 = 0; /* number of lines in input file */ float *z; /* binary floats */ /* Hook up getpar */ initargs(argc, argv); requestdoc(1); /* Get parameters and do set up */ if (!getparstring("outpar", &outpar)) outpar = "/dev/tty" ; outparfp = efopen(outpar, "w"); MUSTGETPARINT("n1",&n1); z = ealloc1float(n1); /* Loop over data converting to ascii */ while ((n1read = efread(z, FSIZE, n1, stdin))) { register int i1; if (n1read != n1) err("out of data in forming line #%d", n2+1); for (i1 = 0; i1 < n1; ++i1) /* z2xyz.c:70: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘size_t’ */ /* printf("%d %d %11.4e \n",n2,i1,z[i1]); */ #if __WORDSIZE == 64 printf("%lu %d %11.4e \n",n2,i1,z[i1]); #else printf("%u %d %11.4e \n",n2,i1,z[i1]); #endif ++n2; } /* Make par file */ /* z2xyz.c:76: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ */ /* fprintf(outparfp, "n2=%d\n", n2); */ #if __WORDSIZE == 64 fprintf(outparfp, "n2=%lu\n", n2); #else fprintf(outparfp, "n2=%u\n", n2); #endif return(CWP_Exit()); }
static void getargs (int argc , char** argv , FILE** avgfile, FILE** fldfile) /* ------------------------------------------------------------------------- * * Parse command-line arguments. * ------------------------------------------------------------------------- */ { char usage[] = "usage: rstress [options] avg.file [field.file]\n" "options:\n" " -h ... display this message\n"; char err[STR_MAX], c; while (--argc && **++argv == '-') switch (c = *++argv[0]) { case 'h': fprintf (stderr, usage); exit (EXIT_SUCCESS); break; default: sprintf (err, "illegal option: %c\n", c); message (prog, err, ERROR); break; } switch (argc) { case 1: *avgfile = efopen (argv[0], "r"); break; case 2: *avgfile = efopen (argv[0], "r"); *fldfile = efopen (argv[1], "r"); break; default: fprintf (stderr, usage); exit (EXIT_FAILURE); break; } }
int efprintf(char *env, char *fmt, ...) { va_list ap; int ret = -1; FILE *f; va_start(ap, fmt); if (f = efopen(env)) { ret = vfprintf(f, fmt, ap); fclose(f); } va_end(ap); return (ret); }
main(int argc, char *argv[]) { int i; FILE *fp; progname = argv[0]; if (argc == 1) { print(stdin, PAGESIZE); } else { for (i = 1; i < argc; i++) { fp = efopen(argv[i], "r"); print(fp, PAGESIZE); fclose(fp); } } exit(0); }
/* 创建字符串链表 */ T strlist_new(const char *file) { FILE *fp = efopen(file, "r");; /*模式串文件*/ T strlist; NEW0(strlist); strlist->file = strdup(file); strlist->list = list_new(NULL); strlist->min_strlen = MAX_STR_LEN; uint64_t line_num = 0; char buf[MAX_STR_LEN+1]; /*模式串缓存,包括换行符*/ while (fgets(buf, sizeof(buf), fp)) { line_num++; char *line_break = strchr(buf, '\n'); /*换行符指针*/ if (line_break) *line_break = '\0'; Str_Len_T len = strlen(buf); if (len) { /*非空行*/ /* 插入链表末尾 */ list_push_back(strlist->list, strdup(buf)); if (len < strlist->min_strlen) strlist->min_strlen = len; else if (len > strlist->max_strlen) strlist->max_strlen = len; strlist->total_strlen += len; strlist->strlen_num[len]++; } } //printf("Total line: %ld\n", line_num); strlist->str_num = list_len(strlist->list); /*计算平均串长*/ strlist->avg_strlen = (double) strlist->total_strlen / strlist->str_num; /* 计算串长标准差 */ strlist->strlen_sd = cal_sd(strlist); efclose(fp); return strlist; }
/* * Compiles src lua source to dest lua bytecode * Bytecode is quicker to load as it is preparsed and optimized. * This function does NOT understands ToME virtual paths they * need to be converted first, this is intentionnal */ s32b tome_compile_lua(char *src) { char *split; char dest[2048]; Proto *tf; PHYSFS_file *dump; /* Clear error state */ PHYSFS_getLastError(); /* A new empty lua state */ compile_lua_state = lua_open(0); tf = load(src); /* If we dump we need to optimize */ if (tome_compile_lua_optimizing) luaU_optchunk(tf); /* Dump to a file */ if (tome_compile_lua_stripping) strip(tf); /* Make up the destination file .lua => .lb */ strncpy(dest, src, 2048); dest[strlen(dest) - 2] = 'b'; dest[strlen(dest) - 1] = '\0'; /* Make sure distination exists */ split = strrchr(dest, '/'); *split = '\0'; PHYSFS_mkdir(dest); *split = '/'; dump = efopen(dest, "wb"); if (dump == NULL) quit("Could not compile lua: error writting"); PHYSFS_getLastError(); luaU_dumpchunk_file(tf, dump); my_fclose(dump); /* Clean up */ /* For a strange reasons this totaly panics lua ... lua_close(compile_lua_state); */ return 0; }
static void next_fragment(struct dpipe *source, struct FeederState *state) { char filename[PATH_MAX]; if (state->file) { fclose(state->file); if (destructive && state->destructive) { sprintf(filename, "%s/%u", state->directory, state->sequence); unlink(filename); } } sprintf(filename, "%s/%u", state->directory, ++state->sequence); if (state->file = state->sequence == 1 ? efopen(filename, "r", WHERE(next_fragment)) : fopen(filename, "r")) if (state->sequence > 1) skip_headers(state->file); }
void *einit_feedback_visual_fbsplash_worker_thread (void *irr) { einit_feedback_visual_fbsplash_worker_thread_running = 1; while (einit_feedback_visual_fbsplash_worker_thread_keep_running) { while (fbsplash_commandQ) { char *command = NULL; emutex_lock (&fbsplash_commandQ_mutex); if (fbsplash_commandQ) { if ((command = fbsplash_commandQ[0])) { void *it = command; command = estrdup (command); fbsplash_commandQ = (char **)setdel ((void **)fbsplash_commandQ, it); } } emutex_unlock (&fbsplash_commandQ_mutex); if (command) { // notice (1, command); FILE *fifo = efopen (fbsplash_fifo, "w"); if (fifo) { eprintf (fifo, "%s\n", command); fclose (fifo); } free (command); }/* else { notice (1, "repaint"); FILE *fifo = efopen (fbsplash_fifo, "w"); if (fifo) { eprintf (fifo, "repaint\n", command); fclose (fifo); } }*/ } emutex_lock (&fbsplash_commandQ_cond_mutex); pthread_cond_wait (&fbsplash_commandQ_cond, &fbsplash_commandQ_cond_mutex); emutex_unlock (&fbsplash_commandQ_cond_mutex); } return NULL; }
/** * Spell check a file using a hash-table dictionary. * Prints all words not in the dictionary to stdout and statistics to stderr. * @param ht hash-table to use as a dictionary. * @param filename name of file to be spell-checked. * @param fill_time time taken to fill the dictionary. */ static void spell_check(htable ht, char *filename, double fill_time){ clock_t start,end; char word[256]; int unknown_words = 0; FILE *file = efopen(filename,"r"); start = clock(); while ((getword(word, sizeof word, file)) != EOF) { if(htable_search(ht,word) == 0){/* word not found */ printf("%s\n",word); unknown_words++; } } end = clock(); fclose(file); fprintf(stderr, "Fill time\t:%f\nSearch time\t:%f\n" "Unknown words = %d\n",fill_time, (end-start)/(double)CLOCKS_PER_SEC,unknown_words); }
void listload (LIST * list, char const *file, char buffer [], size_t length) { FILE *fp; char *sp; if ((fp = efopen (file, "r")) != (FILE *) (0)) { while (fgetline (buffer, length, fp) != -1) { for (sp = buffer; isblank (*sp); ++sp); if (strchr ("#;\n", *sp) == (char *) (0)) { listinsert (list, sp); } } fclose (fp); } return; }
int read_dssp (Options * options, Protein *protein) { char line[LONGSTRING] = {'\0'}; char pdb_id[PDB_ATOM_RES_NO_LEN+2] = {'\0'}; char tmp[5]; int resctr, acc, total = 0; FILE *fptr; fptr = efopen(options->dssp_file_name,"r"); while( fgets( line, LONGSTRING, fptr) != NULL){ if( ! strncmp(line+5,"RESIDUE", 7)){ break; } } while( fgets( line, LONGSTRING, fptr) != NULL){ if ( strchr ( line, '!') ) continue; strncpy ( pdb_id, line+6, 5); string_clean (pdb_id, 5); if ( ! pdb_id[0] ) continue; strncpy ( tmp, line+34, 4); tmp[4] = '\0'; acc = atoi(tmp); if ( acc > options->acc_cutoff ) { for ( resctr=0; resctr < protein->length; resctr++ ) { if ( !strcmp (pdb_id, protein->sequence[resctr].pdb_id) ) { protein->sequence[resctr].solvent_accessible = 1; total++; } } } } fclose (fptr); if ( ! total ) { fprintf (stderr, "No residue solvent accessible (?!)\n"); return 1; } return 0; }
void fig_setup(char *fname, double xmin, double ymin, double xmax, double ymax) { if (fname) out = efopen(fname, "w"); else out = stdout; fprintf(out, "%s", FIG_HEADER); /* save: */ if ((xmax - xmin) > (ymax - ymin)) { /* fit x coordinates to FIG: */ Xmin = xmin; Xmax = xmax; Ymin = ymin; Ymax = ymin + (xmax - xmin); } else { Ymin = ymin; Ymax = ymax; Xmin = xmin; Xmax = xmin + (ymax - ymin); } printf("## x[%g,%g],y[%g,%g]\n",Xmin,Xmax,Ymin,Ymax); }