script3.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // ccScript.  If you copy code from other releases into a copy of GNU
00028 // ccScript, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU ccScript, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00044 #ifndef CCXX_SCRIPT3_H_
00045 #define CCXX_SCRIPT3_H_
00046 
00047 #ifndef CCXX_MISC_H_
00048 #include <cc++/misc.h>
00049 #endif
00050 
00051 #ifndef CXXX_FILE_H_
00052 #include <cc++/file.h>
00053 #endif
00054 
00055 #ifndef CCXX_BUFFER_H_
00056 #include <cc++/buffer.h>
00057 #endif
00058 
00059 #define TRAP_BITS (sizeof(unsigned long) * 8)
00060 #define SCRIPT_INDEX_SIZE KEYDATA_INDEX_SIZE
00061 #define SCRIPT_MAX_ARGS 250
00062 #define SCRIPT_TEMP_SPACE 16
00063 #define SCRIPT_STACK_SIZE 32
00064 #define SCRIPT_ROUTE_SLOTS 16
00065 #define SCRIPT_EXEC_WRAPPER
00066 #define SCRIPT_APPS_WRAPPER
00067 #define SCRIPT_RIPPLE_LEVEL 2
00068 #define SCRIPT_BINDER_SELECT
00069 #define SCRIPT_SERVER_PREFIX
00070 #define SCRIPT_DEFINE_TOKENS
00071 
00072 #ifndef CCXX_PACKING
00073 #if defined(__GNUC__)
00074 #define CCXX_PACKED
00075 #elif !defined(__hpux) && !defined(_AIX)
00076 #define CCXX_PACKED
00077 #endif
00078 #endif  
00079 
00080 namespace ost {
00081 
00082 class __EXPORT ScriptRegistry;
00083 class __EXPORT ScriptCommand;
00084 class __EXPORT ScriptImage;
00085 class __EXPORT ScriptInterp;
00086 class __EXPORT ScriptSymbols;
00087 class __EXPORT ScriptProperty;
00088 class __EXPORT ScriptThread;
00089 class __EXPORT ScriptCompiler;
00090 
00098 class __EXPORT Script
00099 {
00100 public:
00101         class __EXPORT Line;
00102         class __EXPORT Name;
00103 
00104         typedef bool (ScriptInterp::*Method)(void);
00105         typedef const char *(ScriptCommand::*Check)(Line *line, ScriptImage *img);
00106         typedef bool (*Cond)(ScriptInterp *interp, const char *v);
00107         typedef long (*Function)(long *args, unsigned prec);
00108         typedef const char *(*Meta)(ScriptInterp *interp, const char *token);
00109         typedef const char *(*Parse)(ScriptCompiler *img, const char *token);
00110         typedef void (*Init)(void);
00111 
00112         enum scrAccess
00113         {
00114                 scrPUBLIC,
00115                 scrPROTECTED,
00116                 scrPRIVATE,
00117                 scrFUNCTION,
00118                 scrLOCAL
00119         };
00120 
00121         typedef enum scrAccess scrAccess;
00122                 
00123         enum symType
00124         {
00125                 symNORMAL = 0,
00126                 symCONST,
00127                 symDYNAMIC,
00128                 symFIFO,
00129                 symSEQUENCE,
00130                 symSTACK,
00131                 symCOUNTER,
00132                 symPOINTER,
00133                 symREF,
00134                 symARRAY,
00135                 symASSOC,
00136                 symINITIAL,
00137                 symNUMBER,
00138                 symLOCK,
00139                 symPROPERTY,
00140                 symORIGINAL,
00141                 symMODIFIED,
00142                 symTIMER
00143         };
00144 
00145         typedef enum symType symType;
00146 
00147         typedef struct _symbol
00148         {
00149                 struct _symbol *next;
00150                 const char *id;
00151                 unsigned short size;
00152                 symType type: 8;
00153                 char data[1];
00154         }       Symbol;
00155 
00156 #ifdef CCXX_PACKED
00157 #pragma pack(1)
00158 #endif
00159 
00160         typedef struct _array
00161         {
00162                 unsigned short head, tail, rec, count;
00163         }       Array;
00164 
00165 #ifdef  CCXX_PACKED
00166 #pragma pack()
00167 #endif
00168 
00169 public:
00170         class __EXPORT Line
00171         {
00172         public:
00173                 Line *next;
00174                 union
00175                 {
00176                         ScriptRegistry *registry;
00177                         Method method;
00178                         Name *name;
00179                 }       scr;
00180                 const char *cmd, **args;
00181                 unsigned long cmask, mask;
00182                 unsigned short loop, line, lnum;
00183                 unsigned short argc;
00184         };
00185 
00186         class __EXPORT NamedEvent
00187         {
00188         public:
00189                 NamedEvent *next;
00190                 Line *line;
00191                 char type;
00192                 const char *name;
00193         };
00194 
00195         class __EXPORT Name
00196         {
00197         public:
00198                 Name *next;
00199                 NamedEvent *events;
00200                 Line *first, *select;
00201                 Line *trap[TRAP_BITS];
00202                 unsigned long mask;
00203                 const char *name, *filename;
00204                 scrAccess access;
00205         };
00206 
00207         class __EXPORT Initial
00208         {
00209         public:
00210                 const char *name;
00211                 unsigned size;
00212                 const char *value;
00213         };
00214 
00215         class __EXPORT Define
00216         {
00217         public:
00218                 const char *keyword;
00219                 bool init;
00220                 Method method;   
00221                 Check check; 
00222         };
00223 
00224         class __EXPORT Test
00225         {
00226         public:
00227                 const char *id;
00228                 Cond handler;
00229                 Test *next;  
00230         };
00231 
00232         class __EXPORT Fun
00233         {
00234         public:
00235                 const char *id;
00236                 unsigned args;
00237                 Function fn;
00238                 Fun *next;
00239         };
00240 
00241         class __EXPORT InitScript
00242         {
00243         public:
00244                 Init handler;
00245                 InitScript *next;
00246         };      
00247 
00248         class __EXPORT Package : public DSO
00249         {
00250         public:
00251                 static Package *first;
00252                 Package *next;
00253                 const char *filename;
00254         
00255                 Package(const char *name);
00256         };
00257 
00258         static bool fastStart;
00259         static bool useBigmem;
00260         static unsigned fastStepping;
00261         static unsigned autoStepping;
00262         static size_t pagesize;
00263         static unsigned symsize;
00264         static unsigned symlimit;
00265 
00266         static bool isScript(Name *scr);
00267         static bool isSymbol(const char *id);
00268         static bool use(const char *name);
00269         static unsigned getIndex(const char *id);
00270         static Symbol *deref(Symbol *sym);
00271         static bool commit(Symbol *sym, const char *value);
00272         static bool append(Symbol *sym, const char *value);
00273         static bool symindex(Symbol *sym, short offset);
00274         static const char *extract(Symbol *sym);
00275         static unsigned count(Symbol *sym);
00276         static unsigned storage(Symbol *sym);
00277         static void clear(Symbol *sym);
00278         static char decimal;
00279         static bool use_definitions;
00280         static bool use_macros;
00281         static bool use_prefix;
00282         static bool use_merge;
00283         static bool use_funcs;
00284         static const char *plugins;
00285         static const char *altplugins;
00286         static const char *access_user;
00287         static const char *access_pass;
00288         static const char *access_host;
00289         static bool exec_funcs;
00290         static const char *exec_extensions;
00291         static const char *exec_token;
00292         static const char *exec_prefix;
00293         static const char *exit_token;
00294         static const char *apps_extensions;
00295         static const char *apps_prefix;
00296 
00297         static const char *etc_prefix;
00298         static const char *var_prefix;
00299         static const char *log_prefix;
00300 
00301         static void addFunction(const char *name, unsigned count, Function i);
00302         static void addConditional(const char *name, Cond test);
00303 
00304         static bool isPrivate(Name *scr);
00305         static bool isFunction(Name *scr);
00306 
00307 protected:        
00308         static Test *test;
00309         static Fun *ifun;
00310         
00311 };
00312 
00313 class __EXPORT ScriptSymbols : public MemPager, public Script
00314 {
00315 protected:
00316         Symbol *index[SCRIPT_INDEX_SIZE + 1];
00317 
00318         void purge(void);
00319 
00320 public:
00321         ScriptSymbols();
00322         ~ScriptSymbols();
00323 
00324         inline const char *cstring(const char *str)
00325                 {return MemPager::alloc(str);};
00326 
00327         unsigned gathertype(Symbol **idx, unsigned max, const char *prefix, symType group);
00328         unsigned gather(Symbol **idx, unsigned max, const char *prefix, const char *suffix);
00329         Symbol *find(const char *id, unsigned short size = 0);
00330         Symbol *make(const char *id, unsigned short size);
00331 
00332         Symbol *setReference(const char *id, Symbol *target);
00333 };
00334 
00346 class __EXPORT ScriptCommand : public Keydata, public Mutex, public Script
00347 {
00348 private:
00349         friend class __EXPORT ScriptImage;
00350         friend class __EXPORT ScriptInterp;
00351         friend class __EXPORT ScriptCompiler;
00352         friend class __EXPORT ScriptBinder;
00353 
00354 #ifdef  CCXX_PACKED
00355 #pragma pack(1)
00356 #endif
00357 
00358         typedef struct _keyword
00359         {
00360                 struct _keyword *next;
00361                 Method method;
00362                 Check check;
00363                 bool init : 1;
00364                 char keyword[1];
00365         }       Keyword;
00366 
00367 #ifdef  CCXX_PACKED
00368 #pragma pack()
00369 #endif
00370 
00371         ThreadQueue *tq;
00372         Keyword *keywords[SCRIPT_INDEX_SIZE];
00373         char *traps[TRAP_BITS];
00374         ScriptImage *active;
00375         unsigned keyword_count;
00376         unsigned trap_count;
00377         unsigned long imask;
00378         unsigned dbcount;
00379         void *dbc;
00380 
00381 protected:
00382         bool ripple;
00383         unsigned activity;      // activity counter
00384         static ScriptCommand *runtime;
00385 
00386         virtual const char *getExternal(const char *opt);
00387 
00388 public:
00396         virtual bool isInput(Line *line);
00397 
00405         Method getHandler(const char *keyword);
00406 
00414         bool control(char **args);
00415 
00421         inline ScriptImage *getActive(void)
00422                 {return active;};
00423 
00430         const char *getTrapName(unsigned id);
00431 
00438         void aliasModule(const char *id, const char *use);
00439 
00440 protected:
00447         bool isInitial(const char *keyword);
00448 
00457         const char *check(char *command, Line *line, ScriptImage *img);
00458 
00465         virtual unsigned getTrapId(const char *name);
00466 
00472         virtual unsigned long getTrapDefault(void);
00473 
00479         virtual unsigned long getTrapHandler(Name *script);
00480   
00488         virtual unsigned long getTrapMask(unsigned id);
00489 
00498         virtual unsigned long getTrapModifier(const char *name);
00499 
00508         virtual unsigned long getTrapMask(const char *name);
00509 
00516         static bool hasKeywords(Line *line);
00517 
00518 public:
00526         static const char *findKeyword(Line *line, const char *keyword);
00527 
00534         virtual void errlog(const char *level, const char *text);
00535 
00536 public:
00544         static bool useKeywords(Line *line, const char *list);
00545 
00552         static unsigned getCount(Line *line);
00553 
00560         static const char *getMember(Line *line);
00561 
00562 
00563 protected:
00571         static bool useMember(Line *line, const char *list);
00572 
00580         static const char *getOption(Line *line, unsigned *index);
00581 
00589         void load(Script::Define *keywords);
00590 
00600         int trap(const char *name, bool inherited = true);
00601 
00607         inline unsigned getCount(void)
00608                 {return trap_count;};
00609 
00613         bool isInherited(unsigned id);
00614 
00623         virtual const char *check(Check chk, Line *line, ScriptImage *img);
00624 
00625 public:
00629         ScriptCommand();
00630 
00634         ScriptCommand(ScriptCommand *ini);
00635 
00641         inline unsigned getActivity(void)
00642                 {return activity;};
00643 
00644 };
00645 
00646 class __EXPORT ScriptBinder : public Script
00647 {
00648 private:
00649         friend class __EXPORT ScriptInterp;
00650         friend class __EXPORT ScriptCompiler;
00651         friend class __EXPORT ScriptCommand;
00652 
00653         static ScriptBinder *first;
00654         ScriptBinder *next;
00655         const char *id;
00656 
00657 protected:
00658         void bind(Script::Define *extensions);
00659         
00660         virtual void attach(ScriptInterp *interp);
00661         virtual void detach(ScriptInterp *interp);
00662         virtual bool select(ScriptInterp *interp);
00663         virtual bool reload(ScriptCompiler *img);
00664         virtual bool control(ScriptImage *img, char **args);
00665         virtual void down(void);
00666         virtual const char *use(Line *line, ScriptImage *img);
00667 
00668 public:
00669         ScriptBinder(const char *id = NULL);
00670         ScriptBinder(Script::Define *extensions);
00671         virtual ~ScriptBinder();
00672 
00673         static const char *check(Line *line, ScriptImage *img);
00674         static void shutdown(void);
00675         static bool rebuild(ScriptCompiler *img);
00676 };
00677 
00678 class __EXPORT ScriptRuntime : public ScriptCommand
00679 {
00680 public:
00681         ScriptRuntime();
00682 };
00683 
00684 class __EXPORT ScriptRipple : public ScriptCommand
00685 {
00686 public:
00687         ScriptRipple();
00688 };
00689 
00690 class __EXPORT ScriptChecks : public ScriptCommand
00691 {
00692 public:
00696         const char *chkIgnore(Line *line, ScriptImage *img);
00697 
00701         const char *chkUse(Line *line, ScriptImage *img);
00702 
00710         const char *chkHasModify(Line *line, ScriptImage *img);
00711 
00719         const char *chkProperty(Line *line, ScriptImage *img);
00720 
00728         const char *chkFirstVar(Line *line, ScriptImage *img);
00729 
00737         const char *chkType(Line *line, ScriptImage *img);
00738 
00748         const char *chkHasVars(Line *line, ScriptImage *img);
00749 
00758         const char *chkHasList(Line *line, ScriptImage *img);
00759 
00768         const char *chkNoArgs(Line *line, ScriptImage *img);
00769 
00778         const char *chkAllVars(Line *line, ScriptImage *img);
00779 
00788         const char *chkHasArgs(Line *line, ScriptImage *img);
00789 
00798         const char *chkOnlyArgs(Line *line, ScriptImage *img);
00799 
00800         const char *chkOnlyOneArg(Line *line, ScriptImage *img);
00801 
00802         const char *chkRefArgs(Line *line, ScriptImage *img);
00803 
00804         const char *chkSlog(Line *line, ScriptImage *img);
00805 
00806         const char *chkExpression(Line *line, ScriptImage *img);
00807 
00808         const char *chkConditional(Line *line, ScriptImage *img);
00809 
00810         const char *chkGoto(Line *line, ScriptImage *img);
00811 
00812         const char *chkLabel(Line *line, ScriptImage *img);
00813 
00814         const char *chkCall(Line *line, ScriptImage *img);
00815 
00816         const char *chkReturn(Line *line, ScriptImage *img);
00817 
00818         const char *chkRestart(Line *line, ScriptImage *img);
00819 
00820         const char *chkVar(Line *line, ScriptImage *img);
00821 
00822         const char *chkVarType(Line *line, ScriptImage *img);
00823 
00824         const char *chkDecimal(Line *line, ScriptImage *img);
00825 
00826         const char *chkNumber(Line *line, ScriptImage *img);
00827 
00828         const char *chkString(Line *line, ScriptImage *img);
00829 
00830         const char *chkChar(Line *line, ScriptImage *img);
00831 
00832         const char *chkExpr(Line *line, ScriptImage *img);
00833 
00834         const char *chkIndex(Line *line, ScriptImage *img);
00835 
00836         const char *chkError(Line *line, ScriptImage *img);
00837 
00838         const char *chkConst(Line *line, ScriptImage *img);
00839 
00840         const char *chkSequence(Line *line, ScriptImage *img);
00841 
00842         const char *chkSignal(Line *line, ScriptImage *img);
00843 
00844         const char *chkThrow(Line *line, ScriptImage *img);
00845 
00846         const char *chkSet(Line *line, ScriptImage *img);
00847 
00848         const char *chkRepeat(Line *line, ScriptImage *img);
00849 
00850         const char *chkArray(Line *line, ScriptImage *img);
00851 
00852         const char *chkFor(Line *line, ScriptImage *img);
00853 
00854         const char *chkForeach(Line *line, ScriptImage *img);
00855 
00856         const char *chkCat(Line *line, ScriptImage *img);
00857 
00858         const char *chkRemove(Line *line, ScriptImage *img);
00859 
00860         const char *chkOnlyCommand(Line *line, ScriptImage *img);
00861 
00862         const char *chkCounter(Line *line, ScriptImage *img);
00863 
00864         const char *chkTimer(Line *line, ScriptImage *img);
00865 
00866         const char *chkClear(Line *line, ScriptImage *img);
00867 
00868         const char *chkPack(Line *line, ScriptImage *img);
00869 
00870         const char *chkLock(Line *line, ScriptImage *img);
00871 
00872         const char *chkSession(Line *line, ScriptImage *img);
00873 
00874         const char *chkKeywords(Line *line, ScriptImage *img);
00875 
00876         const char *chkDefine(Line *line, ScriptImage *img);
00877 };
00878 
00886 class __EXPORT ScriptObject : public Script
00887 {
00888 private:
00889         friend class __EXPORT ScriptImage;
00890         ScriptObject *next;
00891 
00892 protected:
00893         ScriptObject(ScriptImage *image);
00894         virtual ~ScriptObject();
00895 };
00896 
00906 class __EXPORT ScriptImage : public Keydata, public Script, public Assoc
00907 {
00908 protected:
00909         friend class __EXPORT ScriptObject;
00910 
00911         ScriptCommand *cmds;
00912         unsigned refcount;
00913         Name *index[SCRIPT_INDEX_SIZE + 1], *current;
00914         Line *select, *selecting, *registration;
00915         Line *advertising[SCRIPT_ROUTE_SLOTS];
00916         Mutex duplock;
00917         ScriptObject *objects;
00918         static unsigned long serial;
00919         unsigned long instance;
00920         
00921         class   __EXPORT InitialList : public Script::Initial
00922         {
00923         public:
00924                 InitialList *next;
00925         }       *ilist;
00926 
00927         friend class __EXPORT ScriptInterp;
00928 
00935         Method getHandler(const char *keyword)
00936                 {return cmds->getHandler(keyword);};
00937 
00938 public:
00945         void *getMemory(size_t size);
00946 
00950         virtual void fastBranch(ScriptInterp *interp);
00951 
00957         inline Name *getCurrent(void)
00958                 {return current;};
00959 
00965         void addSelect(Line *line);
00966 
00972         void addRegistration(Line *line);
00973 
00979         ScriptRegistry *getRegistry(void);
00980 
00987         void addRoute(Line *line, unsigned pri);
00988 
00994         inline Line *getSelect(void)
00995                 {return select;};
00996 
01002         inline Line *getRegistration(void)
01003                 {return registration;};
01004 
01010         inline Line *getRoute(unsigned pri)
01011                 {return advertising[pri];};
01012 
01016         inline unsigned long getInstance(void)
01017                 {return instance;};
01018 
01027         ScriptImage(ScriptCommand *cmdset, const char *symset);
01028 
01032         ~ScriptImage();
01033 
01037         void purge(void);
01038 
01044         void commit(void);
01045 
01051         void load(Initial *ilist);
01052 
01060         void initial(const char *keyword, const char *value, unsigned size = 0);
01061 
01068         virtual Name *getScript(const char *name);
01069 
01075         inline ScriptCommand *getCommand(void)
01076                 {return cmds;};
01077 
01083         bool isRipple(void)
01084                 {return cmds->ripple;};
01085 
01094         unsigned gather(const char *suffix, Name **array, unsigned size);
01095 
01099         inline void incRef(void)
01100                 {++refcount;};
01101 
01105         inline void decRef(void)
01106                 {--refcount;};
01107 
01113         inline bool isRef(void)
01114                 {return (bool)(refcount > 0);};
01115 
01121         inline ScriptImage *getActive(void)
01122                 {return cmds->getActive();};
01123 };
01124 
01134 class __EXPORT ScriptCompiler : public ScriptImage
01135 {
01136 protected:
01137         std::ifstream scrSource;
01138         std::istream *scrStream;
01139         char *buffer;
01140         unsigned bufsize;
01141         char *bp;
01142         bool quote;
01143         unsigned paren;
01144         unsigned inccount;
01145         const char *incfiles[256];
01146 
01147         typedef struct _merge
01148         {
01149                 struct _merge *next;
01150                 Name *target;
01151                 const char *source;
01152                 const char *prefix;
01153         }       merge_t;
01154 
01155         merge_t *mlist;
01156         
01157         friend class __EXPORT ScriptInterp;
01158 
01159         virtual bool checkSegment(Name *scr);
01160 
01161 public:
01162         char *getToken(char **pre = NULL);
01163 
01167         virtual void fastBranch(ScriptInterp *interp);
01168 
01177         ScriptCompiler(ScriptCommand *cmdset, const char *symset);
01178 
01186         Name *include(const char *name);
01187 
01196         int compile(const char *file);
01197 
01206         int compile(const char *file, char *name);
01207 
01215         int compileDefinitions(const char *file);
01216 
01225         int compile(std::istream *stream, char *name, const char *file = NULL);
01226 
01232         void commit(void);
01233 
01240         virtual const char *getDefined(const char *token);
01241 
01248         const char *preproc(const char *token);
01249 
01256         inline std::istream *getSource(void)
01257                 {return (std::istream *)&scrSource;};
01258 };
01259 
01260 class __EXPORT ScriptInterp : public Mutex, public ScriptSymbols
01261 {
01262 protected:
01263         friend class __EXPORT ScriptThread;
01264         friend class __EXPORT ScriptCommand;
01265         friend class __EXPORT ScriptBinder;
01266 
01267 public:
01268         class __EXPORT Frame
01269         {
01270         public:
01271                 Name *script;
01272                 Line *line, *first;
01273                 unsigned short index;
01274                 ScriptSymbols *local;
01275                 unsigned long mask;
01276                 bool caseflag : 1;
01277                 bool tranflag : 1;
01278                 bool unused1 : 1;
01279                 bool unused2 : 1;
01280                 unsigned decimal : 4;
01281                 unsigned base : 8;
01282         };
01283         
01284         static long getRealValue(double val, unsigned prec);
01285         static double getDouble(long value, unsigned prec);
01286         static long getInteger(long value, unsigned prec);
01287         static long getTens(unsigned prec);
01288         long getIntValue(const char *text, unsigned prec, ScriptProperty *property = NULL);
01289         int numericExpression(long *list, int max, unsigned prec, ScriptProperty *property = NULL);
01290         bool conditionalExpression(void);
01291         bool conditional(void);
01292         
01293 protected:
01294         Mutex *lock;    // any additional lock that is siezed
01295         ScriptCommand *cmd;
01296         ScriptImage *image;
01297         ScriptInterp *session;
01298         ScriptThread *thread;
01299         Frame frame[SCRIPT_STACK_SIZE];
01300         char *temps[SCRIPT_TEMP_SPACE];
01301         unsigned tempidx;
01302         unsigned stack;
01303         bool initialized, trace, exiting, updated;
01304         unsigned long sequence;
01305         char logname[32];
01306 
01307 public: 
01308         virtual unsigned getId(void);
01309 
01310         inline unsigned long getSequence(void)
01311                 {return sequence;};
01312 
01313         virtual const char *getLogname(void)
01314                 {return logname;};
01315 
01316         virtual ScriptInterp *getInterp(const char *id);
01317 
01318         virtual const char *getExternal(const char *opt);
01319 
01320         inline ScriptImage *getImage(void)
01321                 {return image;};
01322 
01323 protected:
01324         virtual ScriptSymbols *getSymbols(const char *id);
01325 
01326         ScriptSymbols *getLocal(void);
01327 
01328 public:
01329         const char *getMember(void);
01330         const char *getKeyword(const char *kw);
01331         const char *getKeyoption(const char *kw);
01332         const char *getValue(const char *def = NULL);
01333         const char *getOption(const char *def = NULL);
01334         const char *hasOption(void);
01335         const char *getContent(const char *opt);
01336         const char *getSymContent(const char *opt);
01337         Symbol *getKeysymbol(const char *kw, unsigned size = 0);
01338         Symbol *getSymbol(unsigned short size = 0);
01339         char getPackToken(void);
01340 
01341 protected:
01345         void initRuntime(Name *name); 
01346 
01351         virtual void initialize(void);
01352 
01353 public:
01354         inline Frame *getFrame(void)
01355                 {return &frame[stack];};
01356 
01357         inline Line *getLine(void)
01358                 {return frame[stack].line;};
01359 
01360         void setFrame(void);
01361 
01362         inline Name *getName(void)
01363                 {return frame[stack].script;};
01364 
01365         inline bool getTrace(void)
01366                 {return trace;};
01367 
01375         bool execute(Method method);
01376 
01377 protected:
01383         bool push(void);
01384 
01390         bool pull(void);
01391 
01395         void clearStack(void);
01396 
01400         void advance(void);    
01401 
01405         void skip(void);
01406 
01413         void error(const char *error);  
01414 
01425         bool scriptEvent(const char *name, bool inhereted = true);
01426 
01432         void gotoEvent(NamedEvent *event);
01433 
01441         void trap(unsigned id);
01442 
01449         bool tryCatch(const char *id);
01450 
01457         void trap(const char *name);
01458 
01459 public:
01460         virtual void logmissing(const char *id, const char *level = "undefined", const char *group = "symbol");
01461         virtual void logerror(const char *msg, const char *name = NULL);
01462 
01463         Symbol *mapSymbol(const char *id, unsigned short = 0);
01464         Symbol *mapDirect(const char *id, unsigned short = 0);
01465 
01466 protected:
01467         virtual bool isLocked(const char *id);
01468         virtual const char *remapLocal(void);
01469         virtual bool exit(void);
01470         virtual void enterThread(ScriptThread *thread);
01471         virtual void exitThread(const char *msg);
01472         virtual void waitThread(void);
01473         virtual void startThread(void);
01474 
01475         bool eventThread(const char *evt, bool flag = true);
01476         
01477         bool redirect(const char *scr);
01478 
01479         void ripple(void);
01480 
01481         bool redirect(bool evflag);
01482 
01483         unsigned long getMask(void);
01484 
01485 public:
01486         bool setNumber(const char *id, const char *value = NULL, unsigned dec = 0);
01487         bool setSymbol(const char *id, const char *value = NULL, unsigned short size = 0);
01488         bool setConst(const char *id, const char *value);
01489         bool putSymbol(const char *id, const char *value, unsigned short size = 0);
01490         bool getSymbol(const char *id, char *buffer, unsigned short max);
01491         bool catSymbol(const char *id, const char *value, unsigned short size = 0);
01492 
01493         const char *getSymbol(const char *id);
01494 
01495         Name *getScript(const char *name);
01496 
01497         ScriptInterp();
01498 
01499         bool step(void);
01500         bool attach(ScriptCommand *cmd, const char *scrname);
01501         void detach(void);
01502         void attach(ScriptCommand *cmd, ScriptImage *img, Name *scr);
01503 
01507         void release(void);
01508         
01518         bool signal(const char *name);
01519 
01527         bool signal(unsigned id);
01528 
01529         bool done(void);
01530 
01531         timeout_t getTimeout(void);
01532 
01538         virtual void branching(void);
01539 
01540         inline bool isRunning(void)
01541                 {return (image != NULL) && initialized;};
01542 
01543         inline bool isExiting(void)
01544                 {return exiting;};
01545 
01546         char *getTemp(void);
01547 
01548         unsigned getTempSize(void);
01549 };
01550 
01551 class __EXPORT ScriptMethods : public ScriptInterp
01552 {
01553 public:
01554         bool scrNop(void);
01555         bool scrError(void);
01556         bool scrExit(void);
01557         bool scrDecimal(void);
01558         bool scrDefine(void);
01559         bool scrVar(void);
01560         bool scrType(void);
01561         bool scrNumber(void);
01562         bool scrSlog(void);
01563         bool scrExpr(void);
01564         bool scrIndex(void);
01565         bool scrOffset(void);
01566         bool scrRef(void);
01567         bool scrRestart(void);
01568         bool scrInit(void);
01569         bool intGoto(void);
01570         bool scrGoto(void);
01571         bool scrCall(void);
01572         bool scrReturn(void);
01573         bool scrBegin(void);
01574         bool scrEnd(void);
01575         bool scrConst(void);
01576         bool scrSequence(void);
01577         bool scrSet(void);
01578         bool scrArray(void);
01579         bool scrClear(void);
01580         bool scrPack(void);
01581         bool scrUnpack(void);
01582         bool scrLock(void);
01583         bool scrSession(void);
01584         bool scrSignal(void);
01585         bool scrThrow(void);
01586         bool scrInvoke(void);
01587         bool scrCounter(void);
01588         bool scrTimer(void);
01589         bool scrCase(void);
01590         bool scrEndcase(void);
01591         bool scrRemove(void);
01592         bool scrDo(void);
01593         bool scrRepeat(void);
01594         bool scrFor(void);
01595         bool scrForeach(void);
01596         bool scrLoop(void);
01597         bool scrContinue(void);
01598         bool scrBreak(void);
01599         bool scrIf(void);
01600         bool scrIfThen(void);
01601         bool scrThen(void);
01602         bool scrElse(void);
01603         bool scrEndif(void);
01604 };
01605 
01606 class __EXPORT ScriptThread : public Thread, public Script
01607 {
01608 private:
01609         volatile bool exiting;
01610         size_t stacksize;
01611 
01612 protected:
01613         friend class __EXPORT ScriptInterp;
01614 
01615         ScriptInterp *interp;
01616         
01617         void exit(const char *errmsg = NULL);
01618 
01619         void exitEvent(const char *evt, bool inherited = true);
01620 
01621         inline bool isExiting(void)
01622                 {return exiting;};
01623 
01624         inline bool putSymbol(const char *id, const char *value, unsigned short size = 0)
01625                 {return interp->putSymbol(id, value, size);};
01626 
01627         inline bool getSymbol(const char *id, char *buffer, unsigned short max)
01628                 {return interp->getSymbol(id, buffer, max);};
01629 
01630         inline bool addSymbol(const char *id, char *buffer, unsigned short max)
01631                 {return interp->getSymbol(id, buffer, max);};
01632 
01633         void block(void);
01634 
01635         void unblock(void);
01636 
01637         void lock(void);
01638 
01639         void release(void);
01640 
01641 public:
01642         virtual timeout_t getTimeout(void);
01643         
01644         inline size_t getStack(void)
01645                 {return stacksize;};
01646 
01647         ScriptThread(ScriptInterp *interp, int pri = 0, size_t stack = 0);
01648         ~ScriptThread();
01649 };
01650 
01659 class __EXPORT ScriptRegistry : public Script, public TimerPort
01660 {
01661 public:
01662         const char *protocol;
01663         timeout_t duration;
01664         Name *scr;              // script being registered
01665         Line *line;             // line of registry statement
01666 };
01667 
01675 class __EXPORT ScriptProperty : public Script
01676 {
01677 private:
01678         friend class ScriptInterp;
01679 
01680         static ScriptProperty *first;
01681         ScriptProperty *next;
01682         const char *id;
01683 
01684 public:
01692         virtual void set(const char *data, char *temp, unsigned size) = 0;
01693 
01699         virtual unsigned prec(void);
01700 
01708         virtual void setValue(char *data, unsigned short size, long value);
01709 
01716         virtual bool isProperty(const char *data);
01717 
01725         virtual void clear(char *data, unsigned size = 0);
01726 
01732         virtual char token(void);
01733 
01741         virtual void adjust(char *data, size_t size, long adjustment);
01742 
01749         virtual long adjustValue(long value);
01750 
01757         virtual long getValue(const char *data);
01758 
01759         ScriptProperty(const char *name);
01760         virtual ~ScriptProperty();
01761 
01762         static ScriptProperty *find(const char *name);
01763 };
01764 
01765 }
01766 
01767 #endif
01768 

Generated on Thu Apr 6 09:03:03 2006 for Bayonne Framework by  doxygen 1.4.6