void Stop () { // Ignore if we're not recording if (!f) return; // Silence the sound in case index generation is slow Sound::Silence(); // Complete the movi chunk, add the index, and complete the RIFF WriteChunkEnd(f, lMoviPos); WriteIndex(f); WriteChunkEnd(f, lRiffPos); // Write the completed file headers WriteFileHeaders(f); // Seek to end before closing if (fseek(f, 0, SEEK_END) != 0) TRACE("!!! AVI::Stop(): Failed to seek to end of recording\n"); // Close the recording fclose(f); f = nullptr; // Free current frame data delete[] pbCurr, pbCurr = nullptr; // Free resample buffer delete[] pbResample, pbResample = nullptr; Frame::SetStatus("Saved %s", pszFile); }
//--------------------------------------------------------------------------- void Record::WriteFields(void) { if (Invalid) return; Field *p = (Field *)Fields.GetHead(); while (p) { p->WriteField(); p = (Field *)p->GetNext(); } WriteIndex(); }
void BuildIndex(const vector<string>& chrom_files, const int& indicator, const string& output_file, uint32_t& size_of_index) { switch (indicator) { case 0: fprintf(stderr, "[BIULD INDEX FOR FORWARD STRAND (C->T)]\n"); break; case 1: fprintf(stderr, "[BIULD INDEX FOR REVERSE STRAND (C->T)]\n"); break; case 2: fprintf(stderr, "[BIULD INDEX FOR FORWARD STRAND (G->A)]\n"); break; case 3: fprintf(stderr, "[BIULD INDEX FOR REVERSE STRAND (G->A)]\n"); } Genome genome; HashTable hash_table; ReadGenome(chrom_files, genome); if (indicator % 2) { ReverseComplementGenome(genome); } if (indicator == 0 || indicator == 1) { C2T(genome.sequence); } else { G2A(genome.sequence); } set<uint32_t> extremal_large_bucket; CountBucketSize(genome, hash_table, extremal_large_bucket); HashToBucket(genome, hash_table, extremal_large_bucket); SortHashTableBucket(genome, hash_table); WriteIndex(output_file, genome, hash_table); size_of_index = hash_table.index_size > size_of_index ? hash_table.index_size : size_of_index; }
/* Ecrit les fichiers conf et index. * KodeWrite, write out newly encoded message and update .cnf and idx files. */ static void KodeWrite(char *Qmail, long klast) { /* Ecrit l'entete du message, suivi du message */ /* Write the reply header followed by the reply itself */ printf("%s...\n", txt[75]); /* "sauvegarde du message" */ rewind(MsgFile); fseek(MsgFile, 0L, SEEK_END); if (fwrite(Qmail, header_SIZE, one_record, MsgFile) != one_record || fwrite(tampon, CountTotalChars, one_record, MsgFile) != one_record) { printf("KodeWrite() %s\n", txt[73]); (void) sleep(3); } else { fflush(MsgFile); /* Update the index */ fseek(IdxFile, 0L, SEEK_END); /*@-strictops */ if (WriteIndex(IdxFile, (long) (ftell(IdxFile) / IDXSIZE), (block_SIZE * (CountBlocks - 1)), klast) == ATP_OK) /*@=strictops */ fflush(IdxFile); } }
// Shut down the manager SBcacheManager::~SBcacheManager( ) { if ( _cacheDir.length( ) > 0 ) { // Lock to be paranoid, makes sure everyone else is done if ( _entryTableMutex.Lock( ) != VXItrd_RESULT_SUCCESS ) { Error (110, L"%s%s", L"mutex", L"entry table mutex"); } else { // Write out the index file WriteIndex( ); // Clear the cache entries _entryTable.erase (_entryTable.begin( ), _entryTable.end( )); _entryLRUList.erase(_entryLRUList.begin(), _entryLRUList.end()); _curSizeBytes.Reset (0); // Clear the directory name _cacheDir = ""; if ( _entryTableMutex.Unlock( ) != VXItrd_RESULT_SUCCESS ) Error (111, L"%s%s", L"mutex", L"entry table mutex"); } } }
static int generate_os(const int nOS, const int fHeader, const int fCompress, const int fGammon, const int nHashSize, bearoffcontext * pbc, FILE * output) { int i; int n; unsigned short int aus[64]; xhash h; FILE *pfTmp = NULL; unsigned int npos; char *tmpfile; int fTTY = isatty(STDERR_FILENO); /* initialise xhash */ if (XhashCreate(&h, nHashSize / (fGammon ? 128 : 64))) { fprintf(stderr, _("Error creating xhash with %d elements\n"), nHashSize / (fGammon ? 128 : 64)); exit(2); } XhashStatus(&h); /* write header */ if (fHeader) { char sz[41]; sprintf(sz, "gnubg-OS-%02d-15-%1d-%1d-0xxxxxxxxxxxxxxxxxxx\n", nOS, fGammon, fCompress); fputs(sz, output); } if (fCompress) { pfTmp = GetTemporaryFile(NULL, &tmpfile); if (pfTmp == NULL) exit(2); } /* loop trough bearoff positions */ n = Combination(nOS + 15, nOS); npos = 0; for (i = 0; i < n; ++i) { if (i) BearOff(i, nOS, aus, fGammon, &h, pbc, fCompress, output, pfTmp); else { memset(aus, 0, 128); aus[0] = 0xFFFF; aus[32] = 0xFFFF; } if (!(i % 100) && fTTY) fprintf(stderr, "1:%d/%d \r", i, n); WriteOS(aus, fCompress, fCompress ? pfTmp : output); if (fGammon) WriteOS(aus + 32, fCompress, fCompress ? pfTmp : output); XhashAdd(&h, i, aus, fGammon ? 128 : 64); if (fCompress) WriteIndex(&npos, aus, fGammon, output); } if (fCompress) { char ac[256]; size_t n; /* write contents of pfTmp to output */ rewind(pfTmp); while (!feof(pfTmp) && (n = fread(ac, 1, sizeof(ac), pfTmp))) { if (fwrite(ac, 1, n, output) != n) { fprintf(stderr, "failed writing to '%s'\n", tmpfile); exit(3); } } if (ferror(pfTmp)) exit(3); fclose(pfTmp); g_unlink(tmpfile); } putc('\n', stderr); XhashStatus(&h); XhashDestroy(&h); return 0; }
int WriteMap(Map *map, char *filename) { if(!map) { printf("Could not write map; null map pointer. Talk to a MapMerge dev about it, this is an internal error.\n"); return 0; } else if(!filename) { printf("Could not write map; null filename. Talk to a MapMerge dev about it, this is an internal error.\n"); return 0; } FILE *mapFile = fopen(filename, "w"); if(!mapFile) { printf("Could not write map; unable to open output file for writing.\n"); return 0; } TileList *tileList = newTileList(); int x, y, z, index; Tile *tile; int data[map->width][map->height][map->levels]; for(z=0; z<map->levels; z++) for(y=0; y<map->height; y++) for(x=0; x<map-> width; x++) { tile = Map_GetTile(map, x, y, z); index = TileList_IndexOfEqualTile(tileList, tile); if(index == -1) index = TileList_AddTile(tileList, tile); data[x][y][z] = index; } index = tileList->numTiles - 1; int i = 0; while(index) { i++; index /= 52; } for(index=0; index<tileList->numTiles; index++) { fprintf(mapFile, "\""); WriteIndex(index, i, mapFile); fprintf(mapFile, "\" = ("); Tile_Write(TileList_GetTile(tileList, index), mapFile); fprintf(mapFile, ")\n"); } for(z=0; z<map->levels; z++) { fprintf(mapFile, "\n(1,1,%d) = {\"\n", z + 1); for(y=0; y<map->height; y++) { for(x=0; x<map->width; x++) WriteIndex(data[x][y][z], i, mapFile); fprintf(mapFile, "\n"); } fprintf(mapFile, "\"}\n"); } fflush(mapFile); fclose(mapFile); return 1; }
Dump::~Dump(void) { WriteIndex(); fseek(_file, 0, SEEK_END); }
void LibClose (void) /* Write remaining data, close both files and copy the temp file to the old * filename */ { /* Do we have a temporary library? */ if (NewLib) { unsigned I; unsigned char Buf [4096]; size_t Count; /* Walk through the object file list, inserting exports into the * export list checking for duplicates. Copy any data that is still * in the old library into the new one. */ for (I = 0; I < CollCount (&ObjPool); ++I) { /* Get a pointer to the object */ ObjData* O = CollAtUnchecked (&ObjPool, I); /* Check exports, make global export table */ LibCheckExports (O); /* Copy data if needed */ if ((O->Flags & OBJ_HAVEDATA) == 0) { /* Data is still in the old library */ fseek (Lib, O->Start, SEEK_SET); O->Start = ftell (NewLib); LibCopyTo (Lib, O->Size); O->Flags |= OBJ_HAVEDATA; } } /* Write the index */ WriteIndex (); /* Write the updated header */ WriteHeader (); /* Close the file */ if (Lib && fclose (Lib) != 0) { Error ("Error closing library: %s", strerror (errno)); } /* Reopen the library and truncate it */ Lib = fopen (LibName, "wb"); if (Lib == 0) { Error ("Cannot open library `%s' for writing: %s", LibName, strerror (errno)); } /* Copy the new library to the new one */ fseek (NewLib, 0, SEEK_SET); while ((Count = fread (Buf, 1, sizeof (Buf), NewLib)) != 0) { if (fwrite (Buf, 1, Count, Lib) != Count) { Error ("Cannot write to `%s': %s", LibName, strerror (errno)); } } } /* Close both files */ if (Lib && fclose (Lib) != 0) { Error ("Problem closing `%s': %s", LibName, strerror (errno)); } if (NewLib && fclose (NewLib) != 0) { Error ("Problem closing temporary library file: %s", strerror (errno)); } }
int main( int argc, char **argv ) { char **nargv; char **sargv; FILE *fin; int fout; char *helpstr[2]; bool f_swtch; f_swtch = FALSE; helpstr[0] = NULL; helpstr[1] = NULL; for( argc=1, sargv=nargv=argv+1; *sargv; ++sargv ) { if( ! _IsCmdSwitch( *sargv ) ) { *nargv++ = *sargv; argc++; } else { switch( (*sargv)[1] ) { case 'n': GenIndex = FALSE; if( f_swtch ) { PrintError( "More than one format switch found in command line\n" ); Usage(); } f_swtch = TRUE; break; case 'v': Verbose = TRUE; break; case 'c': if( (*sargv)[2] != '\0' ) { MaxCol = atoi( &(*sargv)[2] ); } else { if( *++sargv == NULL ) Usage(); MaxCol = atoi( *sargv ); } break; case 'r': if( (*sargv)[2] != '\0' ) { MaxRow = atoi( &(*sargv)[2] ); } else { if( *++sargv == NULL ) Usage(); MaxRow = atoi( *sargv ); } break; case 'h': if( (*sargv)[2] != '\0' ) { Height = atoi( &(*sargv)[2] ); } else { if( *++sargv == NULL ) Usage(); Height = atoi( *sargv ); } break; case 'w': if( (*sargv)[2] != '\0' ) { Width = atoi( &(*sargv)[2] ); } else { if( *++sargv == NULL ) Usage(); Width = atoi( *sargv ); } break; case 'f': if( f_swtch ) { PrintError( "More than one format switch found in command line\n" ); Usage(); } f_swtch = TRUE; if( (*sargv)[2] == '0' ) { GenIndex = FALSE; } else if( (*sargv)[2] == '1' ) { GenStrings = FALSE; } else if( (*sargv)[2] == '2' ) { GenStrings = TRUE; } else { Usage(); } break; default: Usage(); break; } } } if( argc > 1 && strcmp( argv[1], "?" ) == 0 ) { Usage(); } if( argc != 3 ) { Usage(); } InitError( argv[1] ); fin = fopen( argv[1], "rt" ); if( fin == NULL ) { PrintError( "Unable to open '%s' for input\n", argv[1] ); return( -1 ); } fout = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, PMODE_RW ); if( fout == -1 ) { PrintError( "Unable to open '%s' for output\n", argv[2] ); return( -1 ); } pass1( fin, helpstr ); pass2( fin, fout, helpstr ); fclose( fin ); close( fout ); if( GenIndex ) { fout = open( argv[2], O_WRONLY | O_BINARY ); WriteIndex( fout, helpstr, GenStrings ); close( fout ); } FiniError(); HelpMemFree( helpstr[0] ); HelpMemFree( helpstr[1] ); return( 0 ); }