HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CMD_Source.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: CMD library (C++)
7  *
8  * COMMENTS: A source for commands
9  *
10  */
11 
12 #ifndef __CMD_Source_h__
13 #define __CMD_Source_h__
14 
15 #include "CMD_API.h"
16 #include <UT/UT_ValArray.h>
17 #include <UT/UT_StringArray.h>
18 
19 #define CMD_MAX_IF_NESTS 128
20 
21 class UT_WorkBuffer;
22 class FS_Reader;
23 class CMD_VariableTable;
24 class CMD_HistoryTable;
25 class CMD_Manager;
26 class CMD_Loop;
27 
29  CMD_IF_NOTVALID = 0, // Not in an if statement
30  CMD_IF_NOTDONE, // Haven't found a true branch yet
31  CMD_IF_DONE, // We've completed the true branch
32  CMD_IF_BYPASS, // Nested if inside a false branch
33  CMD_IF_DOING // Doing the true branch
34 };
35 
37 public:
38  CMD_Source(const char *filename, int interactive = 0);
39  ~CMD_Source();
40 
41  void addHistory(const char *cmd);
42  CMD_VariableTable *getLocalVariables() { return myVariables; }
43 
44  const char *getFilename() { return myFilename; }
45 
46  CMD_HistoryTable *getHistory() { return myHistory; }
47 
48  CMD_IfState getIfState() { return myIfState[myIfNestLevel]; }
49  void setIfState(CMD_IfState state)
50  {
51  myIfState[myIfNestLevel] = state;
52  }
53  int bumpIfNest(int dir);
54  const char *getLine(UT_WorkBuffer &buf);
55  int getLineNumber() const;
56  int getIfNestLevel() const { return myIfNestLevel;}
57  void setIfNestLevel(int l) { myIfNestLevel = l; }
58  void setEchoState(int onoff) { myEchoState = onoff; }
59  int getEchoState() const { return myEchoState; }
60 
61  // Returns true if this source is stdin
62  bool isStdIn() const;
63 
65  {
66  return getIfState() == CMD_IF_NOTVALID ||
67  getIfState() == CMD_IF_DOING;
68  }
69 
70  UT_IStream *getInputStream() { return myInput; }
71  bool isInteractive() const
72  { return myIsInteractive; }
73  void setIsInteractive(bool is_interactive)
74  { myIsInteractive = is_interactive; }
75 
76  void pushUnfinishedCommands(const char *);
77  bool hasUnfinishedCommands();
78  void startBlock();
79  void endBlock();
80 
81 private:
82  void initCommon(const char *filename);
83  void setInput(char *buffer, int64 buflen);
84 
85  CMD_VariableTable *myVariables;
86  CMD_HistoryTable *myHistory;
87  char *myFilename;
88  CMD_Loop *myCurrentLoop;
89  UT_IStream *myInput;
90  char *myBuffer;
91  int myLoopStatus;
92  int myIsInteractive;
93  int myLineNum;
94  int myEchoState;
95  CMD_IfState myIfState[CMD_MAX_IF_NESTS];
96  int myIfNestLevel;
97  UT_IntArray myUnfinishedCommandsWaterlines;
98  UT_StringArray myUnfinishedCommands;
99 
100  friend class CMD_Manager;
101 };
102 
103 #endif
UT_IStream * getInputStream()
Definition: CMD_Source.h:70
Class for reading files.
Definition: FS_Reader.h:30
int getEchoState() const
Definition: CMD_Source.h:59
CMD_HistoryTable * getHistory()
Definition: CMD_Source.h:46
const char * getFilename()
Definition: CMD_Source.h:44
int getIfNestLevel() const
Definition: CMD_Source.h:56
GLuint buffer
Definition: glcorearb.h:659
CMD_IfState getIfState()
Definition: CMD_Source.h:48
long long int64
Definition: SYS_Types.h:100
#define CMD_MAX_IF_NESTS
Definition: CMD_Source.h:19
void setIfNestLevel(int l)
Definition: CMD_Source.h:57
void setEchoState(int onoff)
Definition: CMD_Source.h:58
int doIfStatements()
Definition: CMD_Source.h:64
bool isInteractive() const
Definition: CMD_Source.h:71
void setIfState(CMD_IfState state)
Definition: CMD_Source.h:49
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
#define CMD_API
Definition: CMD_API.h:10
CMD_IfState
Definition: CMD_Source.h:28
CMD_VariableTable * getLocalVariables()
Definition: CMD_Source.h:42
void setIsInteractive(bool is_interactive)
Definition: CMD_Source.h:73