HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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_NonCopyable.h>
17 #include <UT/UT_StringArray.h>
18 #include <UT/UT_ValArray.h>
19 
20 #define CMD_MAX_IF_NESTS 128
21 
22 class UT_WorkBuffer;
23 class FS_Reader;
24 class CMD_VariableTable;
25 class CMD_HistoryTable;
26 class CMD_Manager;
27 class CMD_Loop;
28 
30 {
31  CMD_IF_NOTVALID = 0, // Not in an if statement
32  CMD_IF_NOTDONE, // Haven't found a true branch yet
33  CMD_IF_DONE, // We've completed the true branch
34  CMD_IF_BYPASS, // Nested if inside a false branch
35  CMD_IF_DOING // Doing the true branch
36 };
37 
39 {
40 public:
41  CMD_Source(const char *filename, int interactive = 0);
42  ~CMD_Source();
43 
45 
46  void addHistory(const char *cmd);
47  CMD_VariableTable *getLocalVariables() { return myVariables; }
48 
49  const char *getFilename() { return myFilename; }
50 
51  CMD_HistoryTable *getHistory() { return myHistory; }
52 
53  CMD_IfState getIfState() { return myIfState[myIfNestLevel]; }
54  void setIfState(CMD_IfState state)
55  {
56  myIfState[myIfNestLevel] = state;
57  }
58  int bumpIfNest(int dir);
59  const char *getLine(UT_WorkBuffer &buf);
60  int getLineNumber() const;
61  int getIfNestLevel() const { return myIfNestLevel;}
62  void setIfNestLevel(int l) { myIfNestLevel = l; }
63  void setEchoState(int onoff) { myEchoState = onoff; }
64  int getEchoState() const { return myEchoState; }
65 
66  // Returns true if this source is stdin
67  bool isStdIn() const;
68 
70  {
71  return getIfState() == CMD_IF_NOTVALID ||
72  getIfState() == CMD_IF_DOING;
73  }
74 
75  UT_IStream *getInputStream() { return myInput; }
76  bool isInteractive() const
77  { return myIsInteractive; }
78  void setIsInteractive(bool is_interactive)
79  { myIsInteractive = is_interactive; }
80 
81  void pushUnfinishedCommands(const char *);
82  bool hasUnfinishedCommands();
83  void startBlock();
84  void endBlock();
85 
86 private:
87  void initCommon(const char *filename);
88  void setInput(char *buffer, int64 buflen);
89 
90  CMD_VariableTable *myVariables;
91  CMD_HistoryTable *myHistory;
92  char *myFilename;
93  CMD_Loop *myCurrentLoop;
94  UT_IStream *myInput;
95  char *myBuffer;
96  int myLoopStatus;
97  int myIsInteractive;
98  int myLineNum;
99  int myEchoState;
100  CMD_IfState myIfState[CMD_MAX_IF_NESTS];
101  int myIfNestLevel;
102  UT_IntArray myUnfinishedCommandsWaterlines;
103  UT_StringArray myUnfinishedCommands;
104 
105  friend class CMD_Manager;
106 };
107 
108 #endif
UT_IStream * getInputStream()
Definition: CMD_Source.h:75
Class for reading files.
Definition: FS_Reader.h:33
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
GT_API const UT_StringHolder filename
int getEchoState() const
Definition: CMD_Source.h:64
CMD_HistoryTable * getHistory()
Definition: CMD_Source.h:51
const char * getFilename()
Definition: CMD_Source.h:49
int getIfNestLevel() const
Definition: CMD_Source.h:61
CMD_IfState getIfState()
Definition: CMD_Source.h:53
#define CMD_MAX_IF_NESTS
Definition: CMD_Source.h:20
Definition: core.h:760
void setIfNestLevel(int l)
Definition: CMD_Source.h:62
void setEchoState(int onoff)
Definition: CMD_Source.h:63
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
int doIfStatements()
Definition: CMD_Source.h:69
long long int64
Definition: SYS_Types.h:116
bool isInteractive() const
Definition: CMD_Source.h:76
void setIfState(CMD_IfState state)
Definition: CMD_Source.h:54
#define CMD_API
Definition: CMD_API.h:10
CMD_IfState
Definition: CMD_Source.h:29
CMD_VariableTable * getLocalVariables()
Definition: CMD_Source.h:47
void setIsInteractive(bool is_interactive)
Definition: CMD_Source.h:78