int do_show(FILE *stream, const char *path_p, const struct stat *st, acl_t acl, acl_t dacl) { struct name_list *acl_names = get_list(st, acl), *first_acl_name = acl_names; struct name_list *dacl_names = get_list(st, dacl), *first_dacl_name = dacl_names; int acl_names_width = max_name_length(acl_names); int dacl_names_width = max_name_length(dacl_names); acl_entry_t acl_ent; acl_entry_t dacl_ent; char acl_mask[ACL_PERMS+1], dacl_mask[ACL_PERMS+1]; int ret; names_width = 8; if (acl_names_width > names_width) names_width = acl_names_width; if (dacl_names_width > names_width) names_width = dacl_names_width; acl_mask[0] = '\0'; if (acl) { acl_mask_perm_str(acl, acl_mask); ret = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_ent); if (ret == 0) acl = NULL; if (ret < 0) return ret; } dacl_mask[0] = '\0'; if (dacl) { acl_mask_perm_str(dacl, dacl_mask); ret = acl_get_entry(dacl, ACL_FIRST_ENTRY, &dacl_ent); if (ret == 0) dacl = NULL; if (ret < 0) return ret; } fprintf(stream, "# file: %s\n", xquote(path_p, "\n\r")); while (acl_names != NULL || dacl_names != NULL) { acl_tag_t acl_tag, dacl_tag; if (acl) acl_get_tag_type(acl_ent, &acl_tag); if (dacl) acl_get_tag_type(dacl_ent, &dacl_tag); if (acl && (!dacl || acl_tag < dacl_tag)) { show_line(stream, &acl_names, acl, &acl_ent, acl_mask, NULL, NULL, NULL, NULL); continue; } else if (dacl && (!acl || dacl_tag < acl_tag)) { show_line(stream, NULL, NULL, NULL, NULL, &dacl_names, dacl, &dacl_ent, dacl_mask); continue; } else { if (acl_tag == ACL_USER || acl_tag == ACL_GROUP) { id_t *acl_id_p = NULL, *dacl_id_p = NULL; if (acl_ent) acl_id_p = acl_get_qualifier(acl_ent); if (dacl_ent) dacl_id_p = acl_get_qualifier(dacl_ent); if (acl && (!dacl || *acl_id_p < *dacl_id_p)) { show_line(stream, &acl_names, acl, &acl_ent, acl_mask, NULL, NULL, NULL, NULL); continue; } else if (dacl && (!acl || *dacl_id_p < *acl_id_p)) { show_line(stream, NULL, NULL, NULL, NULL, &dacl_names, dacl, &dacl_ent, dacl_mask); continue; } } show_line(stream, &acl_names, acl, &acl_ent, acl_mask, &dacl_names, dacl, &dacl_ent, dacl_mask); } } free_list(first_acl_name); free_list(first_dacl_name); return 0; }
int main(int argc,char **argv) { int optind=1; std::vector<Index*> indexes; std::string::size_type max_name_length(0); for(int i=optind; i<argc;++i) { if(argv[i][0]!='/') { std::cerr << "expected a full path name but got "<< argv[i] << std::endl; return EXIT_FAILURE; } } std::cout << "#ifndef FAIDX_H\n#define FAIDX_H\n"; std::cout << "#define FASTA_FILE_COUNT \t" << (argc-optind) << std::endl; std::cout << "static const char* fasta_filenames[FASTA_FILE_COUNT]={" << std::endl; for(int i=optind; i<argc;++i) { std::cout << "\t\"" << argv[i]<< "\" " <<(i+1==argc?"":",") <<" /* "<< (i-optind) << "th" << " */" << std::endl; } std::cout << "};\n" << std::endl; for(int i=optind; i<argc;++i) { errno=0; FILE* in; long offset=-1L; int curr_line_size=0; Index* current=NULL; if(argv[i][0]!='/') { std:: cerr << "file " << argv[i] << " should be a full unix path starting with '/'" << std::endl; std::exit(EXIT_FAILURE); } in=std::fopen(argv[i],"r"); if(in==NULL) { std:: cerr << "cannot open " << argv[i] << " " << std::strerror(errno) << std::endl; exit(EXIT_FAILURE); } for(;;) { int c=std::fgetc(in); if(c!=EOF) offset++; //end of line or end of file if(current!=NULL && (c==EOF || (c=='\n'))) { current->indexLineSize= ( current->indexLineSize > curr_line_size? current->indexLineSize: curr_line_size ); curr_line_size=0; } if(c==-1 || c=='>') { if(current!=NULL) { indexes.push_back(current); current=NULL; } if(c==-1) break; current=new Index; current->file_index=(i-optind); current->offsetNameStart= offset; for(;;) { c=std::fgetc(in); if(c==EOF) { std::cerr << "unfinished name at offset "<< offset << std::endl; exit(EXIT_FAILURE); } offset++; if(c=='\n') break; current->name+=((char)c); } max_name_length=std::max(max_name_length,current->name.size()); current->offsetNameEnd=offset; current->offsetSeqStart=offset+1; current->offsetSeqEnd=offset+1; current->seqLength=0; curr_line_size=0; } else if(current!=NULL) { if(c=='\n') { //already processed ignore } else if(std::isalpha(c)) { current->offsetSeqEnd= offset+1L; current->seqLength++; curr_line_size++; } else { std::cerr << "Illegal character " << (char)c<< " at " << offset << std::endl; std::exit(EXIT_FAILURE); } } } std::fclose(in); } std::sort(indexes.begin(),indexes.end(),Index::lt); std::cout << "#define FASTA_SEQUENCE_MAX_NAME_LENGTH\t" << (max_name_length+1) << std::endl; std::cout << "typedef struct FastaIndex_t\n" << "\t{\n" << "\tchar name[FASTA_SEQUENCE_MAX_NAME_LENGTH];\n" << "\tint fileIndex;\n" << "\tunsigned long seqLength;\n" << "\tunsigned long offsetSeqStart;\n" << "\tunsigned long offsetSeqEnd;\n" << "\tint lineSize;\n" << "\t}FastaIndex,*FastaIndexPtr;" << std::endl; std::cout << "#define FASTA_SEQUENCE_COUNT\t" << (indexes.size()) << std::endl; std::cout << "static const FastaIndex fastaIndexes[FASTA_SEQUENCE_COUNT]={\n"; for(std::vector<Index*>::size_type i=0;i< indexes.size();++i) { Index* curr= indexes.at(i); if(i>0) std::cout << ",\n"; std::cout << "\t{"; std::cout << "\"" << curr->name << "\"," << curr->file_index << "," << curr->seqLength << "," << curr->offsetSeqStart<< "," << curr->offsetSeqEnd << "," << curr->indexLineSize ; std::cout << "}"; delete curr; } std::cout << "\n};" << std::endl; std::cout << "#endif" << std::endl; return EXIT_SUCCESS; }