00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: CMD library (C++) 00015 * 00016 * COMMENTS: A source for commands 00017 * 00018 */ 00019 00020 #ifndef __CMD_Source_h__ 00021 #define __CMD_Source_h__ 00022 00023 #include "CMD_API.h" 00024 #include <iostream.h> 00025 #include <UT/UT_PtrArray.h> 00026 #include <UT/UT_StringArray.h> 00027 00028 #define CMD_MAX_IF_NESTS 128 00029 00030 class UT_WorkBuffer; 00031 class FS_Reader; 00032 class CMD_VariableTable; 00033 class CMD_HistoryTable; 00034 class CMD_Manager; 00035 class CMD_Loop; 00036 00037 enum CMD_IfState { 00038 CMD_IF_NOTVALID = 0, // Not in an if statement 00039 CMD_IF_NOTDONE, // Haven't found a true branch yet 00040 CMD_IF_DONE, // We've completed the true branch 00041 CMD_IF_BYPASS, // Nested if inside a false branch 00042 CMD_IF_DOING // Doing the true branch 00043 }; 00044 00045 class CMD_API CMD_Source { 00046 public: 00047 CMD_Source(const char *filename, int interactive = 0); 00048 ~CMD_Source(); 00049 00050 void addHistory(const char *cmd); 00051 CMD_VariableTable *getLocalVariables() { return myVariables; } 00052 00053 const char *getFilename() { return myFilename; } 00054 00055 CMD_HistoryTable *getHistory() { return myHistory; } 00056 00057 CMD_IfState getIfState() { return myIfState[myIfNestLevel]; } 00058 void setIfState(CMD_IfState state) 00059 { 00060 myIfState[myIfNestLevel] = state; 00061 } 00062 int bumpIfNest(int dir); 00063 const char *getLine(UT_WorkBuffer &buf); 00064 int getLineNumber() const; 00065 int getIfNestLevel() const { return myIfNestLevel;} 00066 void setIfNestLevel(int l) { myIfNestLevel = l; } 00067 void setEchoState(int onoff) { myEchoState = onoff; } 00068 int getEchoState() const { return myEchoState; } 00069 00070 // Returns true if this source is stdin 00071 bool isStdIn() const; 00072 00073 int doIfStatements() 00074 { 00075 return getIfState() == CMD_IF_NOTVALID || 00076 getIfState() == CMD_IF_DOING; 00077 } 00078 UT_IStream *getInputStream() { return myInput; } 00079 void pushUnfinishedCommands(const char *); 00080 bool hasUnfinishedCommands(); 00081 void startBlock(); 00082 void endBlock(); 00083 00084 private: 00085 void initCommon(const char *filename); 00086 void setInput(char *buffer, int buflen); 00087 00088 CMD_VariableTable *myVariables; 00089 CMD_HistoryTable *myHistory; 00090 char *myFilename; 00091 CMD_Loop *myCurrentLoop; 00092 UT_IStream *myInput; 00093 char *myBuffer; 00094 int myLoopStatus; 00095 int myIsInteractive; 00096 int myLineNum; 00097 int myEchoState; 00098 CMD_IfState myIfState[CMD_MAX_IF_NESTS]; 00099 int myIfNestLevel; 00100 UT_StringArray myUnfinishedCommands; 00101 00102 friend class CMD_Manager; 00103 }; 00104 00105 #endif
1.5.9