// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include using namespace fsa; void usage(const char *name, const char *errormsg = NULL) { if(errormsg!=NULL){ fprintf(stderr,"%s: %s\n",name,errormsg); } fprintf(stderr,"usage:\n"); fprintf(stderr," %s [OPTIONS] fsa\n",name); fprintf(stderr,"\n"); fprintf(stderr," Valid options are:\n"); fprintf(stderr," -h display this help\n"); fprintf(stderr," -V display version number\n"); fprintf(stderr,"\n"); } void version() { std::cout << "fsainfo " << FSA::VER/1000000 << "." << (FSA::VER/1000)%1000 << "." << FSA::VER%1000; if(FSA::VER != FSA::libVER()){ std::cout << " (library " << FSA::libVER()/1000000 << "." << (FSA::libVER()/1000)%1000 << "." << FSA::libVER()%1000 << ")"; } std::cout << std::endl; } int main(int argc, char** argv) { const char *fsa_file; int opt; extern int optind; while((opt=getopt(argc,argv,"hV")) != -1){ switch(opt){ case 'h': usage(argv[0]); return 0; case 'V': version(); return 0; case '?': usage(argv[0],"unrecognized option"); return 1; } } if(optind!=argc-1){ usage(argv[0],"required parameter fsa is missing"); return 1; } fsa_file = argv[optind]; FSA::Header header; size_t r; int fd = ::open(fsa_file,O_RDONLY); if(fd<0){ std::cerr << "Failed to open fsa file (" << fsa_file << ")" << std::endl; return 1; } else{ r=::read(fd,&header,sizeof(header)); ::close(fd); if(r