| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
#include <cstdlib> |
| 38 |
#include <unistd.h> |
| 39 |
#include <Inventor/SoDB.h> |
| 40 |
#include <Inventor/SoInteraction.h> |
| 41 |
#include <Inventor/nodekits/SoNodeKit.h> |
| 42 |
#include "Man.h" |
| 43 |
|
| 44 |
///////////////////////////////////////////////////////////////////////////// |
| 45 |
// |
| 46 |
// Prints usage message. |
| 47 |
// |
| 48 |
///////////////////////////////////////////////////////////////////////////// |
| 49 |
|
| 50 |
static void |
| 51 |
printUsage(const char *progname) |
| 52 |
{ |
| 53 |
fprintf(stderr, |
| 54 |
"Usage: %s [-bc] dir1/class1 dir2/class2 ...\n" |
| 55 |
" where class1 is the most derived class\n" |
| 56 |
" -b creates output for the reference manual book, as opposed\n" |
| 57 |
" to on-line man pages (the default)\n" |
| 58 |
" -c indicates C, as opposed to C++ (the default)\n", |
| 59 |
progname); |
| 60 |
|
| 61 |
exit(1); |
| 62 |
} |
| 63 |
|
| 64 |
///////////////////////////////////////////////////////////////////////////// |
| 65 |
// |
| 66 |
// Creates and returns 1 class definition structure. Returns NULL on |
| 67 |
// error. This is passed the main ClassDef (the one the man page is |
| 68 |
// for) to pass into the ClassDef::setUp method. If this ClassDef IS |
| 69 |
// the main one, this pointer is NULL. |
| 70 |
// |
| 71 |
///////////////////////////////////////////////////////////////////////////// |
| 72 |
|
| 73 |
static ClassDef * |
| 74 |
createClassDef(const char *pathName, const ClassDef *mainCd) |
| 75 |
{ |
| 76 |
ClassDef *cd = new ClassDef(); |
| 77 |
|
| 78 |
if (Reader::open(pathName) && cd->read() && cd->setUp(mainCd)) |
| 79 |
return cd; |
| 80 |
|
| 81 |
delete cd; |
| 82 |
|
| 83 |
return NULL; |
| 84 |
} |
| 85 |
|
| 86 |
///////////////////////////////////////////////////////////////////////////// |
| 87 |
// |
| 88 |
// Mainline |
| 89 |
// |
| 90 |
///////////////////////////////////////////////////////////////////////////// |
| 91 |
|
| 92 |
int main(int argc, char *argv[]) |
| 93 |
{ |
| 94 |
SbBool ok = TRUE; |
| 95 |
int c, curArg; |
| 96 |
|
| 97 |
Writer::setLanguage(C_PLUS_PLUS); |
| 98 |
|
| 99 |
while ((c = getopt(argc, argv, "bc")) != -1) { |
| 100 |
switch (c) { |
| 101 |
case 'b': |
| 102 |
Writer::setForBook(TRUE); |
| 103 |
break; |
| 104 |
case 'c': |
| 105 |
Writer::setLanguage(C); |
| 106 |
break; |
| 107 |
default: |
| 108 |
ok = FALSE; |
| 109 |
break; |
| 110 |
} |
| 111 |
} |
| 112 |
curArg = optind; |
| 113 |
|
| 114 |
// Check for at least 1 class at end |
| 115 |
if (! ok || curArg >= argc) |
| 116 |
printUsage(argv[0]); |
| 117 |
|
| 118 |
SoDB::init(); |
| 119 |
SoNodeKit::init(); |
| 120 |
SoInteraction::init(); |
| 121 |
|
| 122 |
// Process each class in turn |
| 123 |
ClassDef *mainCd = NULL, *curCd = NULL, *cd; |
| 124 |
while (curArg < argc) { |
| 125 |
|
| 126 |
cd = createClassDef(argv[curArg++], mainCd); |
| 127 |
|
| 128 |
if (cd == NULL) { |
| 129 |
ok = FALSE; |
| 130 |
break; |
| 131 |
} |
| 132 |
|
| 133 |
if (mainCd == NULL) |
| 134 |
mainCd = cd; |
| 135 |
mainCd->addInherit(cd); |
| 136 |
|
| 137 |
if (curCd != NULL) |
| 138 |
curCd->setParent(cd); |
| 139 |
|
| 140 |
curCd = cd; |
| 141 |
} |
| 142 |
|
| 143 |
// Remove any inherited methods that have the same name or are |
| 144 |
// constructors |
| 145 |
mainCd->cullMethods(); |
| 146 |
|
| 147 |
if (ok) { |
| 148 |
Writer::setPointer(stdout); |
| 149 |
|
| 150 |
// give the writer the name of the original source file |
| 151 |
// in case we have error messages to print (to let the user |
| 152 |
// know which file we barfed on). (alain) |
| 153 |
if (Writer::getLanguage() == C_PLUS_PLUS) |
| 154 |
Writer::setSourceFileName(argv[1]); |
| 155 |
else |
| 156 |
Writer::setSourceFileName(argv[2]); |
| 157 |
|
| 158 |
mainCd->write(FALSE); |
| 159 |
} |
| 160 |
|
| 161 |
return ! ok; |
| 162 |
} |