File: obdoc.cpp

package info (click to toggle)
openbabel 2.3.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,356 kB
  • ctags: 41,971
  • sloc: cpp: 321,256; ansic: 89,228; python: 7,262; perl: 6,418; pascal: 793; sh: 194; xml: 97; ruby: 55; makefile: 48; java: 23
file content (163 lines) | stat: -rw-r--r-- 4,562 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**********************************************************************
obdoc - Automatically generate documentation database for file formats

Copyright (C) 2005 by Geoffrey R. Hutchison
 
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
***********************************************************************/


// used to set import/export for Cygwin DLLs
#ifdef WIN32
#define USING_OBDLL
#endif

#include <openbabel/babelconfig.h>
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>

using namespace std;
using namespace OpenBabel;

int main(int argc,char **argv)
{
  char *program_name= argv[0];

  vector< vector<string> > extensionList; // some formats have multiple codes
  vector< OBFormat *> formatList;

  OBConversion conv;
  Formatpos pos;
  OBFormat* pFormat;
  const char* str=NULL;
  bool newFormat;

  while(OBConversion::GetNextFormat(pos,str,pFormat))
    {
      if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE))
        continue;

      if (formatList.size() == 0)
        {
          formatList.push_back(pFormat);
          vector<string> formatExtensions;
          formatExtensions.push_back(pos->first);
          extensionList.push_back(formatExtensions);
        }
      else
        {
          newFormat = true; // until we find otherwise
          for(unsigned int i = 0; i < formatList.size(); ++i)
            if (formatList[i] == pFormat)
              {
                newFormat = false;
                extensionList[i].push_back(pos->first);
                break;
              }
	    
          if (newFormat)
            {
              formatList.push_back(pFormat);
              vector<string> formatExtensions;
              formatExtensions.push_back(pos->first);
              extensionList.push_back(formatExtensions);
            }
        }

    }

  string notes, description, name, code;
  ofstream ofs, indexExt, indexName;

  indexExt.open("code-index.html");

  for(unsigned int i = 0; i < formatList.size(); ++i)
    {
      pFormat = formatList[i];
      description = pFormat->Description();
      name = description.substr(0,description.find('\n'));
      code = extensionList[i][0] + "-data.html";

      ofs.open(code.c_str());

      ofs << "{{Format|" << endl;
      ofs << "|extensions=";

      for (unsigned int j = 0; j < extensionList[i].size(); ++j)
        {
          ofs << extensionList[i][j];

          indexExt << "* " << extensionList[i][j]	 
                   << " - [[" << name << "]]"	 
                   << endl;
 
          if (j != extensionList[i].size() - 1)
            ofs << ", ";
        }
      ofs << endl;

      ofs << "|mime=";
      if (pFormat->GetMIMEType() && strlen(pFormat->GetMIMEType()) != 0)
        ofs << pFormat->GetMIMEType() << endl;
      else
        ofs << endl;
	
      ofs << "|url=";
      if (pFormat->SpecificationURL() && 
          strlen(pFormat->SpecificationURL()) != 0)
        {
          ofs << pFormat->SpecificationURL() << endl;
        }
      else
        ofs << "Unknown" << endl;

      ofs << "|import=";
      if (pFormat->Flags() & NOTREADABLE)
        ofs << "No";
      else
        ofs << "Yes";
      if (pFormat->Flags() & READONEONLY)
        ofs << ", One record per input file";
      if (pFormat->Flags() & READBINARY)
        ofs << ", Input is a binary file";
      ofs << endl;

      ofs << "|export=";
      if (pFormat->Flags() & NOTWRITABLE)
        ofs << "No";
      else
        ofs << "Yes";
      if (pFormat->Flags() & WRITEONEONLY)
        ofs << ", One record per output file";
      if (pFormat->Flags() & WRITEBINARY)
        ofs << ", Output is a binary file";
      ofs << endl;

      ofs << "|version=2.2 and later" << endl; // added in 2.1
      ofs << "|dimensionality=3D" << endl;
      ofs << "|options =\n<pre>";
      ofs << 	description.substr(description.find('\n'), description.size()); 
      ofs << "</pre>" << endl;
      ofs << "}}" << endl << endl;

      ofs << "[[Category:Formats]]" << endl;

      ofs.close();
    }

  indexExt.close();

  return(0);
} // end main