--- trunk/src/applications/atom2md/atom2md.cpp 2008/01/21 21:50:29 1209 +++ trunk/src/applications/atom2md/atom2md.cpp 2008/01/23 03:45:33 1210 @@ -3,10 +3,11 @@ Copyright (C) 1998-2001 by OpenEye Scientific Software command-line handling. Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. -Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison -Some portions Copyright (C) 2004-2005 by Chris Morley +Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison +Some portions Copyright (C) 2004-2006 by Chris Morley +Some portions Copyright (C) 2008 by J. Daniel Gezelter -This file is part of the OOPSE and Open Babel projects. +This file is part of both the OOPSE and Open Babel projects. For more information, see and This program is free software; you can redistribute it and/or modify @@ -20,40 +21,37 @@ GNU General Public License for more details. ***********************************************************************/ #include "config.h" -#if HAVE_IOSTREAM - #include -#elif HAVE_IOSTREAM_H - #include + +// used to set import/export for Cygwin DLLs +#ifdef WIN32 +#define USING_OBDLL #endif -#if HAVE_FSTREAM - #include -#elif HAVE_FSTREAM_H - #include -#endif -#if HAVE_SSTREAM - #include -#elif - #include -#endif +#include + +#include +#include +#include + #include #include #if HAVE_CONIO_H #include #endif +#include #if !HAVE_STRNCASECMP extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); #endif -#include "openbabel/obconversion.hpp" -#include "brains/Register.hpp" +#include using namespace std; using namespace OpenBabel; -using namespace oopse; -void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, - int& arg, int argc, char *argv[]); + +void DoOption(const char* p, OBConversion& Conv, + OBConversion::Option_type typ, int& arg, int argc, + char *argv[]); void usage(); void help(); @@ -62,28 +60,25 @@ int main(int argc,char *argv[]) int main(int argc,char *argv[]) { - registerOBFormats(); OBConversion Conv(&cin, &cout); //default input and output are console - - // string GenOptions; + OBFormat* pInFormat = NULL; OBFormat* pOutFormat = NULL; vector FileList, OutputFileList; string OutputFileName; - // obMessageLevel filterLevel = obWarning; // 2 out of 5 - + // Parse commandline bool gotInType = false, gotOutType = false; - bool UseSavedOptions = false; - + bool SplitOrBatch=false; + char *oext; char *iext; string inputExt; string outputExt; - + //Save name of program without its path (and .exe) string pn(argv[0]); - unsigned int pos; + string::size_type pos; #ifdef _WIN32 pos = pn.find(".exe"); if(pos!=string::npos) @@ -94,10 +89,10 @@ int main(int argc,char *argv[]) program_name=argv[0]; else program_name=argv[0]+pos+1; - + const char* p; int arg; - for (arg = 1; arg < argc; arg++) + for (arg = 1; arg < argc; ++arg) { if (argv[arg]) { @@ -105,22 +100,24 @@ int main(int argc,char *argv[]) { switch (argv[arg][1]) { - + case 'V': { - cout << "atom2md: part of OOPSE " << - OOPSE_VERSION_MAJOR << "." << OOPSE_VERSION_MINOR << "." << - OOPSE_VERSION_TINY << " and Open Babel " << BABEL_VERSION << " -- " + cout << program_name << ": part of OOPSE " << + OOPSE_VERSION_MAJOR << "." << OOPSE_VERSION_MINOR << + "." << OOPSE_VERSION_TINY << + " and Open Babel " << BABEL_VERSION << " -- " << __DATE__ << " -- " << __TIME__ << endl; exit(0); } - + case 'i': gotInType = true; iext = argv[arg] + 2; if(!*iext) - iext = argv[++arg]; //space left after -i: use next argument - + iext = argv[++arg]; // space left after -i: use next + // argument + if (strncasecmp(iext, "MIME", 4) == 0) { // get the MIME type from the next argument @@ -129,23 +126,25 @@ int main(int argc,char *argv[]) } else { - //The ID provided by the OBFormat class is used as the identifying file extension + // The ID provided by the OBFormat class is used as the + // identifying file extension pInFormat = Conv.FindFormat(iext); } if(pInFormat==NULL) { - cerr << program_name << ": cannot read input format!" << endl; + cerr << program_name << ": cannot read input format!" + << endl; usage(); } - inputExt = iext; break; case 'o': gotOutType = true; oext = argv[arg] + 2; if(!*oext) - oext = argv[++arg]; //space left after -i: use next argument - + oext = argv[++arg]; // space left after -i: use next + // argument + if (strncasecmp(oext, "MIME", 4) == 0) { // get the MIME type from the next argument @@ -154,15 +153,25 @@ int main(int argc,char *argv[]) } else pOutFormat = Conv.FindFormat(oext); - + if(pOutFormat==NULL) { - cerr << program_name << ": cannot write output format!" << endl; + cerr << program_name << ": cannot write output format!" + << endl; usage(); } - outputExt = oext; - break; + break; + case 'F': + if(!Conv.SetOutFormat("fpt")) + cout << "FingerprintFormat needs to be loaded" << endl; + else + { + Conv.AddOption("F",OBConversion::OUTOPTIONS); + Conv.Write(NULL); + } + return 0; + case '?': case 'H': if(isalnum(argv[arg][2])) @@ -199,9 +208,57 @@ int main(int argc,char *argv[]) } else help(); - exit(0); - - + exit(0); + + case '-': //long option --name text + { + //Do nothing if name is empty + //Option's text is the next arg provided it doesn't start with - + char* nam = argv[arg]+2; + if(*nam != '\0') + { + string txt; + int i; + for(i=0; iTargetClassDescription()); + pos = objectname.find('\n'); + if(count==1) --pos; + objectname.erase(pos); + pos = objectname.rfind(' '); + if(pos==std::string::npos) + pos=0; + std::clog << count << objectname.substr(pos) << " converted" << endl; if(OutputFileList.size()>1) { clog << OutputFileList.size() << " files output. The first is " << OutputFileList[0] <] [-o] " << endl; @@ -345,7 +442,7 @@ void help() void help() { - cout << "Open Babel converts chemical structures from one file format to another"<< endl << endl; + cout << program_name << " converts chemical structures from one file format to another"<< endl << endl; cout << "Usage: " << program_name << " [Options]" << endl << endl; cout << "Each spec can be a file whose extension decides the format." << endl; cout << "Optionally the format can be specified by preceding the file by" << endl; @@ -377,7 +474,7 @@ void help() while(OBConversion::GetNextFormat(pos,str,pFormat)) { if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) - continue; + continue; cout << " " << str << endl; } cout << "\nSee further specific info and options using -H, e.g. -Hpdb" << endl;