void lts_read(char *name,lts_t lts){ int format=lts_guess_format(name); switch(format){ case LTS_GCF: case LTS_DIR: { archive_t archive=format==LTS_DIR?arch_dir_open(name,65536):arch_gcf_read(raf_unistd(name)); stream_t ds=arch_read(archive,"info"); int magic=DSreadS32(ds); DSclose(&ds); if (magic==31) { // DIR in .dir lts_read_dir(archive,lts); arch_close(&archive); return; } else { // VEC in .dir arch_close(&archive); break; } } case LTS_TRA: lts_read_tra(name,lts); return; case LTS_IMCA: Abort("no read support for imca"); default: break; } lts_file_t src=lts_file_open(name); int segments=lts_file_get_segments(src); lts_type_t ltstype=lts_file_get_type(src); if (lts->ltstype==NULL){ lts_set_sig(lts,ltstype); } else { Print(info,"** warning ** omitting signature check"); } lts_file_t dst=lts_writer(lts,segments,src); int T=lts_type_get_type_count(ltstype); for(int i=0;i<T;i++){ if (lts->values[i]) lts_file_set_table(src,i,lts->values[i]); } lts_file_copy(src,dst); lts_file_close(src); lts_file_close(dst); }
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 int copy_item(void*arg,int id,const char*name){ (void)id; copy_context_t ctx=(copy_context_t)arg; Print(info,"copying %s",name); char*compression=SSMcall(ctx->encode,name); Print(debug,"compression method is %s",compression); stream_t is=arch_read(ctx->src,(char*)name); stream_t os=arch_write_apply(ctx->dst,(char*)name,compression); 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_read_dir(archive_t archive,lts_t lts){ Print(infoShort,"opening info"); stream_t input=arch_read(archive,"info"); dir_info_t info=DIRinfoRead(input,1); DSclose(&input); int segments=info->segment_count; Print(infoShort,"got info for %d segments",segments); int offset[segments]; offset[0]=0; for(int i=1;i<segments;i++){ offset[i]=info->state_count[i-1]+offset[i-1]; } int s_count=0; int t_count=0; for(int i=0;i<segments;i++){ s_count+=info->state_count[i]; for(int j=0;j<segments;j++){ t_count+=info->transition_count[i][j]; } } Print(infoShort,"counted %u states and %u transitions",s_count,t_count); lts_set_sig(lts,single_action_type()); lts_set_type(lts,LTS_LIST); lts_set_size(lts,1,s_count,t_count); lts->root_list[0]=offset[info->initial_seg]+info->initial_ofs; lts->tau=info->label_tau; Print(infoShort,"getting %d labels from TermDB",info->label_count); input=arch_read(archive,"TermDB"); int type_no=lts_type_get_edge_label_typeno(lts->ltstype,0); for(int i=0;i<info->label_count;i++){ char *line=DSreadLN(input); int len=strlen(line); char data[len]; chunk tmp_chunk=chunk_ld(len,data); string2chunk(line,&tmp_chunk); VTputAtChunk(lts->values[type_no], tmp_chunk, i); } DSclose(&input); Print(infoShort,"got labels"); int t_offset=0; char filename[1024]; for(int i=0;i<segments;i++){ for(int j=0;j<segments;j++){ sprintf(filename,"src-%d-%d",i,j); stream_t src=arch_read(archive,filename); sprintf(filename,"label-%d-%d",i,j); stream_t lbl=arch_read(archive,filename); sprintf(filename,"dest-%d-%d",i,j); stream_t dst=arch_read(archive,filename); for(int k=0;k<info->transition_count[i][j];k++){ lts->src[t_offset]=offset[i]+DSreadU32(src); lts->label[t_offset]=DSreadU32(lbl); lts->dest[t_offset]=offset[j]+DSreadU32(dst); t_offset++; } DSclose(&src); DSclose(&lbl); DSclose(&dst); } } DIRinfoDestroy(info); }