00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _ORGANIZER_H
00012 #define _ORGANIZER_H
00013
00014 #include "scparser.h"
00015 #include "filecls.h"
00016 #include <sys/types.h>
00017 #include <sys/stat.h>
00018 #include <errno.h>
00019 #include <unistd.h>
00020 #include <time.h>
00021 #include <sys/types.h>
00022 #include <sys/time.h>
00023 #include <sys/resource.h>
00024
00025 #ifdef _PARALLEL
00026 #include <mpi.h>
00027 #endif
00028
00029 class AUXFile
00030 {
00031 public:
00032 LFile *f; int type; int count; char fname[1000], zipname[1000], extname[1000];
00033 virtual int writeentry(void *){return 0;}
00034 virtual int writeblock(void *){return 0;}
00035 virtual int readblock(void *){return 0;}
00036 virtual char *describe(){return 0;}
00037 public:
00038 enum {ENTRIES,BLOCK,SERIES};
00039 AUXFile(int t):f(NULL),type(t),count(1){};
00040 virtual ~AUXFile(){close();}
00041 int close(int zip=0, bool bg=true);
00042 int open(char *name,int format=LFile::O_WriteNew);
00043 int reopen();
00044 int write(void *p, int zip=1, bool bg=true);
00045 int read(void *p);
00046 static const char *Skip(const char *str, const char *blank)
00047 {
00048 ASSERT(str!=NULL);
00049 ASSERT(blank!=NULL);
00050 const char *ret=str;
00051 while(*ret!=0 && strchr(blank, *ret)) ret++;
00052 return ret;
00053 }
00054 static const char *SkipBlanks(const char *str)
00055 { return Skip(str, " \n\t\r"); }
00056
00057 void setcount(int n){count=n;}
00058 private:
00059 static int lastoccur(char *n,char c);
00060 public:
00061 static void insertindex(char *ext,char *n,int c);
00062 };
00063
00064
00065 class Organizer : public SCParser
00066 {
00067 public:
00068 bool overwrite,nolog,renew,diropened;
00069 int sleepseconds;
00070 LFile *olog;
00071 public:
00072 char dirname[1000], logfilename[1000];
00073 public:
00074 Organizer():overwrite(false),nolog(false),renew(false),diropened(false),
00075 sleepseconds(600),olog(NULL){init();};
00076 virtual ~Organizer() {}
00077
00078 void bindvar(char *vn,void *p,int type)
00079 {SCParser::bindvar(vn,p,type);}
00080 int exec(char *name);
00081 int parse(FILE *file);
00082 int parse_line(FILE *file);
00083 int assignvar(int offset=0);
00084 void quit();
00085
00086 private:
00087 void setoverwrite(bool b=true){overwrite=b;}
00088 void setnolog(bool b=true){nolog=b;}
00089 void getsleep();
00090 void init();
00091 int SysParse(FILE *file);
00092 char *currentime();
00093 void printSysInfo();
00094 void printEndInfo();
00095 void closefiles(int zip=1,bool bg=true);
00096 int opendir();
00097 };
00098
00099 #define ah HIC"ASSIGN "NOR
00100 #define eh HIB"EXEC "NOR
00101
00102 #define INFO_buffer_plain(pre,ref,type) INFO(pre<<varname[curn] \
00103 <<" = "\
00104 <<ref((type *)varptr[curn]))
00105 #define INFO_buffer_offset(pre,ref,type) INFO(pre<<varname[curn] \
00106 <<"("<<offset<<") = "\
00107 <<ref(((type *)varptr[curn])+offset))
00108 #define INFO_buffer(pre,ref,type) if(offset==0) \
00109 INFO_buffer_plain(pre,ref,type);\
00110 else INFO_buffer_offset(pre,ref,type);
00111
00112 #endif // _ORGANIZER_H
00113