script3.h
来自「GNU ccScript is a C++ class framework fo」· C头文件 代码 · 共 1,769 行 · 第 1/3 页
H
1,769 行
* only if it has not been included already. * * @return named script object. * @param name of script file to compile. */ Name *include(const char *name); /** * The script compiler itself. This linearly compiles a Bayonne * script file that is specified. Normally used along with a dir * scanner in the constructor. * * @return lines of script compiled. * @param file name of script file to compile. */ int compile(const char *file); /** * Compile a script from disk and give it a different internal * "name" as passed. * * @return lines of script compiled. * @param file name of script file to compile. * @param name of script to compile under. */ int compile(const char *file, char *name); /** * Compile a defintions library, commonly used for remapping * tokens to macros. * * @return lines of script compiled. * @param file name of defintions file to compile. */ int compileDefinitions(const char *file); /** * Compile an open stream object into a script. * * @return lines of script compiled. * @param stream object to use. * @param name of script save under. * @param file name to use in object. */ int compile(std::istream *stream, char *name, const char *file = NULL); /** * Used in the derived constructor to "commit" the current image * for new processes. This is usually the last statement in the * derived constructor. */ void commit(void); /** * Used to process '$const' inserts. * * @return string if found. * @param token string being substituted. */ virtual const char *getDefined(const char *token); /** * Check for special preprocessor token. * * @return error message or NULL if no error. * @param token name of keyword to check. */ const char *preproc(const char *token); /** * Used by embedded interpreters to fetch script from the current * source file. * * @return reference to source file stream. */ inline std::istream *getSource(void) {return (std::istream *)&scrSource;};};class __EXPORT ScriptInterp : public Mutex, public ScriptSymbols{protected: friend class __EXPORT ScriptThread; friend class __EXPORT ScriptCommand; friend class __EXPORT ScriptBinder;public: class __EXPORT Frame { public: Name *script; Line *line, *first; unsigned short index; ScriptSymbols *local; unsigned long mask; bool caseflag : 1; bool tranflag : 1; bool unused1 : 1; bool unused2 : 1; unsigned decimal : 4; unsigned base : 8; }; static long getRealValue(double val, unsigned prec); static double getDouble(long value, unsigned prec); static long getInteger(long value, unsigned prec); static long getTens(unsigned prec); long getIntValue(const char *text, unsigned prec, ScriptProperty *property = NULL); int numericExpression(long *list, int max, unsigned prec, ScriptProperty *property = NULL); bool conditionalExpression(void); bool conditional(void); protected: Mutex *lock; // any additional lock that is siezed ScriptCommand *cmd; ScriptImage *image; ScriptInterp *session; ScriptThread *thread; Frame frame[SCRIPT_STACK_SIZE]; char *temps[SCRIPT_TEMP_SPACE]; unsigned tempidx; unsigned stack; bool initialized, trace, exiting, updated; unsigned long sequence; char logname[32];public: virtual unsigned getId(void); inline unsigned long getSequence(void) {return sequence;}; virtual const char *getLogname(void) {return logname;}; virtual ScriptInterp *getInterp(const char *id); virtual const char *getExternal(const char *opt); inline ScriptImage *getImage(void) {return image;};protected: virtual ScriptSymbols *getSymbols(const char *id); ScriptSymbols *getLocal(void);public: const char *getMember(void); const char *getKeyword(const char *kw); const char *getKeyoption(const char *kw); const char *getValue(const char *def = NULL); const char *getOption(const char *def = NULL); const char *hasOption(void); const char *getContent(const char *opt); const char *getSymContent(const char *opt); Symbol *getKeysymbol(const char *kw, unsigned size = 0); Symbol *getSymbol(unsigned short size = 0); char getPackToken(void);protected: /** * Initialize execution environment for a script. */ void initRuntime(Name *name); /** * New virtual to initialize script environment syms * before running init sections. */ virtual void initialize(void);public: inline Frame *getFrame(void) {return &frame[stack];}; inline Line *getLine(void) {return frame[stack].line;}; void setFrame(void); inline Name *getName(void) {return frame[stack].script;}; inline bool getTrace(void) {return trace;}; /** * Runtime execution of script handler. This can be called in * the current or derived class to invoke extensible methods. * * @return true if immediately ready for next step. * @param method derived method member to call. */ bool execute(Method method);protected: /** * Attempt to push a value onto the stack. * * @return false if stack overflow. */ bool push(void); /** * Attempt to recall a previous stack level. * * @return false if stack underflow. */ bool pull(void); /** * Clear the stack of local loops or recursion for branching. */ void clearStack(void); /** * Advance program to the next script statement. */ void advance(void); /** * Skip line without checking or setting updates. */ void skip(void); /** * Set error variable and advance to either the error handler * or next script statement. * * @param error message. */ void error(const char *error); /** * Events reference to named \@event handlers which have been * attached to a script. This allows low level applications * to invoke an event handler much the way a signal handler * occurs. * * @return true if event handler exists. * @param name of event handler. * @param inhereted search flag. */ bool scriptEvent(const char *name, bool inhereted = true); /** * Branch to a selected event record immediately. * * @param event record pointer to access. */ void gotoEvent(NamedEvent *event); /** * Set the execution interpreter to a trap identifier. If no * trap id exists, then advance to next script statement (unless * exit trap). * * @param id of trap to select numerically. */ void trap(unsigned id); /** * Tries a catch handler... * * @return true if caught. * @param id of catch handler to try. */ bool tryCatch(const char *id); /** * Select trap by symbolic name and execute if found, else advance * to next script step (unless exit trap). * * @param name of trap to select. */ void trap(const char *name);public: virtual void logmissing(const char *id, const char *level = "undefined", const char *group = "symbol"); virtual void logerror(const char *msg, const char *name = NULL); Symbol *mapSymbol(const char *id, unsigned short = 0); Symbol *mapDirect(const char *id, unsigned short = 0);protected: virtual bool isLocked(const char *id); virtual const char *remapLocal(void); virtual bool exit(void); virtual void enterThread(ScriptThread *thread); virtual void exitThread(const char *msg); virtual void waitThread(void); virtual void startThread(void); bool eventThread(const char *evt, bool flag = true); bool redirect(const char *scr); void ripple(void); bool redirect(bool evflag); unsigned long getMask(void);public: bool setNumber(const char *id, const char *value = NULL, unsigned dec = 0); bool setSymbol(const char *id, const char *value = NULL, unsigned short size = 0); bool setConst(const char *id, const char *value); bool putSymbol(const char *id, const char *value, unsigned short size = 0); bool getSymbol(const char *id, char *buffer, unsigned short max); bool catSymbol(const char *id, const char *value, unsigned short size = 0); const char *getSymbol(const char *id); Name *getScript(const char *name); ScriptInterp(); bool step(void); bool attach(ScriptCommand *cmd, const char *scrname); void detach(void); void attach(ScriptCommand *cmd, ScriptImage *img, Name *scr); /** * Release any aquired lock... */ void release(void); /** * Signals are used during "delayed" execution steps when a * signal event has occured aynchronously with the execution * of a script controlled state event handler. This mechanism * can be used in place of calling implicit "Step" traps. * * @return true if signal handler is not blocked. * @param name of signal identifier. */ bool signal(const char *name); /** * Signals can be referenced by numeric id as well as by symbolic * name. * * @return true if signal handler is not blocked. * @param id number of handler. */ bool signal(unsigned id); bool done(void); timeout_t getTimeout(void); /** * A virtual holding a branch conditional member. This may be * invoked typically from goto or restart. Can be used to check * contextual changes. */ virtual void branching(void); inline bool isRunning(void) {return (image != NULL) && initialized;}; inline bool isExiting(void) {return exiting;}; char *getTemp(void); unsigned getTempSize(void);};class __EXPORT ScriptMethods : public ScriptInterp{public: bool scrNop(void); bool scrError(void); bool scrExit(void); bool scrDecimal(void); bool scrDefine(void); bool scrVar(void); bool scrType(void); bool scrNumber(void); bool scrSlog(void); bool scrExpr(void); bool scrIndex(void); bool scrOffset(void); bool scrRef(void); bool scrRestart(void); bool scrInit(void); bool intGoto(void); bool scrGoto(void); bool scrCall(void); bool scrReturn(void); bool scrBegin(void); bool scrEnd(void); bool scrConst(void); bool scrSequence(void); bool scrSet(void); bool scrArray(void); bool scrClear(void); bool scrPack(void); bool scrUnpack(void); bool scrLock(void); bool scrSession(void); bool scrSignal(void); bool scrThrow(void); bool scrInvoke(void); bool scrCounter(void); bool scrTimer(void); bool scrCase(void); bool scrEndcase(void); bool scrRemove(void); bool scrDo(void); bool scrRepeat(void); bool scrFor(void); bool scrForeach(void); bool scrLoop(void); bool scrContinue(void); bool scrBreak(void); bool scrIf(void); bool scrIfThen(void); bool scrThen(void); bool scrElse(void); bool scrEndif(void);};class __EXPORT ScriptThread : public Thread, public Script{private: volatile bool exiting; size_t stacksize;protected: friend class __EXPORT ScriptInterp; ScriptInterp *interp; void exit(const char *errmsg = NULL); void exitEvent(const char *evt, bool inherited = true); inline bool isExiting(void) {return exiting;}; inline bool putSymbol(const char *id, const char *value, unsigned short size = 0) {return interp->putSymbol(id, value, size);}; inline bool getSymbol(const char *id, char *buffer, unsigned short max) {return interp->getSymbol(id, buffer, max);}; inline bool addSymbol(const char *id, char *buffer, unsigned short max) {return interp->getSymbol(id, buffer, max);}; void block(void); void unblock(void); void lock(void); void release(void);public: virtual timeout_t getTimeout(void); inline size_t getStack(void) {return stacksize;}; ScriptThread(ScriptInterp *interp, int pri = 0, size_t stack = 0); ~ScriptThread();};/** * This class is used for registering scripts with an external * registry. Sometimes this is used as a base class for a more * complete one. * * @author David Sugar <dyfet@ostel.com> * @short Registry for script objects. */class __EXPORT ScriptRegistry : public Script, public TimerPort{public: const char *protocol; timeout_t duration; Name *scr; // script being registered Line *line; // line of registry statement};/** * This class is used for DSO modules that impliment property * extensions for scripting objects. * * @author David Sugar <dyfet@ostel.com> * @short ccScript property module */class __EXPORT ScriptProperty : public Script{private: friend class ScriptInterp; static ScriptProperty *first; ScriptProperty *next; const char *id;public: /** * Set property method. Performs set.xxx and init.xxx methods. * * @param data buffer to work from. * @param temp workspace buffer to use. * @param size of temp area. */ virtual void set(const char *data, char *temp, unsigned size) = 0; /** * Precision for property type expressions. * * @return precision. */ virtual unsigned prec(void); /** * Set property from integer value. * * @param data to save. * @param size of data. * @param value being set. */ virtual void setValue(char *data, unsigned short size, long value); /** * See if should be computed as property. * * @return true if property valid. * @param data string to test. */ virtual bool isProperty(const char *data); /** * Initialize a new property through var definition. * * @return property value. * @param data location to clear. * @param size of workspace to clear. */ virtual void clear(char *data, unsigned size = 0); /** * Fetch a property specific seperator token. * * @return seperator token used in foreach loops... */ virtual char token(void); /** * adjust value method. Performs inc.xxx conversions. * * @param data buffer to work from. * @param size of data buffer. * @param adjustment offset to apply. */ virtual void adjust(char *data, size_t size, long adjustment); /** * normalize values for scope and range. * * @return noramized value. * @param value prior to normalization. */ virtual long adjustValue(long value); /** * Get the "numeric" (or #var) value of this property symbol. * * @return numeric value of this property object. * @param data being examined from property object. */ virtual long getValue(const char *data); ScriptProperty(const char *name); virtual ~ScriptProperty(); static ScriptProperty *find(const char *name);};}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?