HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
standalone.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * Sample stand alone application.
27  */
28 
29 #include <getopt.h>
30 #include <stdlib.h>
31 #include <PI/PI_ResourceManager.h>
32 #include <MOT/MOT_Director.h>
33 #include <UT/UT_StringStream.h>
34 #include <iostream>
35 
36 #define LINE_SIZE 1024
37 
38 static void
39 usage(const char *program)
40 {
41  std::cerr << "Usage: " << program << " [-h]\n";
42  std::cerr << "Stand alone houdini application\n";
43  exit(1);
44 }
45 
46 int
47 main(int argc, char *argv[])
48 {
49  int opt, i;
50  MOT_Director *boss;
51  CMD_Manager *cmd;
52 
53  // Do argument parsing
54  while ((opt = getopt(argc, argv, "h")) != -1)
55  {
56  switch (opt)
57  {
58  case 'h':
59  default: usage(argv[0]);
60  }
61  }
62 
63  // Initialize the whole heirarchy of operators
64  boss = new MOT_Director("standalone");
65  OPsetDirector(boss);
67 
68  cmd = boss->getCommandManager();
69  if (argc == optind)
70  {
71  // If we have no arguments, source 123.cmd
72  cmd->sendInput("source -q 123.cmd");
73  }
74  else
75  {
76  for (i = optind; i < argc; i++)
77  {
78  // Merge in using the mread command.
80  ts << "mread -m * " << argv[i] << std::ends;
81  cmd->sendInput(ts.str().buffer());
82  }
83  }
84 
85  // Now, enter the main loop
86  do {
87  char line[LINE_SIZE];
88  cmd->doPrompt();
89  if (!std::cin.getline(line, LINE_SIZE))
90  break;
91  cmd->sendInput(line);
92  } while (std::cin);
93 
94  return 0;
95 }
OP_API OP_Director * OPsetDirector(OP_Director *boss)
PI_API void PIcreateResourceManager(bool verbose=true)
SYS_FORCE_INLINE const char * buffer() const
An output stream object that owns its own string buffer storage.
const UT_WorkBuffer & str() const
Returns a read-only reference to the underlying UT_WorkBuffer.
void doPrompt()
png_uint_32 i
Definition: png.h:2877
#define LINE_SIZE
Definition: standalone.C:36
GLsizeiptr const void GLenum usage
Definition: glcorearb.h:663
int main(int argc, char *argv[])
Definition: standalone.C:47
OP_CommandManager * getCommandManager()
Definition: OP_Director.h:98
void sendInput(const char *input, bool create_block=true)
GLbitfield GLuint program
Definition: glcorearb.h:1930