void RF_destroy(RF_class *RF, WORD compact_threshold) { OD_link *link, *next; WORD lost_percent; ULONG lost_space, entry, nentries; RF_class *new_class, *old; BYTE *RF_filename, *temp_fn; if (RF->touched) { lseek(RF->file, 0L, SEEK_SET); r_write(RF->file, &RF->hdr, sizeof(RF_file_hdr)); } link = RF->root; while (link != NULL) { if (link->touched) { lseek(RF->file, link->origin, SEEK_SET); r_write(RF->file, &link->blk, sizeof(OD_block)); } next = link->next; mem_free(link); link = next; } close(RF->file); lost_space = RF->hdr.lost_space; lost_percent = (WORD) ((lost_space * 100L) / RF->hdr.file_size); RF_filename = str_alloc(RF->filename); mem_free(RF->filename); mem_free(RF); if (lost_space && (lost_percent >= compact_threshold)) { rename(RF_filename, temp_fn = temp_filename(NULL)); old = RF_construct(temp_fn, 0); new_class = RF_construct(RF_filename, 1); new_class->hdr.modify_time = old->hdr.modify_time; new_class->hdr.create_time = old->hdr.create_time; new_class->touched = 1; nentries = RF_entry_count(old); for (entry = 0; entry < nentries; entry++) { RF_new_entry(new_class, &old->file, RF_header(old, entry), RTYP_HOUSECLEAN); RF_set_flags(new_class, entry, RF_flags(old, entry)); } RF_destroy(new_class, 0); RF_destroy(old, 100); remove_tempfile(temp_fn); } mem_free(RF_filename); }
int main ( int argc, char *argv[] ) { Param params; FlowCom *comPtr = NULL; char line [ LINE_LEN ]; while ( argc > 1 ) { if ( !strcmp( argv[1], "-D" ) ) { setDebugFlag(); } else if ( !strcmp( argv[1], "-V" ) ) { printf ( "%s\n", VERSION ); exit ( 0 ); } else { break; } argv++; argc--; } open_tempfile(); open_infile ( ( argc > 1 ) ? argv[ 1 ] : NULL ); tprintf ( "%% picture environment flowchart generated by flow " ); tprintf ( "%s\n", VERSION ); while ( readline_infile ( line, LINE_LEN ) != NULL ) { if ( ( comPtr = getCommand ( line, params ) ) != NULL ) { switch ( comPtr -> command ) { case MACRO: if ( doMacro ( params ) ) { errout ( E_NO_END_MACRO ); } break; case EXPAND: doExpand ( params ); break; default: if ( !doCommand ( comPtr, params ) ) { return 10; } } } else { break; } } close_infile(); close_tempfile(); apply_tempfile ( getPic(), ( argc > 2 ) ? argv[ 2 ] : NULL ); remove_tempfile(); // dumpFigure(); return 0; /* just to suppress the warning */ }