| 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 <cstring> |
| 38 | #include <unistd.h> |
| 39 | #include <cstdlib> |
| 40 | |
| 41 | #include <Inventor/SoDB.h>cxx . . $ `<file>/lib/database/include/Inventor/SoDB.h`/ |
| 42 | #include <Inventor/SoInput.h>cxx . . $ `<file>/lib/database/include/Inventor/SoInput.h`/ |
| 43 | #include <Inventor/SoInteraction.h>cxx . . $ `<file>/lib/interaction/include/Inventor/SoInteraction.h`/ |
| 44 | #include <Inventor/actions/SoWriteAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoWriteAction.h`/ |
| 45 | #include <Inventor/nodes/SoSeparator.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoSeparator.h`/ |
| 46 | |
| 47 | #include "IfFixer.h"cxx . . $ `<file>/apps/tools/ivfix/IfFixer.h`/ |
| 48 | #include "IfReporter.h"cxx . . $ `<file>/apps/tools/ivfix/IfReporter.h`/ |
| 49 | |
| 50 | ///////////////////////////////////////////////////////////////////////////// |
| 51 | // |
| 52 | // This structure is used to store and pass around command-line options. |
| 53 | // |
| 54 | ///////////////////////////////////////////////////////////////////////////// |
| 55 | |
| 56 | typedef structcxx . . $ $anonymous_type_ad341586ff74012a_0# { |
| 57 | IfFixercxx . . $ IfFixer#::ReportLevelcxx . . $ IfFixer#ReportLevel# reportLevelcxx . . $ $anonymous_type_ad341586ff74012a_0#reportLevel.; |
| 58 | SbBoolcxx . . $ SbBool# writeAsciicxx . . $ $anonymous_type_ad341586ff74012a_0#writeAscii.; |
| 59 | SbBoolcxx . . $ SbBool# doAnyNormalscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyNormals.; |
| 60 | SbBoolcxx . . $ SbBool# doAnyTexCoordscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyTexCoords.; |
| 61 | SbBoolcxx . . $ SbBool# writeStripscxx . . $ $anonymous_type_ad341586ff74012a_0#writeStrips.; |
| 62 | SbBoolcxx . . $ SbBool# writeVertexPropertycxx . . $ $anonymous_type_ad341586ff74012a_0#writeVertexProperty.; |
| 63 | SoInputcxx . . $ SoInput# inFilecxx . . $ $anonymous_type_ad341586ff74012a_0#inFile.; |
| 64 | SoOutputcxx . . $ SoOutput# outFilecxx . . $ $anonymous_type_ad341586ff74012a_0#outFile.; |
| 65 | } OptionInfocxx . . $ OptionInfo#; |
| 66 | |
| 67 | ///////////////////////////////////////////////////////////////////////////// |
| 68 | // |
| 69 | // Forward references. |
| 70 | // |
| 71 | ///////////////////////////////////////////////////////////////////////////// |
| 72 | |
| 73 | static void printUsagecxx . . $ printUsage(85c52e162fed56f9).(const char *progname); |
| 74 | static void parseArgscxx . . $ parseArgs(20c729cfbf0569d8).(int argc, char **argv, OptionInfocxx . . $ OptionInfo# &options); |
| 75 | static void initOptionscxx . . $ initOptions(a0b28d9fa568e781).(OptionInfocxx . . $ OptionInfo# &options); |
| 76 | |
| 77 | ///////////////////////////////////////////////////////////////////////////// |
| 78 | // |
| 79 | // Mainline. |
| 80 | // |
| 81 | ///////////////////////////////////////////////////////////////////////////// |
| 82 | |
| 83 | int |
| 84 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 85 | { |
| 86 | OptionInfocxx . . $ OptionInfo# options; |
| 87 | |
| 88 | initOptionscxx . . $ initOptions(a0b28d9fa568e781).(options); |
| 89 | |
| 90 | SoInteractioncxx . . $ SoInteraction#::initcxx . . $ SoInteraction#init(49f6e7a06ebc5aa8).(); |
| 91 | |
| 92 | // Parse arguments |
| 93 | parseArgscxx . . $ parseArgs(20c729cfbf0569d8).(argc, argv, options); |
| 94 | |
| 95 | IfFixercxx . . $ IfFixer# fixercxx . . $ IfFixer#IfFixer(49f6e7a06ebc5aa8).; |
| 96 | fixer.setReportLevelcxx . . $ IfFixer#setReportLevel(b960238e92d56e6).(options.reportLevelcxx . . $ $anonymous_type_ad341586ff74012a_0#reportLevel., stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); |
| 97 | fixer.setStripFlagcxx . . $ IfFixer#setStripFlag(d4f767463ce0a6b3).(options.writeStripscxx . . $ $anonymous_type_ad341586ff74012a_0#writeStrips.); |
| 98 | fixer.setNormalFlagcxx . . $ IfFixer#setNormalFlag(d4f767463ce0a6b3).(options.doAnyNormalscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyNormals.); |
| 99 | fixer.setTextureCoordFlagcxx . . $ IfFixer#setTextureCoordFlag(d4f767463ce0a6b3).(options.doAnyTexCoordscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyTexCoords.); |
| 100 | fixer.setVertexPropertyFlagcxx . . $ IfFixer#setVertexPropertyFlag(d4f767463ce0a6b3).(options.writeVertexPropertycxx . . $ $anonymous_type_ad341586ff74012a_0#writeVertexProperty.); |
| 101 | |
| 102 | // Read stuff: |
| 103 | IfReportercxx . . $ IfReporter#::startReportcxx . . $ IfReporter#startReport(34d26762b42c433a).("Reading file"); |
| 104 | SoSeparatorcxx . . $ SoSeparator# *root = SoDBcxx . . $ SoDB#::readAllcxx . . $ SoDB#readAll(e6adbfcd7bb1cb98).(&options.inFilecxx . . $ $anonymous_type_ad341586ff74012a_0#inFile.); |
| 105 | if (root == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 106 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n%s: Problem reading data from file\n", argv[0]); |
| 107 | printUsagecxx . . $ printUsage(85c52e162fed56f9).(argv[0]); |
| 108 | } |
| 109 | IfReportercxx . . $ IfReporter#::finishReportcxx . . $ IfReporter#finishReport(d4f767463ce0a6b3).(); |
| 110 | |
| 111 | // We don't need to ref the root since we want the IfFixer to get |
| 112 | // rid of the scene graph when it's done with it |
| 113 | SoNodecxx . . $ SoNode# *resultRoot = fixer.fixcxx . . $ IfFixer#fix(4a10d168dc65ab48).(root); |
| 114 | if (resultRoot == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 115 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: No shapes found in data\n", argv[0]); |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | resultRoot->refcxx . . $ SoBase#ref(83f5f38750778ac8).(); |
| 120 | |
| 121 | // Write out the results |
| 122 | IfReportercxx . . $ IfReporter#::startReportcxx . . $ IfReporter#startReport(34d26762b42c433a).("Writing result"); |
| 123 | SoWriteActioncxx . . $ SoWriteAction# wacxx . . $ SoWriteAction#SoWriteAction(46d85c4d426f339d).(&options.outFilecxx . . $ $anonymous_type_ad341586ff74012a_0#outFile.); |
| 124 | if (! options.writeAsciicxx . . $ $anonymous_type_ad341586ff74012a_0#writeAscii.) |
| 125 | wa.getOutputcxx . . $ SoWriteAction#getOutput(daf9692406936d14).()->setBinarycxx . . $ SoOutput#setBinary(d4f767463ce0a6b3).(TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!); |
| 126 | wa.applycxx . . $ SoAction#apply(da6c7544ccee32bd).(resultRoot); |
| 127 | IfReportercxx . . $ IfReporter#::finishReportcxx . . $ IfReporter#finishReport(d4f767463ce0a6b3).(); |
| 128 | |
| 129 | // Clean up |
| 130 | resultRoot->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).(); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | ///////////////////////////////////////////////////////////////////////////// |
| 136 | // |
| 137 | // Prints usage message and exits. |
| 138 | // |
| 139 | ///////////////////////////////////////////////////////////////////////////// |
| 140 | |
| 141 | static void |
| 142 | printUsagecxx . . $ printUsage(85c52e162fed56f9).(const char *progname) |
| 143 | { |
| 144 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Usage: %s [options] [infile] [outfile]\n", progname); |
| 145 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 146 | "\t-a : Write out an ascii file. Default is binary\n" |
| 147 | "\t-d dir : Add 'dir' to the list of directories to search\n" |
| 148 | "\t-f : Produce independent faces rather than tri strips\n" |
| 149 | "\t-h : Print this message (help)\n" |
| 150 | "\t-n : Do not generate any normals\n" |
| 151 | "\t-p : Do not produce SoVertexProperty nodes for properties\n" |
| 152 | "\t-t : Do not generate any texture coordinates\n" |
| 153 | "\t-v : (Verbose) Display status info during processing\n" |
| 154 | "\t-V : (Very verbose) Display more detailed status info\n" |
| 155 | ); |
| 156 | |
| 157 | exit(99); |
| 158 | } |
| 159 | |
| 160 | ///////////////////////////////////////////////////////////////////////////// |
| 161 | // |
| 162 | // Parses input options, filling in OptionInfo structure. |
| 163 | // |
| 164 | ///////////////////////////////////////////////////////////////////////////// |
| 165 | |
| 166 | static void |
| 167 | parseArgscxx . . $ parseArgs(20c729cfbf0569d8).(int argc, char **argv, OptionInfocxx . . $ OptionInfo# &options) |
| 168 | { |
| 169 | SbBoolcxx . . $ SbBool# uhoh = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 170 | int c; |
| 171 | |
| 172 | while ((c = getopt(argc, argv, "ad:fhnptvV")) != -1) { |
| 173 | switch(c) { |
| 174 | case 'a': |
| 175 | options.writeAsciicxx . . $ $anonymous_type_ad341586ff74012a_0#writeAscii. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 176 | break; |
| 177 | case 'd': |
| 178 | options.inFilecxx . . $ $anonymous_type_ad341586ff74012a_0#inFile..addDirectoryLastcxx . . $ SoInput#addDirectoryLast(85c52e162fed56f9).(optarg); |
| 179 | break; |
| 180 | case 'f': |
| 181 | options.writeStripscxx . . $ $anonymous_type_ad341586ff74012a_0#writeStrips. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 182 | break; |
| 183 | case 'n': |
| 184 | options.doAnyNormalscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyNormals. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 185 | break; |
| 186 | case 'p': |
| 187 | options.writeVertexPropertycxx . . $ $anonymous_type_ad341586ff74012a_0#writeVertexProperty. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 188 | break; |
| 189 | case 't': |
| 190 | options.doAnyTexCoordscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyTexCoords. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 191 | break; |
| 192 | case 'v': |
| 193 | options.reportLevelcxx . . $ $anonymous_type_ad341586ff74012a_0#reportLevel. = IfFixercxx . . $ IfFixer#::LOWcxx . . $ IfFixer#LOW.; |
| 194 | break; |
| 195 | case 'V': |
| 196 | options.reportLevelcxx . . $ $anonymous_type_ad341586ff74012a_0#reportLevel. = IfFixercxx . . $ IfFixer#::HIGHcxx . . $ IfFixer#HIGH.; |
| 197 | break; |
| 198 | case 'h': // Help |
| 199 | default: |
| 200 | uhoh = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Handle optional input file name |
| 206 | if (optind < argc) { |
| 207 | char *inFileName = argv[optind++]; |
| 208 | if (! options.inFilecxx . . $ $anonymous_type_ad341586ff74012a_0#inFile..openFilecxx . . $ SoInput#openFile(cb7559238bb26814).(inFileName)) { |
| 209 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Could not open file %s", argv[0], inFileName); |
| 210 | printUsagecxx . . $ printUsage(85c52e162fed56f9).(argv[0]); |
| 211 | } |
| 212 | |
| 213 | // If the filename includes a directory path, add the directory name |
| 214 | // to the list of directories where to look for input files |
| 215 | const char *slashPtr; |
| 216 | char *searchPath = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 217 | if ((slashPtr = strrchr(inFileName, '/')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 218 | searchPath = strdup(inFileName); |
| 219 | searchPath[slashPtr - inFileName] = '\0'; |
| 220 | SoInputcxx . . $ SoInput#::addDirectoryFirstcxx . . $ SoInput#addDirectoryFirst(85c52e162fed56f9).(searchPath); |
| 221 | free(searchPath); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | // Trying to read stdin from a tty is a no-no |
| 226 | else if (isatty(fileno(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!))) |
| 227 | uhoh = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 228 | |
| 229 | // Handle optional output file name |
| 230 | if (optind < argc) { |
| 231 | char *outFileName = argv[optind++]; |
| 232 | if (! options.outFilecxx . . $ $anonymous_type_ad341586ff74012a_0#outFile..openFilecxx . . $ SoOutput#openFile(5c4306d8553b3696).(outFileName)) { |
| 233 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Could not open file %s", argv[0],outFileName); |
| 234 | printUsagecxx . . $ printUsage(85c52e162fed56f9).(argv[0]); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // Too many arguments? |
| 239 | if (optind < argc) |
| 240 | uhoh = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 241 | |
| 242 | if (uhoh) |
| 243 | printUsagecxx . . $ printUsage(85c52e162fed56f9).(argv[0]); |
| 244 | } |
| 245 | |
| 246 | ///////////////////////////////////////////////////////////////////////////// |
| 247 | // |
| 248 | // Initializes an OptionInfo structure. |
| 249 | // |
| 250 | ///////////////////////////////////////////////////////////////////////////// |
| 251 | |
| 252 | static void |
| 253 | initOptionscxx . . $ initOptions(a0b28d9fa568e781).(OptionInfocxx . . $ OptionInfo# &options) |
| 254 | { |
| 255 | options.reportLevelcxx . . $ $anonymous_type_ad341586ff74012a_0#reportLevel. = IfFixercxx . . $ IfFixer#::NONEcxx . . $ IfFixer#NONE.; |
| 256 | options.writeAsciicxx . . $ $anonymous_type_ad341586ff74012a_0#writeAscii. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 257 | options.doAnyNormalscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyNormals. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 258 | options.doAnyTexCoordscxx . . $ $anonymous_type_ad341586ff74012a_0#doAnyTexCoords. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 259 | options.writeStripscxx . . $ $anonymous_type_ad341586ff74012a_0#writeStrips. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 260 | options.writeVertexPropertycxx . . $ $anonymous_type_ad341586ff74012a_0#writeVertexProperty. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 261 | } |