/* FUNCTION: call_script_ctx() * * Execute commands from a script file. * - A new GIO struct is pushed onto the GIO stack. * - The input stream is set to the script file * - The output stream is "null" of echo_out is FALSE. * - Commands are parsed and executed until EOF is reached. * * PARAM1: CLI_CTX current CLI context * PARAM2: void * script name or memory address * PARAM3: int input type: file or memory * PARAM4: bool_t TRUE = echo commands to output stream * PARAM5: bool_t FALSE = suppress command output * PARAM6: bool_t TRUE = abort script on first error * * RETURN: int 0 or error code */ int call_script_ctx(CLI_CTX ctx, void *cmdset, int type, bool_t echo_in, bool_t echo_out, bool_t halt) { GIO *gio = ctx->gio; VFILE *fd; int rtn; switch (type) { case CMDSFROMFILE: if ((fd = vfopen((char *)cmdset, "r")) == (VFILE *)NULL) { /* gio_printf(gio, "file not found: %s\n", cmdset); */ return (ENP_NOFILE); } else { /* input = file */ if ((rtn = GIO_PUSH_FILE(&ctx->gio, fd, GIO_RD)) != GIO_DONE) { vfclose(fd); return (rtn); } gio = ctx->gio; /* update gio descriptor */ /* if echo_out == FALSE, redirect output to "null" */ if (!echo_out) { GIO_NULL(gio, GIO_WR); } /* set the GIO_F_ECHO flag if we are echoing commands */ if (echo_in) gio->flags |= GIO_F_ECHO; else gio->flags &= ~GIO_F_ECHO; rtn = do_script(ctx, halt); vfclose(fd); /* close the file */ gio_pop(&ctx->gio); /* destroy the script context */ } break; case CMDSFROMMEM: /* not yet implemented */ default: dtrap(); /* unknown script type */ rtn = CLI_ERR_FATAL; break; } return (rtn); }
Oligo * read_oligo_list ( char *fname) { Oligo *O; FILE *fp; int a, b; O=vcalloc (1, sizeof (Oligo)); O->ALPHABET=vcalloc ( 100, sizeof (char)); O->EALPHABET=vcalloc ( 100, sizeof (char)); O->AMBIGUITIES=vcalloc ( 100, sizeof (char)); fp=vfopen ( fname, "r"); fscanf ( fp, "ALPHABET %s\n", O->ALPHABET); fscanf ( fp, "AMBIG_ALPHABET %s\n", O->AMBIGUITIES); if ( O->AMBIGUITIES[0]=='@')O->AMBIGUITIES[0]='\0'; fscanf ( fp, "WORD_SIZE %d\n", &O->WSIZE); fscanf ( fp, "NSEQ %d\n", &O->NSEQ); fscanf ( fp, "LEN %d\n", &O->LEN); fscanf ( fp, "SCORE %d", &a); sprintf ( O->EALPHABET, "%s%s", O->ALPHABET, O->AMBIGUITIES); O->seq=declare_char ( O->NSEQ, O->LEN+1); for ( a=0; a< O->NSEQ; a++) { fscanf ( fp, "%*s\n%s\n",O->seq[a]); } vfclose (fp); return O; }
Mixture * read_dirichlet ( char *name) { FILE *fp; int a,b, c; float f; Mixture *D; D=vcalloc ( 1, sizeof (Mixture)); D->N_COMPONENT=9; D->ALPHA=vcalloc (9, sizeof (double*)); for ( a=0; a< 9; a++) D->ALPHA[a]=vcalloc (20, sizeof (double)); D->DM_Q=vcalloc (9, sizeof (double)); if (name!=NULL) { fp=vfopen ( name, "r"); for ( a=0; a< 9; a++) { fscanf(fp, "%f\n", &f); D->DM_Q[a]=(double)f; fscanf(fp, "%f", &f); for ( b=0; b<20; b++) { fscanf(fp, "%f", &f); D->ALPHA[a][b]=(double)f; } fscanf(fp, "\n"); } for ( a=0; a< 9; a++) { fprintf(stderr, "\n%f\n",(float)D->DM_Q[a] ); for ( b=0; b<20; b++) { fprintf(stderr, "%f ", (float)D->ALPHA[a][b]); } fprintf(stderr, "\n"); } fprintf ( stderr, "\nN_C=%d",D->N_COMPONENT ); vfclose ( fp); } else { for (c=0, a=0; a< 9;a++) { D->DM_Q[a]=dm[c++]; for (b=0; b<20; b++) D->ALPHA[a][b]=dm[c++]; } } return D; }
int main(int argc, char *argv[]) { #if VFS_USING_C_API // <- This will be defined if VFS_ENABLE_C_API is on and the ttvfs overrides are in use. ttvfs::Root vfs; vfs.AddLoader(new ttvfs::DiskLoader); ttvfs_setroot(&vfs); // The C-like API supports only one (global) root object. // Must be set before calling any of the functions, // and must stay alive and unchanged while any VFILEs are opened. puts("Using VFS"); #else puts("Not using VFS"); #endif VFILE *fh = vfopen("myfile.txt", "r"); if(!fh) { puts("ERROR: File not found: myfile.txt"); return 1; } char buf[513]; size_t bytes = vfread(buf, 1, 512, fh); buf[bytes] = 0; puts(buf); vfclose(fh); //---------------------------------- InStream strm("mydata.txt"); if(strm) { // The below is mostly copied from example #3 unsigned int i, line = 0; float f; std::string s; while(true) { ++line; strm >> s >> i >> f; // we may hit EOF, causing any of the reads to fail if(!strm) // after reading, check if line was read in completely break; std::cout << "Line " << line << ": String '" << s << "', int " << i << ", float " << f << std::endl; } strm.close(); } return 0; }
int BGBCC_StoreFile(char *name, void *buf, int sz) { VFILE *fd; // basm_storetextfile(b, tbuf); fd=vffopen(name, "wb"); if(fd) { vfwrite(buf, 1, sz, fd); vfclose(fd); } return(0); }
int BGBCC_StoreTextFile(char *name, char *buf) { VFILE *fd; // basm_storetextfile(b, tbuf); fd=vffopen(name, "wt"); if(fd) { vfwrite(buf, 1, strlen(buf), fd); vfclose(fd); } return(0); }
int BTGE_Voxel_LoadDungeonList(char *name) { VFILE *fd; void *p; char buf[256]; char **a, *s; int i; // strcpy(buf, tmp->name); strcpy(buf, name); s=buf+strlen(buf); while((s>buf) && (*s!='.'))s--; if(*s!='.')s=buf+strlen(buf); strcpy(s, ".txt"); fd=vffopen(buf, "rt"); if(!fd)return(-1); while(!vfeof(fd)) { vfgets(buf, 255, fd); a=gcrsplit(buf); if(!a[0])continue; if(!strcmp(a[0], "$flags")) { } if(!strcmp(a[0], "$dungeon")) { btge_vox_dungeon_name[atoi(a[1])]=dystrdup(a[2]); // BTGE_Voxel_LoadDungeonType( // atoi(a[1]), dyllStrdup(a[2])); } } for(i=0; i<256; i++) { if(!btge_vox_dungeon_name[i]) continue; BTGE_Voxel_LoadDungeonType( i, btge_vox_dungeon_name[i]); } vfclose(fd); return(0); }
int BGBBTJ_PCX_StoreRaw(char *name, unsigned char *buf, int w, int h, char *pal) { VFILE *fd; fd=vffopen(name, "wb"); if(!fd) { printf("PCX_StoreRaw: can't open '%s'\n", name); return(-1); } BGBBTJ_PCX_Store(fd, buf, w, h, pal); vfclose(fd); return(0); }
unsigned char *BGBBTJ_PCX_LoadRaw(char *name, int *w, int *h, char *pal) { VFILE *fd; unsigned char *tmp; fd=vffopen(name, "rb"); if(!fd) { printf("PCX_LoadRaw: can't open '%s'\n", name); return(NULL); } tmp=BGBBTJ_PCX_Load(fd, w, h, pal); vfclose(fd); return(tmp); }
/*-- Cat pdnet;Protocols;Meta0 Form int Meta0_CloseConnection(Meta0_Con *con); Description Close a connection. --*/ int Meta0_CloseConnection(Meta0_Con *con) { Meta0_PortInfo *inf; inf=con->info; gc_printf("Meta0: Close connection, service %s.\n", inf->name); if(inf->closed) inf->closed(con); vfclose(con->sock); meta0_cons[con->num]=NULL; if(con->buf)gcfree(con->buf); gcfree(con); return(0); }
BTGE_API int BTGECM_ColorKey_LoadPalette( char *name, byte *clrbuf, int maxcolors) { char buf[256]; VFILE *fd; char **a; char *s; int i, n; fd=vffopen(name, "rt"); if(!fd) { return(-1); } memset(clrbuf, 0, 3*maxcolors); n=0; while(!vfeof(fd)) { vfgets(buf, 255, fd); a=gcrsplit(buf); if(!a[0])continue; if(*(a[0])=='/')continue; //comment if(*(a[0])==';')continue; //comment if(!strcmp(a[0], "color")) { i=gcratoi(a[1]); if((i<0) || (i>=maxcolors)) continue; clrbuf[i*3+0]=gcratoi(a[2]); clrbuf[i*3+1]=gcratoi(a[3]); clrbuf[i*3+2]=gcratoi(a[4]); if(i>=n)n=i+1; } } vfclose(fd); return(n); }
BTGE_API int BTGECM_ColorKey_LoadNames( char *name, char *key, char **namebuf, int maxnames) { char buf[256]; VFILE *fd; char **a; char *s; int i, n; fd=vffopen(name, "rt"); if(!fd) { return(-1); } for(i=0; i<maxnames; i++) namebuf[i]=NULL; n=0; while(!vfeof(fd)) { vfgets(buf, 255, fd); a=gcrsplit(buf); if(!a[0])continue; if(*(a[0])=='/')continue; //comment if(*(a[0])==';')continue; //comment if(!strcmp(a[0], key)) { i=gcratoi(a[1]); if((i<0) || (i>=maxnames)) continue; namebuf[i]=dystrdup(a[2]); if(i>=n)n=i+1; } } vfclose(fd); return(n); }
bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding ) { TIXML_STRING filename( _filename ); value = filename; // reading in binary mode so that tinyxml can normalize the EOL VFILE* file = vfopen( value.c_str (), "rb" ); if ( file ) { bool result = LoadFile( file, encoding ); vfclose( file ); return result; } else { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } }
BTGE_API void BTGE_BrushMap_SaveFile(BTGE_BrushWorld *world, char *name) { VFILE *fd; BTGE_SEntity *ecur; printf("Saving Map %s\n", name); world->map_name=dystrdup(name); fd=vffopen(name, "wt"); ecur=world->entity; while(ecur) { BTGE_BrushMap_SaveEntity(world, fd, ecur); ecur=ecur->next; } vfclose(fd); }
char *bgbcc_loadfile(char *name, int *rsz) { VFILE *fd; void *buf; int sz; fd=vffopen(name, "rb"); if(!fd)return(NULL); vfseek(fd, 0, 2); sz=vftell(fd); vfseek(fd, 0, 0); buf=bgbcc_malloc(sz+16); memset(buf, 0, sz+16); vfread(buf, 1, sz, fd); vfclose(fd); if(rsz)*rsz=sz; return(buf); #if 0 char *buf, *buf1; int i, sz; buf=basm_loadfile(name, &sz); if(buf) { buf1=bgbcc_malloc(sz); memcpy(buf1, buf, sz); basm_free(buf); if(rsz)*rsz=sz; return(buf1); } return(NULL); #endif }
int BGBCC_LoadCSource(char *name, char *out) { char tb[256], tb1[256]; VFILE *fd; BCCX_Node *t; byte *obj; char *s, *buf, *buf1, *buf2; int i, sz, t0, t1, dt; if(BGBCC_CacheCheckFile(name)) { strcpy(tb, name); s=tb; while(*s) { if(*s=='/')*s='_'; if(*s=='\\')*s='_'; if(*s==':')*s='_'; s++; } while((s>tb) && (*s!='.'))s--; if(s>tb)*s=0; sprintf(tb1, "dump/cache/%s.o", tb); fd=vffopen(tb1, "rb"); if(fd) { obj=vf_bufferin_sz(fd, &sz); vfclose(fd); if(obj) { i=BASM_LoadObjectBuffer(tb, obj, sz); gcfree(obj); if(i>=0)return(0); } } } // buf=bgbcc_loadfile(name, &sz); buf=BGBCC_ReadFile(name, &sz); if(!buf) { for(i=0; i<bgbcc_nsrc; i++) { sprintf(tb, "%s/%s", bgbcc_src[i], name); buf=bgbcc_loadfile(tb, &sz); if(buf)break; } } if(!buf) { printf("BGBCC_LoadModule: fail load '%s'\n", name); return(-1); } printf("BGBCC_LoadModule: %s %d bytes\n", name, sz); strcpy(tb, name); s=tb; while(*s) { if(*s=='/')*s='_'; if(*s=='\\')*s='_'; if(*s==':')*s='_'; s++; } while((s>tb) && (*s!='.'))s--; if(s>tb)*s=0; // printf("BGBCC_LoadModule: Begin Parse\n"); t0=clock(); // t=BS1_CParse_ModuleBuffer(name, tb, buf); t=BGBCP_ModuleBuffer(name, tb, buf); if(!t) { // free(buf); return(-1); } // BCCX_PrintFD(stdout, t); #if 1 sprintf(tb1, "dump/%s_ast.txt", tb); fd=vffopen(tb1, "wt"); if(fd) { BCCX_PrintVF(fd, t); vfclose(fd); } #endif t1=clock(); dt=t1-t0; printf("BGBCC_LoadModule: Parse took %dms\n", (int)(1000*(dt/(float)CLOCKS_PER_SEC))); buf1=BGBCC_CompileModule(tb, t); // BGBGC_SaveSig(); dyllMetaCommit(); BGBCC_CleanupAll(); if(!buf1) { // free(buf); return(-1); } // printf("%s\n", buf1); #if 1 sprintf(tb1, "dump/%s_ril.txt", tb); fd=vffopen(tb1, "wt"); if(fd) { vfwrite(buf1, 1, strlen(buf1), fd); vfclose(fd); } #endif // SXIL_BeginModule(tb); // sxil_puts(buf1); // buf2=SXIL_EndModuleBuffer(out); if(!buf2) { // free(buf); return(-1); } // printf("%s\n", buf2); #if 1 sprintf(tb1, "dump/%s_asm.txt", tb); fd=vffopen(tb1, "wt"); if(fd) { vfwrite(buf2, 1, strlen(buf2), fd); vfclose(fd); } #endif BASM_BeginAssembly(tb); basm_puts(buf2); if(out) { BASM_EndAssemblyFile(out); } else { // BASM_EndAssembly(); // obj=BASM_EndAssemblyObjBuf(&sz); // BASM_LoadObjectBuffer(obj, sz); obj=BASM_EndAssemblyCacheObjBuf(&sz); sprintf(tb1, "dump/cache/%s.o", tb); fd=vffopen(tb1, "wb"); if(fd) { vfwrite(obj, 1, sz, fd); vfclose(fd); BGBCC_UpdateCheckFile(name); } } dt=clock()-t1; printf("BGBCC_LoadModule: Compile took %dms\n", (int)(1000*(dt/(float)CLOCKS_PER_SEC))); if(!out) bgbcc_loads[bgbcc_nloads++]=basm_strdup(name); // free(buf); return(i); }
//HACK: deal with matter of FILE IO not working between DLL's static FILE *s_ogg_open(char *name) { char tb[256]; FILE *fd; VFILE *vfd; byte *buf; char *s; int hi, sz; // sprintf(tb, "%s/%s", FS_Gamedir(), name); // fd=ov_fopen(tb, "rb"); // if(fd)return(fd); // sprintf(tb, "%s/%s", "baseq2", name); // fd=ov_fopen(tb, "rb"); // if(fd)return(fd); sprintf(tb, "%s/%s", "resource", name); fd=ov_fopen(tb, "rb"); if(fd)return(fd); fd=ov_fopen(name, "rb"); if(fd)return(fd); //see if this can be resolved to an existent OS file s=vfTryFindOSPath(name, "rb"); if(s) { fd=ov_fopen(s, "rb"); if(fd)return(fd); } #if 1 //hack... //try to cache VFS files somewhere accessible to fopen s=name; hi=0; while(*s)hi=hi*251+(*s++); hi=((hi*251)>>8)&0xFFFFFF; sprintf(tb, "resource/sound/tmp_%06X", hi); fd=ov_fopen(tb, "rb"); if(fd)return(fd); vfd=vffopen(name, "rb"); if(vfd) { buf=vf_bufferin_sz(vfd, &sz); vfclose(vfd); if(buf) { fd=fopen(tb, "wb"); if(fd) { fwrite(buf, 1, sz, fd); fclose(fd); } fd=ov_fopen(tb, "rb"); if(fd)return(fd); } return(NULL); } #endif return(NULL); }
BTGE_API int BTGE_Texture_LoadInfo(BTGE_TexImage *tmp) { VFILE *fd; void *p; char buf[256]; char **a, *s; int i; strcpy(buf, tmp->name); s=buf+strlen(buf); while((s>buf) && (*s!='.'))s--; if(*s!='.')s=buf+strlen(buf); strcpy(s, ".txt"); fd=vffopen(buf, "rt"); if(!fd)return(-1); while(!vfeof(fd)) { vfgets(buf, 255, fd); a=gcrsplit(buf); if(!a[0])continue; if(!strcmp(a[0], "$flags")) { for(i=1; a[i]; i++) { if(!strcmp(a[i], "alpha")) tmp->flags|=BTGE_TXFL_ALPHA; if(!strcmp(a[i], "valpha")) tmp->flags|=BTGE_TXFL_VALPHA; if(!strcmp(a[i], "nonsolid")) tmp->flags|=BTGE_TXFL_NONSOLID; if(!strcmp(a[i], "detail")) tmp->flags|=BTGE_TXFL_DETAIL; if(!strcmp(a[i], "nocsg")) tmp->flags|=BTGE_TXFL_NOCSG; if(!strcmp(a[i], "fullbright")) tmp->flags|=BTGE_TXFL_FULLBRIGHT; if(!strcmp(a[i], "window")) tmp->flags|=BTGE_TXFL_WINDOW; if(!strcmp(a[i], "warpst")) tmp->flags|=BTGE_TXFL_WARPST; if(!strcmp(a[i], "nodraw")) tmp->flags|=BTGE_TXFL_NODRAW; if(!strcmp(a[i], "fluid")) tmp->flags|=BTGE_TXFL_FLUID; if(!strcmp(a[i], "water")) tmp->flags|=BTGE_TXFL_FLUID_WATER; if(!strcmp(a[i], "slime")) tmp->flags|=BTGE_TXFL_FLUID_SLIME; if(!strcmp(a[i], "lava")) tmp->flags|=BTGE_TXFL_FLUID_LAVA; if(!strcmp(a[i], "sewer")) tmp->flags|=BTGE_TXFL_FLUID_SEWER; if(!strcmp(a[i], "noshadow")) tmp->flags|=BTGE_TXFL_NOSHADOW; if(!strcmp(a[i], "lightvol")) { tmp->flags|=BTGE_TXFL_EFFECT_LVOL; tmp->alpha=0.25; } if(!strcmp(a[i], "newscreen")) tmp->flags|=BTGE_TXFL_NEWSCREEN; if(!strcmp(a[i], "keepscreen")) tmp->flags|=BTGE_TXFL_KEEPSCREEN; if(!strcmp(a[i], "gloss")) { tmp->flags|=BTGE_TXFL_GLOSS; tmp->gloss=0.25; } if(!strcmp(a[i], "fog")) { tmp->flags|=BTGE_TXFL_EFFECT_FOG; } if(!strcmp(a[i], "origin")) { tmp->flags|=BTGE_TXFL_EFFECT_ORIGIN; } if(!strcmp(a[i], "antiportal")) { tmp->flags|=BTGE_TXFL_EFFECT_ANTIPORTAL; } if(!strcmp(a[i], "sky")) { tmp->flags|=BTGE_TXFL_NODRAW; tmp->flags|=BTGE_TXFL_MATERIAL_SKY; } } } if(!strcmp(a[0], "$material")) { i=1; if(!strcmp(a[i], "solid")) { tmp->flags|=BTGE_TXFL_MATERIAL_SOLID; } if(!strcmp(a[i], "sky")) { tmp->flags|=BTGE_TXFL_MATERIAL_SKY; } if(!strcmp(a[i], "glass")) { tmp->flags|=BTGE_TXFL_MATERIAL_GLASS; } if(!strcmp(a[i], "wood")) { tmp->flags|=BTGE_TXFL_MATERIAL_WOOD; } if(!strcmp(a[i], "metal")) { tmp->flags|=BTGE_TXFL_MATERIAL_METAL; } if(!strcmp(a[i], "flesh")) { tmp->flags|=BTGE_TXFL_MATERIAL_FLESH; } if(!strcmp(a[i], "concrete")) { tmp->flags|=BTGE_TXFL_MATERIAL_CONCRETE; } if(!strcmp(a[i], "foam")) { tmp->flags|=BTGE_TXFL_MATERIAL_FOAM; } if(!strcmp(a[i], "computer")) { tmp->flags|=BTGE_TXFL_MATERIAL_COMPUTER; } if(!strcmp(a[i], "unbreakable_glass")) { tmp->flags|=BTGE_TXFL_MATERIAL_UBGLASS; } if(!strcmp(a[i], "stone")) { tmp->flags|=BTGE_TXFL_MATERIAL_STONE; } } if(!strcmp(a[0], "$lightvol")) { tmp->flags|=BTGE_TXFL_EFFECT_LVOL; tmp->alpha=atof(a[1]); } if(!strcmp(a[0], "$fog")) { tmp->flags|=BTGE_TXFL_EFFECT_FOG; } if(!strcmp(a[0], "$alpha")) { tmp->flags|=BTGE_TXFL_VALPHA; tmp->alpha=atof(a[1]); } if(!strcmp(a[0], "$gloss")) { tmp->flags|=BTGE_TXFL_GLOSS; tmp->gloss=atof(a[1]); } if(!strcmp(a[0], "$scale")) { if(a[2]) { tmp->xscale=atof(a[1]); tmp->yscale=atof(a[2]); }else { tmp->xscale=atof(a[1]); tmp->yscale=atof(a[1]); } } if(!strcmp(a[0], "$script")) { } if(!strcmp(a[0], "$shader")) { } if(!strcmp(a[0], "$sky")) { tmp->flags|=BTGE_TXFL_NODRAW; tmp->flags|=BTGE_TXFL_MATERIAL_SKY; // BTGE_Sky_LoadSky(a[1]); } if(!strcmp(a[0], "$video")) { } if(!strcmp(a[0], "$chromakey")) { } if(!strcmp(a[0], "$drawfunc")) { } if(!strcmp(a[0], "$fparm")) { } if(!strcmp(a[0], "$vparm")) { } if(!strcmp(a[0], "$texparm")) { } } vfclose(fd); return(0); }
/*-- Cat pdnet;Protocols;Meta0 Form int Meta0_HandleConnection(Meta0_Con *con); Description Polls a connection for activity. Status Internal --*/ int Meta0_HandleConnection(Meta0_Con *con) { Meta0_PortInfo *inf; int i, sz; char *s, *t; // printf("Meta0_HandleConnection %p\n", con); if(!con->buf) { con->buf=gcalloc(65536); con->end=con->buf; } inf=con->info; if(inf && inf->think) inf->think(con); while(1) { memset(con->end, 0, 65536-(con->end-con->buf)); sz=vfread(con->end, 1, 65536-(con->end-con->buf), con->sock); if(sz<0)break; // if(sz>0)gc_printf("meta0: %p got %d bytes\n", con, sz); con->end+=sz; *con->end=0; // gc_printf("%s", con->buf); if(con->end==con->buf)break; i=con->end-con->buf; s=con->buf; if(inf->input) sz=inf->input(con); else sz=-1; // gc_printf("meta0 stat: %p %p %d\n", con->buf, s, sz); if(sz==-1)break; s+=sz; if(s!=con->buf) { t=con->buf; while(s<con->end)*t++=*s++; con->end=t; }else break; } if(sz<0) { gc_printf("Meta0: Connection closed, service %s.\n", inf->name); if(inf->closed) inf->closed(con); vfclose(con->sock); con->sock=NULL; meta0_cons[con->num]=NULL; if(con->buf)gcfree(con->buf); gcfree(con); } return(0); }
int ftp_log(void * pio) { FC_MENULOG(); if (log_flag==TRUE) { /* Logging is enabled. Disable it */ log_flag=FALSE; #ifdef FC_LOGFILE if (ftplog) { ns_printf(pio, "Logging to file disabled\n"); vfclose((VFILE *)fc_file_io.id); } else #endif /*FC_LOGFILE */ ns_printf(pio, "Logging to STDIO disabled\n"); } else { /* Logging is disabled. Enable it. If an argument is passed, * then it is name of logfile. Hence enable logging to file. If * no argument is passed, then enable logging to stdio. */ #ifdef FC_LOGFILE char * filename=NULL; GEN_IO io= (GEN_IO) pio ; VFILE * fp; #endif /*FC_LOGFILE */ log_flag=TRUE; ftplog =NULL; /* By default log to stdio */ #ifdef FC_LOGFILE /* extract args from command buffer */ if ( io != NULL ) { filename = nextarg(io->inbuf); if(*filename != 0) /* user passed file name */ { fp=vfopen(filename, "w"); if (fp==NULL) { ns_printf(pio, "Can't open file %s.", filename); } else { fc_file_io.id = (long)fp; ftplog = &fc_file_io; } } } if (ftplog) ns_printf(pio, "Logging to file %s enabled\n", filename); else #endif /*FC_LOGFILE */ ns_printf(pio, "Logging to STDIO enabled\n"); } return 0; }
int BGBCC_LoadCSourceBuffer(char *name, char *buf) { char tb[256], tb1[256]; VFILE *fd; FILE *fd2; BCCX_Node *t; byte *obj; char *s, *mod, *buf1, *buf2; int i, sz, t0, t1, dt; // BGBGC_InitSig(); dyllMetaInit(); if(!buf) return(-1); #if 0 if(!name) { // name=BASM_GenSym(); s=buf; i=0; while(*s)i=(i*8191)+(*s++); sprintf(tb, "TMP_%08X", i); name=dystring(tb); } #endif mod=NULL; if(name) { strcpy(tb, name); s=tb; while(*s) { if(*s=='/')*s='_'; if(*s=='\\')*s='_'; if(*s==':')*s='_'; s++; } while((s>tb) && (*s!='.'))s--; if(s>tb)*s=0; mod=dystrdup(tb); } t0=clock(); t=BGBCP_ModuleBuffer(name, mod, buf); // BGBGC_Collect(); if(!t) return(-1); #if 1 if(mod) { sprintf(tb1, "dump/%s_ast.txt", mod); fd=vffopen(tb1, "wt"); if(fd) { BCCX_PrintVF(fd, t); vfclose(fd); } } #endif #if 0 if(mod) { sprintf(tb1, "dump/%s_ast.txt", mod); fd2=fopen(tb1, "wt"); if(fd) { BCCX_PrintFD(fd2, t); fclose(fd2); } } #endif t1=clock(); dt=t1-t0; printf("BGBCC_LoadModule: Parse took %dms\n", (int)(1000*(dt/(float)CLOCKS_PER_SEC))); // BGBGC_Collect(); buf1=BGBCC_CompileModule(tb, t); if(!buf1) return(-1); dyllMetaCommit(); // BGBGC_SaveSig(); BGBCC_CleanupAll(); #if 1 if(mod) { sprintf(tb1, "dump/%s_ril.txt", mod); fd=vffopen(tb1, "wt"); if(fd) { vfwrite(buf1, 1, strlen(buf1), fd); vfclose(fd); } } #endif // SXIL_BeginModule(mod); // sxil_puts(buf1); // buf2=SXIL_EndModuleBuffer(NULL); if(!buf2) return(-1); #if 1 if(mod) { sprintf(tb1, "dump/%s_asm.txt", mod); fd=vffopen(tb1, "wt"); if(fd) { vfwrite(buf2, 1, strlen(buf2), fd); vfclose(fd); } } #endif BASM_BeginAssembly(mod); basm_puts(buf2); BASM_EndAssembly(); dt=clock()-t1; printf("BGBCC_LoadModule: Compile took %dms\n", (int)(1000*(dt/(float)CLOCKS_PER_SEC))); return(0); }
Sequence *free_constraint_list (Constraint_list *CL) { Sequence *S; int a, b; Constraint_list *pCL; /*Prepare the selective freeing of the CL data structure: If the CL has been obtained from copy, every pointer that is identical to the parent CL (CL->pCL) will not be saved. */ if ( !CL)return NULL; else S=CL->S; if ( CL->copy_mode==SOFT_COPY && !CL->pCL) {vfree(CL); return S;} else if ( CL->copy_mode==SOFT_COPY) { pCL=CL->pCL; CL->residue_index=NULL; if ( CL->M ==pCL->M )CL->M=NULL; if (CL->start_index ==pCL->start_index )CL->start_index=NULL; if (CL->end_index ==pCL->end_index )CL->end_index=NULL; if ( CL->fp ==pCL->fp )CL->fp=NULL; if ( CL->matrices_list ==pCL->matrices_list )CL->matrices_list=NULL; if ( CL->STRUC_LIST ==pCL->STRUC_LIST )CL->STRUC_LIST=NULL; if ( CL->W ==pCL->W )CL->W=NULL; if ( CL->DM ==pCL->DM )CL->DM=NULL; if ( CL->ktupDM ==pCL->ktupDM )CL->ktupDM=NULL; if ( CL->translation ==pCL->translation )CL->translation=NULL; if ( CL->moca ==pCL->moca )CL->moca=NULL; if ( CL->Prot_Blast ==pCL->Prot_Blast )CL->Prot_Blast=NULL; if ( CL->DNA_Blast ==pCL->DNA_Blast )CL->DNA_Blast=NULL; if ( CL->Pdb_Blast ==pCL->Pdb_Blast )CL->Pdb_Blast=NULL; if ( CL->seq_for_quadruplet ==pCL->seq_for_quadruplet )CL->seq_for_quadruplet=NULL; if ( CL->TC ==pCL->TC )CL->TC=NULL; } /*End of selective freeing of the CL data structure*/ if ( CL->residue_index)free_arrayN(CL->residue_index, 3); if ( CL->M)free_int (CL->M, -1); if ( CL->fp)vfclose (CL->fp); if ( CL->matrices_list)free_char(CL->matrices_list,-1); if ( CL->start_index)free_int ( CL->start_index,-1); if ( CL->end_index)free_int ( CL->end_index,-1); if ( CL->STRUC_LIST)free_sequence ( CL->STRUC_LIST, (CL->STRUC_LIST)->nseq); if ( CL->W)free_weights (CL->W); CL->DM=free_distance_matrix (CL->DM); CL->ktupDM=free_distance_matrix (CL->ktupDM); if ( CL->translation)vfree(CL->translation); if ( CL->moca)free_moca (CL->moca); if ( CL->Prot_Blast)free_blast_param ( CL->Prot_Blast); if ( CL->DNA_Blast) free_blast_param ( CL->DNA_Blast); if ( CL->Pdb_Blast) free_blast_param ( CL->Pdb_Blast); if ( CL->TC) free_TC_param ( CL->TC); if (CL->seq_for_quadruplet)vfree (CL->seq_for_quadruplet); vfree(CL); return S; }
int BGBCC_LoadCHeader(char *name) { char tb[256], tb1[256]; VFILE *fd; BCCX_Node *t; byte *obj; char *s, *buf, *buf1, *buf2; int i, sz, t0, t1, dt; if(BGBCC_CacheCheckFile(name)>0) { //header is up-to-date and known to metadata?... // s=DYLL_MetaPath_LookupKey(name); s=dyllMetaLookupKey(name); if(s && (s!=UNDEFINED) && !strcmp(s, "header")) { printf("BGBCC_LoadCHeader: '%s' is fresh\n", name); return(0); } printf("BGBCC_LoadCHeader: '%s' lacks metadata\n", name); }else { printf("BGBCC_LoadCHeader: '%s' is stale\n", name); } buf=bgbcc_loadfile(name, &sz); if(!buf) { for(i=0; i<bgbcc_nsrc; i++) { sprintf(tb, "%s/%s", bgbcc_src[i], name); buf=bgbcc_loadfile(tb, &sz); if(buf)break; } } if(!buf) { buf=BGBPP_LoadInclude(NULL, name, &sz); } if(!buf) { printf("BGBCC_LoadCHeader: fail load '%s'\n", name); return(-1); } printf("BGBCC_LoadCHeader: %s %d bytes\n", name, sz); strcpy(tb, name); s=tb; while(*s) { if(*s=='/')*s='_'; if(*s=='\\')*s='_'; if(*s==':')*s='_'; s++; } while((s>tb) && (*s!='.'))s--; if(s>tb)*s=0; // printf("BGBCC_LoadModule: Begin Parse\n"); t0=clock(); t=BGBCP_ModuleBuffer(name, tb, buf); if(!t) { // free(buf); return(-1); } // BCCX_PrintFD(stdout, t); #if 1 sprintf(tb1, "dump/%s_ast.txt", tb); fd=vffopen(tb1, "wt"); if(fd) { BCCX_PrintVF(fd, t); vfclose(fd); } #endif t1=clock(); dt=t1-t0; printf("BGBCC_LoadModule: Parse took %dms\n", (int)(1000*(dt/(float)CLOCKS_PER_SEC))); buf1=BGBCC_CompileModule(tb, t); // DYLL_MetaPath_BindKey(name, "header"); dyllMetaBindKey(name, "header"); // BGBGC_SaveSig(); dyllMetaCommit(); BGBCC_CleanupAll(); BGBCC_UpdateCheckFile(name); bgbcc_loads[bgbcc_nloads++]=basm_strdup(name); // free(buf1); return(0); }
int BTGE_Voxel_LoadDungeonInfo( BTGE_VoxelDungeonInfo *inf, char *name) { VFILE *fd; void *p; char buf[256]; char **a, *s; int i, j, k; // strcpy(buf, tmp->name); strcpy(buf, name); s=buf+strlen(buf); while((s>buf) && (*s!='.'))s--; if(*s!='.')s=buf+strlen(buf); strcpy(s, ".txt"); fd=vffopen(buf, "rt"); if(!fd)return(-1); while(!vfeof(fd)) { vfgets(buf, 255, fd); a=gcrsplit(buf); if(!a[0])continue; if(!strcmp(a[0], "$flags")) { } if(!strcmp(a[0], "$dung_vox")) { j=BTGE_Voxel_IndexVoxelName(a[1]); if(j<0) { printf("BTGE_Voxel_LoadDungeonInfo: " "%s Bad Voxel Type %s\n", name, a[1]); continue; } i=inf->n_idx++; inf->idx_vox[i].type=j; inf->idx_rgba[i*4+0]=atoi(a[2]); inf->idx_rgba[i*4+1]=atoi(a[3]); inf->idx_rgba[i*4+2]=atoi(a[4]); inf->idx_rgba[i*4+3]=255; for(j=5; a[j]; j++) { if(!strcmp(a[j], "unbreakable")) { inf->idx_vox[i].type|=VOX_TYM_UNBREAKABLE; } if(!strcmp(a[j], "flexform")) { inf->idx_vox[i].type|=VOX_TYM_FLEXFORM; } if(!strncmp(a[j], "aux=", 4)) { inf->idx_vox[i].aux=atoi(a[j]+4); } if(!strncmp(a[j], "aux2=", 5)) { inf->idx_vox[i].aux2=atoi(a[j]+5); } if(!strncmp(a[j], "vlight=", 7)) { inf->idx_vox[i].vlight=atoi(a[j]+7); } if(!strncmp(a[j], "slight=", 7)) { inf->idx_vox[i].slight=atoi(a[j]+7); } if(!strncmp(a[j], "delay=", 6)) { inf->idx_vox[i].delay=atoi(a[j]+6); } } } if(!strcmp(a[0], "$dung_allow_nx")) { i=inf->allow_n_edge[0]++; inf->allow_edge[0][i]=BTGE_Voxel_IndexDungeonName(a[1]); } if(!strcmp(a[0], "$dung_allow_px")) { i=inf->allow_n_edge[1]++; inf->allow_edge[1][i]=BTGE_Voxel_IndexDungeonName(a[1]); } if(!strcmp(a[0], "$dung_allow_ny")) { i=inf->allow_n_edge[2]++; inf->allow_edge[2][i]=BTGE_Voxel_IndexDungeonName(a[1]); } if(!strcmp(a[0], "$dung_allow_py")) { i=inf->allow_n_edge[3]++; inf->allow_edge[3][i]=BTGE_Voxel_IndexDungeonName(a[1]); } if(!strcmp(a[0], "$dung_allow_nz")) { i=inf->allow_n_edge[4]++; inf->allow_edge[4][i]=BTGE_Voxel_IndexDungeonName(a[1]); } if(!strcmp(a[0], "$dung_allow_pz")) { i=inf->allow_n_edge[5]++; inf->allow_edge[5][i]=BTGE_Voxel_IndexDungeonName(a[1]); } if(!strcmp(a[0], "$dung_allow_biome")) { i=inf->allow_n_biome++; inf->allow_biome[i]=BTGE_Voxel_IndexBiomeName(a[1]); } if(!strcmp(a[0], "$dung_deny_biome")) { i=inf->deny_n_biome++; inf->deny_biome[i]=BTGE_Voxel_IndexBiomeName(a[1]); } if(!strcmp(a[0], "$dung_min_z")) { inf->min_z=atoi(a[1]); } if(!strcmp(a[0], "$dung_max_z")) { inf->max_z=atoi(a[1]); } } vfclose(fd); return(0); }