int main(int argc, char *argv[]){ char*gcf_name; archive_t gcf=NULL; RTinitPopt(&argc,&argv,options,1,-1,&gcf_name,NULL,"([-c] <gcf> (<dir>|<file>)*) | (-x <gcf> [<dir>|<pattern>])", "Tool for creating and extracting GCF archives\n\nOptions"); compression_policy_compile(policy); if (operation==GCF_EXTRACT) { char *out_name=RTinitNextArg(); archive_t dir; if(out_name){ if(RTinitNextArg()){ Fatal(1,error,"extraction uses gcf -x <gcf> [<dir>|<pattern>]"); } if (strstr(out_name,"%s")) { dir=arch_fmt(out_name,file_input,file_output,blocksize); } else { dir=arch_dir_create(out_name,blocksize,force?DELETE_ALL:DELETE_NONE); } } else { dir=arch_dir_open(".",blocksize); } if (is_a_dir(gcf_name)){ gcf=arch_dir_open(gcf_name,blocksize); } else { gcf=arch_gcf_read(raf_unistd(gcf_name)); } archive_copy(gcf,"auto",dir,NULL,blocksize); arch_close(&dir); arch_close(&gcf); } else { if (operation==GCF_FILE){ gcf=arch_gcf_create(raf_unistd(gcf_name),blocksize,blocksize*blockcount,0,1); } else { gcf=arch_dir_create(gcf_name,blocksize,force?DELETE_ALL:DELETE_NONE); } for(;;){ char *input_name=RTinitNextArg(); if (!input_name) break; if (is_a_dir(input_name)){ Warning(info,"copying contents of %s",input_name); archive_t dir=arch_dir_open(input_name,blocksize); archive_copy(dir,NULL,gcf,get_compression,blocksize); arch_close(&dir); } else { Warning(info,"copying %s",input_name); stream_t is=file_input(input_name); stream_t os=arch_write(gcf,input_name,get_compression(input_name),1); char buf[blocksize]; for(;;){ int len=stream_read_max(is,buf,blocksize); if (len) stream_write(os,buf,len); if(len<blocksize) break; } stream_close(&is); stream_close(&os); } } arch_close(&gcf); } }
static int copy_item(void*arg,int id,char*name){ (void)id; copy_context_t ctx=(copy_context_t)arg; Warning(info,"copying %s",name); char*compression=ctx->encode?ctx->encode(name):NULL; Warning(debug,"compression method is %s",compression); stream_t is=arch_read(ctx->src,name,ctx->decode); stream_t os=arch_write(ctx->dst,name,compression,1); char buf[ctx->bs]; for(;;){ int len=stream_read_max(is,buf,ctx->bs); if (len) stream_write(os,buf,len); if(len<ctx->bs) break; } stream_close(&is); stream_close(&os); return 0; }
static void lts_write_dir(archive_t archive,string_map_t map,lts_t lts,int segments){ if (map) arch_set_write_policy(archive,map); dir_info_t info=DIRinfoCreate(segments); int i,j; uint32_t k; char filename[1024]; stream_t output; stream_t *src_out; stream_t *lbl_out; stream_t *dst_out; if (lts->root_count !=1) Abort("LTS has %u initial states DIR requires 1",lts->root_count); lts_set_type(lts,LTS_BLOCK); info->label_tau=lts->tau; int type_no=lts_type_get_edge_label_typeno(lts->ltstype,0); switch(lts_type_get_format(lts->ltstype,type_no)){ case LTStypeChunk: case LTStypeEnum: break; default: Abort("DIR is limited to Chunk/Enum edge labels."); } info->label_count=VTgetCount(lts->values[type_no]); info->initial_seg=lts->root_list[0]%segments; info->initial_ofs=lts->root_list[0]/segments; output=arch_write(archive,"TermDB"); int last_idx = 0; table_iterator_t it = VTiterator (lts->values[type_no]); while (IThasNext(it)) { chunk label_c = ITnext (it); int idx = VTputChunk (lts->values[type_no], label_c); while (last_idx < idx) { // fill non-dense indices write_chunk (output, (chunk){0, ""}); last_idx++; } write_chunk (output, label_c); } DSclose(&output); src_out=(stream_t*)RTmalloc(segments*sizeof(stream_t)); lbl_out=(stream_t*)RTmalloc(segments*sizeof(stream_t)); dst_out=(stream_t*)RTmalloc(segments*sizeof(stream_t)); for(i=0;i<segments;i++) { for(j=0;j<segments;j++) { sprintf(filename,"src-%d-%d",i,j); src_out[j]=arch_write(archive,filename); sprintf(filename,"label-%d-%d",i,j); lbl_out[j]=arch_write(archive,filename); sprintf(filename,"dest-%d-%d",i,j); dst_out[j]=arch_write(archive,filename); } for(j=i;j<(int)lts->states;j+=segments){ for(k=lts->begin[j];k<lts->begin[j+1];k++){ int dseg=(lts->dest[k])%segments; info->transition_count[i][dseg]++; DSwriteU32(src_out[dseg],info->state_count[i]); DSwriteU32(lbl_out[dseg],lts->label[k]); DSwriteU32(dst_out[dseg],(lts->dest[k])/segments); } info->state_count[i]++; } for(j=0;j<segments;j++) { DSclose(&src_out[j]); DSclose(&lbl_out[j]); DSclose(&dst_out[j]); } } info->info="bsim2 output"; output=arch_write(archive,"info"); DIRinfoWrite(output,info); DSclose(&output); info->info=NULL; DIRinfoDestroy(info); }