ZExport0 ZProfile::ZProfile (const ZProfile & aProfile) { ZFUNCTRACE_DEVELOP ("ZProfile::ZProfile(const ZProfile& aProfile)"); #ifdef ZC_WIN iRootHandle = 0; iPathHandle = 0; #endif #ifdef ZC_OS2 iHab = WinInitialize (0); if (iHab == 0) throwSysErr (WinInitializeName); #endif *this = aProfile; } // ZProfile
static ZString splitPath (ZString & aPath) { ZFUNCTRACE_DEVELOP ("splitPath(ZString& aPath)"); long pos (aPath.indexOf (ZC_PATHSEPARATOR)); if (!pos) { ZString ret (aPath); aPath = ""; return ret; } // if ZString ret (aPath.subString (1, pos - 1)); aPath = aPath.subString (pos + 1); return ret; } // splitPath
ZCsl::Instruction * ZCsl::Instruction::last () { ZFUNCTRACE_DEVELOP ("ZCsl::Instruction::last()"); Instruction *p = 0; Instruction *i = this; while (i->iNext) { p = i; i = i->iNext; } // while if (!p) ZTHROWEXC (ZString (msgInternalErr) + "(Instruction::last)"); return p; } // last
void ZProfile::openPath (ZBoolean aCreate) { ZFUNCTRACE_DEVELOP ("ZProfile::openPath(ZBoolean aCreate)"); if (iPathHandle == 0 || (aCreate && iPathReadOnly)) { closePath (); openRoot (aCreate); if (iPath.size ()) iPathHandle = openHandle ((HKEY) iRootHandle, iPath, aCreate); else iPathHandle = iRootHandle; iPathReadOnly = !aCreate; } // if } // openPath
ZCsl::Variable & ZCsl::Variable::set (const ZString & aValue, ZBoolean aInitConst) { ZFUNCTRACE_DEVELOP ("ZCsl::Variable::set(const ZString& aValue, ZBoolean aInitConst)"); if (iIsExtern) iParent->throwExcept (msgUnallocExtern, iName); if (iIsConst && !aInitConst) iParent->throwExcept (msgWriteConst, iName); if (iIndex < 0 || iIndex >= size ()) iParent->throwExcept (msgInvalidIndex, iName); iVals[iIndex] = aValue; return *this; } // set
long ZDateTime::asSeconds () const { ZFUNCTRACE_DEVELOP ("ZDateTime::asSeconds() const"); if (iYear < 1902 || iYear > 2039) ZTHROWEXC ("Cannot handle year outside 1902-2038 (" + ZString ((int) iYear) + ")"); struct tm t; t.tm_year = iYear - 1900; t.tm_mon = iMonth - 1; t.tm_mday = iDay; t.tm_hour = iHour; t.tm_min = iMinute; t.tm_sec = iSecond; return mktime (&t); } // asSeconds
static ZString getWinError () { ZFUNCTRACE_DEVELOP ("getWinError()"); DWORD errcode = GetLastError (); LPTSTR lpMsgBuf; FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, errcode, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) & lpMsgBuf, 0, NULL); ZString msg (lpMsgBuf); LocalFree (lpMsgBuf); return msg; } // getWinError
ZExport (ZProfile &) ZProfile::setPath (const ZString & aPath) { ZFUNCTRACE_DEVELOP ("ZProfile::setPath(const ZString& aPath)"); #ifdef ZC_WIN ZString newPath (stripPath (aPath)); if (iPath != newPath) { closePath (); iPath = newPath; } // if #endif #ifdef ZC_OS2 iPath = aPath; #endif return *this; } // setPath
ZExport(int) ZSqlLink::getCursor(ZSqlCursor **csr) { ZFUNCTRACE_DEVELOP("ZSqlLink::getCursor(ZSqlCursor **csr)"); int ret, prio, curr; int old = -1; ZSqlCursor *c; // search for active cursor for (curr = 0; curr < iCsrCount; curr++) { c = iCsrPool[curr]; if ( csr == c->iOwner && *csr == c ) { ret = c->newParseRequired() || c->iInv; goto gotcursor; } // if if (!c->iPrio) old = curr; // remember least busy cursor } // for // check if new cursor may be opened if (iCsrCount < iMaxCursor) { iCsrPool[iCsrCount] = allocCursor(); curr = iCsrCount; iCsrPool[curr]->iPrio = iCsrCount++; } else { if (old < 0) ZTHROWEXC("Internal error in ZSql.cpp"); curr = old; iCsrPool[curr]->newParseRequired(); // for DB2 cleanup! } // if // save owner signature and return SqlCursor ptr ret = 1; c = *csr = iCsrPool[curr]; c->iOwner = csr; gotcursor: c->iInv = zFalse; // mark this cursor most busy if ( c->iPrio < iCsrCount-1) { prio = c->iPrio; c->iPrio = iCsrCount; for (curr = 0; curr < iCsrCount; curr++) { c = iCsrPool[curr]; if (c->iPrio >= prio) c->iPrio--; } // for } // if return ret; } // getCursor
ZExport (int) ZRegularExpression::match (const ZString & aString, int aMaxMatches, long *aStartpos, long *aLength, int aMatchFlags) { ZFUNCTRACE_DEVELOP ("ZRegularExpression::match(const ZString&, int, long*, long*, int)"); if (!iHandle) ZTHROWEXC ("Invalid regular expression!"); // check nmatch if (aMaxMatches < 0) ZTHROWEXC ("match count >= 0"); if (aMaxMatches > __REG_SUBEXP_MAX) ZTHROWEXC ("match count must be <= " + ZString (__REG_SUBEXP_MAX)); regmatch_t rm[__REG_SUBEXP_MAX]; int eflags (0); if (aMatchFlags & matchNotBol) eflags |= REG_NOTBOL; if (aMatchFlags & matchNotEol) eflags |= REG_NOTEOL; // do the matching int err = regexec ((regex_t *) iHandle, aString, aMaxMatches, rm, eflags); if (err == REG_NOMATCH) return 0; if (err) { char msg[80]; regerror (err, (regex_t *) iHandle, msg, sizeof (msg)); ZTHROWEXC (msg); } // if // get the results for (int x = 0; x < aMaxMatches; x++) { if (rm[x].rm_so < 0) return x; aStartpos[x] = rm[x].rm_so + 1; aLength[x] = rm[x].rm_eo - rm[x].rm_so; } // for return aMaxMatches; } // match
ZExport (ZProfile &) ZProfile::deleteValue (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::deleteValue(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); RegDeleteValue ((HKEY) iPathHandle, aValueName); #endif #ifdef ZC_OS2 if (!iPath.size ()) ZTHROWEXC (MissingPath); if (!aValueName.size ()) ZTHROWEXC (MissingValueName); openRoot (); if (!PrfWriteProfileString (iRootHandle, iPath, aValueName, 0)) throwSysErr (PrfWriteProfileStringName); #endif return *this; } // deleteValue
ZExport0 ZProfile::ZProfile (const ZString & aRoot, const ZString & aPath) { ZFUNCTRACE_DEVELOP ("ZProfile::ZProfile(const ZString& aRoot, const ZString& aPath)"); #ifdef ZC_WIN iRootHandle = 0; iPathHandle = 0; iRoot = stripPath (aRoot); setPath (aPath); #endif #ifdef ZC_OS2 iHab = WinInitialize (0); if (iHab == 0) throwSysErr (WinInitializeName); iRoot = aRoot; iPath = aPath; #endif } // ZProfile
ZCsl::Instruction * ZCsl::Instruction::copy (Instruction * aInst) { ZFUNCTRACE_DEVELOP ("ZCsl::Instruction::copy(Instruction* aInst)"); Instruction *i = aInst; Instruction *n = next (); Instruction *n2 = n; ZBoolean reloc (zFalse); while (i->iNext) { n->iCode = i->iCode; n->iAddr = i->iAddr; if (i->iAddr) reloc = zTrue; n->iText = i->iText; n->iFunc = i->iFunc; n->iNext = new Instruction; i = i->iNext; n = n->iNext; } // if if (reloc) { n = n2; while (n->iNext) { if (n->iAddr) { Instruction *ii = aInst; Instruction *nn = n2; while (ii) { if (ii == n->iAddr) { n->iAddr = nn; break; } // if ii = ii->iNext; nn = nn->iNext; } // while } // if n = n->iNext; } // while } // if return n; } // copy
ZExport (long) ZProfile::longValue (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::longValue(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); DWORD data, dataType, size (4); if (!RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, &dataType, (LPBYTE) & data, &size) == ERROR_SUCCESS) ZTHROWEXC (ValueNotFound); if (dataType != 4) ZTHROWEXC (UnsupportedDataType); return data; #endif #ifdef ZC_OS2 return value (aValueName).asLong (); #endif } // longValue
ZExport (ZProfile &) ZProfile::setValue (long aValue, const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::setValue(const ZString& aValue, const ZString& aValueName, int aType)"); #ifdef ZC_WIN openPath (zTrue); if (valueExists (aValueName)) deleteValue (aValueName); if (!RegSetValueEx ((HKEY) iPathHandle, aValueName, 0, 4, (LPBYTE) & aValue, 4) == ERROR_SUCCESS) throwSysErr (SRegSetValueEx); #endif #ifdef ZC_OS2 setValue (ZString (aValue)); #endif return *this; } // setValue
void ZCsl::dump (Function * aFunc) { ZFUNCTRACE_DEVELOP ("ZCsl::dump(Function* aFunc)"); log (); log (funcHeader (aFunc).constBuffer ()); log (); log ("address opcode parameter"); log ("-------- ------ --------------------------------------------------------------"); PackedInstruction *p = aFunc->iPcode; for (long i (0); i < aFunc->iPsize; i++) log (dumpInstr (i, p++, zFalse).constBuffer ()); ZString msg = "code: " + ZString (aFunc->iPsize * sizeof (PackedInstruction)) + " " + "text: " + ZString (aFunc->iTsize) + " " + "total: " + ZString (aFunc->iPsize * sizeof (PackedInstruction) + aFunc->iTsize); log (); log (msg.constBuffer ()); } // dump
ZExport (ZBoolean) ZProfile::valueExists (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::valueExists(const ZString& aValueName)"); #ifdef ZC_WIN try { openPath (zFalse); } catch (const ZException & exc) { return zFalse; } // catch #endif #ifdef ZC_OS2 openRoot (); #endif ZStringlist list; getValues (list); return list.find (aValueName) >= 0; } // valueExists
ZExport (ZBoolean) ZProfile::keyExists (const ZString & aKeyName) { ZFUNCTRACE_DEVELOP ("ZProfile::keyExists(const ZString& aKeyName)"); ZStringlist list; ZBoolean found; if (aKeyName.size ()) { getKeys (list); found = list.find (aKeyName) >= 0; } else { #ifdef ZC_WIN found = zTrue; try { openPath (zFalse); } catch (const ZException & exc) { found = zFalse; } // catch #endif #ifdef ZC_OS2 ZString path (iPath); try { setPath (""); getKeys (list); found = list.find (path) >= 0; setPath (path); } // try catch (const ZException & exc) { setPath (path); throw; } // catch #endif } // if return found; } // keyExists
void ZProfile::closeRoot () { ZFUNCTRACE_DEVELOP ("ZProfile::closeRoot()"); #ifdef ZC_WIN if (iRootHandle) { closePath (); closeHandle ((HKEY) iRootHandle); iRootHandle = 0; } // if #endif #ifdef ZC_OS2 if (iRootHandle != 0 && iRootHandle != HINI_SYSTEMPROFILE && iRootHandle != HINI_USERPROFILE) { if (!PrfCloseProfile (iRootHandle)) throwSysErr (PrfCloseProfileName); iRootHandle = 0; } // if #endif } // closeRoot
static HKEY openHandle (HKEY aParentHandle, ZString aPath, ZBoolean aCreate) { ZFUNCTRACE_DEVELOP ("openHandle(HKEY aParentHandle, ZString aPath, ZBoolean aCreate)"); HKEY parentHandle (aParentHandle); HKEY handle; for (;;) { ZString token (splitPath (aPath)); if (aCreate) { if (RegCreateKeyEx (parentHandle, token.constBuffer (), 0, "", REG_OPTION_NON_VOLATILE, (KEY_READ | KEY_WRITE), NULL, &handle, NULL) != ERROR_SUCCESS) { if (parentHandle != aParentHandle) closeHandle (parentHandle); throwSysErr (SRegCreateKeyEx); } // if } else { if (RegOpenKeyEx (parentHandle, token.constBuffer (), 0, KEY_READ, &handle) != ERROR_SUCCESS) { if (parentHandle != aParentHandle) closeHandle (parentHandle); throwSysErr (SRegOpenKeyEx); } // if } // if if (parentHandle != aParentHandle) closeHandle (parentHandle); if (aPath.size () == 0) break; parentHandle = handle; } // for return handle; } // openHandle
ZExport (ZProfile &) ZProfile::deleteKey (const ZString & aKeyName) { ZFUNCTRACE_DEVELOP ("ZProfile::deleteKey(const ZString& aKeyName)"); #ifdef ZC_WIN // delete all values and subkeys first ZString oldPath (iPath); try { setPath (iPath + (char) ZC_PATHSEPARATOR + aKeyName); openPath (zFalse); ZStringlist list; int i; // delete all values setValue (ZString ()); // just clear out default value getValues (list); for (i = 0; i < list.count (); i++) if (list[i].size ()) { deleteValue (list[i]); } // if // delete all subkeys getKeys (list); for (i = 0; i < list.count (); i++) deleteKey (list[i]); } // try catch (const ZException & exc) { setPath (oldPath); throw; } // catch setPath (oldPath); openPath (zFalse); RegDeleteKey ((HKEY) iPathHandle, aKeyName); #endif #ifdef ZC_OS2 if (iPath.size () && aKeyName.size ()) return *this; // no keys at this level openRoot (); if (!iPath.size () && !aKeyName.size ()) { // delete all applications: // will only do this if not the system- or user profile! if (iRootHandle == HINI_SYSTEMPROFILE || iRootHandle == HINI_USERPROFILE) return *this; ZStringlist apps; getKeys (apps); for (long i = 0; i < apps.count (); i++) if (!PrfWriteProfileString (iRootHandle, apps[i], 0, 0)) throwSysErr (PrfWriteProfileStringName); } else { if (!PrfWriteProfileString (iRootHandle, iPath.size ()? iPath : aKeyName, 0, 0)) throwSysErr (PrfWriteProfileStringName); } // if #endif return *this; } // deleteKey
ZExport0 ZPointerlist::~ZPointerlist() { ZFUNCTRACE_DEVELOP("ZPointerlist::~ZPointerlist()"); drop(); if (iList) delete [] iList; } // ~ZPointerlist
ZExport(ZSqlLink*) ZSqlLink::connect( const char* aDatabase, // db name (ORACLE, DB2, ...) const char* aConnection, // connection/datastore name const char* aUsername, // users name const char* aPassword, // user password int aMaxCursor) // cursor pool size { ZFUNCTRACE_DEVELOP("ZSqlLink::connect(const char*, const char*, const char*, const char*, int)"); #if ZC_WIN || ZC_OS2 #if ZC_IBM ZString dllName(ZString("Z")+aDatabase+"I"); #endif #if ZC_MICROSOFT ZString dllName(ZString("Z")+aDatabase+"M"); #endif #if ZC_BORLAND ZString dllName(ZString("Z")+aDatabase+"B"); #endif #if ZC_GNU ZString dllName(ZString("Z")+aDatabase+"G"); #endif dllName.lowerCase(); #endif // ZC_WIN || ZC_OS2 #if ZC_UNIXFAM ZString db(aDatabase); ZString dllName( ZString("libZ") +db.subString(1,1).upperCase() +db.subString(2).lowerCase() +"G.so." +ZString(ZC_MAJOR_VERSION) ); #endif // ZC_UNIXFAM // check if allready loaded Dll* d = dlls; while (d) { if (d->iName == dllName) break; d = d->iPrev; } // while if (!d) { ZDynamicLinkLibrary* dll = new ZDynamicLinkLibrary(dllName.constBuffer()); d = dlls = new Dll(dllName, dll, dlls); } // if ZSqlLink* (*connectTo)(const char*, const char*, const char*, int); connectTo = (ZSqlLink* (*)(const char*, const char*, const char*, int)) d->iDll->procAddress( #if ZC_WIN || ZC_OS2 #if ZC_IBM "ZSqlConnectTo__FPCcN21i" #endif #if ZC_BORLAND "@ZSqlConnectTo$qpxct1t1i" #endif #if ZC_MICROSOFT "?ZSqlConnectTo@@YAPAVZSqlLink@@PBD00H@Z" #endif #if ZC_GNU "ZSqlConnectTo__FPCcN21i" #endif #endif // ZC_WIN || ZC_OS2 #if ZC_UNIXFAM "ZSqlConnectTo__FPCcN20i" #endif // ZC_UNIXFAM ); return (*connectTo)(aConnection, aUsername, aPassword, aMaxCursor); } // connect
void ZCsl::checkNum (const ZString & aVal) { ZFUNCTRACE_DEVELOP ("ZCsl::checkNum(const ZString& aVal)"); if (!isNumber (aVal)) throwExcept (msgInvOpStrings, aVal); } // checkNum
ZExport (ZProfile &) ZProfile::setValue (const ZString & aValue, const ZString & aValueName, int aType) { ZFUNCTRACE_DEVELOP ("ZProfile::setValue(const ZString& aValue, const ZString& aValueName, int aType)"); // find out type if auto if (aType == Auto) { ZString v (aValue); if (ZString (v.strip ().asLong ()) == v) aType = Integer; else { if (aValue.isPrintable ()) aType = String; else aType = Binary; } // if } // if #ifdef ZC_WIN long dataType; switch (aType) { case String: dataType = 1; // String break; case Integer: return setValue (aValue.asLong (), aValueName); default: dataType = 3; // Binary } // switch openPath (zTrue); if (valueExists (aValueName)) deleteValue (aValueName); if (!RegSetValueEx ((HKEY) iPathHandle, aValueName, 0, dataType, (LPBYTE) (const char *) aValue, aValue.size ()) == ERROR_SUCCESS) throwSysErr (SRegSetValueEx); #endif #ifdef ZC_OS2 if (!iPath.size ()) ZTHROWEXC (MissingPath); if (!aValueName.size ()) ZTHROWEXC (MissingValueName); openRoot (); switch (aType) { case String: if (!PrfWriteProfileString (iRootHandle, iPath, aValueName, ZString::exp (aValue))) throwSysErr (PrfWriteProfileStringName); break; case Integer: { ZString v (aValue); if (!PrfWriteProfileString (iRootHandle, iPath, aValueName, ZString (v.strip ().asLong ()))) throwSysErr (PrfWriteProfileStringName); break; } // Integer default: { ZString val (aValue); if (!PrfWriteProfileData (iRootHandle, iPath, aValueName, (char *) val, val.size ())) throwSysErr (PrfWriteProfileDataName); } // default } // switch #endif return *this; } // setValue
ZExport (ZString) ZProfile::value (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::value(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); DWORD dataType, size; if (!RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, &dataType, NULL, &size) == ERROR_SUCCESS) ZTHROWEXC (ValueNotFound); if (size) { ZString str (0, size); RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, NULL, (LPBYTE) (char *) str, (LPDWORD) & size); switch (dataType) { case 1: // String case 2: // ExpandString case 7: // MultiString if (str.size () > 0 && str[str.size ()] == 0) return str.subString (1, str.size ()); default:; } // switch } // if #endif #ifdef ZC_OS2 if (!iPath.size ()) ZTHROWEXC (MissingPath); if (!aValueName.size ()) ZTHROWEXC (MissingValueName); openRoot (); // query size of data unsigned long size; if (!PrfQueryProfileSize (iRootHandle, iPath, aValueName, &size)) throwSysErr (PrfQueryProfileSizeName); if (size > 0) { ZString buf (0, size++); // try to get as string first PrfQueryProfileString (iRootHandle, iPath, aValueName, "", buf, size); ERRORID err = WinGetLastError (iHab); if (err == 0) { if (buf[buf.size ()] == 0 && buf.subString (1, buf.size () - 1).isPrintable ()) return buf.subString (1, buf.size () - 1); return buf; } // if if (ERRORIDERROR (err) != PMERR_INVALID_ASCIIZ) throwSysErr (PrfQueryProfileStringName); // try to get binary data if (!PrfQueryProfileData (iRootHandle, iPath, aValueName, buf, &size)) throwSysErr (PrfQueryProfileDataName); return buf; } // if #endif return ZString (); } // value
void ZCsl::interpret (Function * aFunc) { ZFUNCTRACE_DEVELOP ("ZCsl::interpret(Function* aFunc)"); ZException *excpt = 0; PackedInstruction *loAddr = aFunc->iPcode; PackedInstruction *hiAddr = loAddr + aFunc->iPsize - 1; PackedInstruction *i = loAddr; ZString v2; Variable *v; double d2; long i2; ZBoolean head (zTrue); while (zTrue) { try { if (iTraceMode & traceCode) { if (head) { trace ('#'); trace ('#', funcHeader (aFunc).constBuffer ()); trace ('#'); trace ('#', "address opcode parameter tos tos-1"); trace ('#', "-------- ------ -------------------- -------------------- --------------------"); head = zFalse; } // if trace ('#', dumpInstr (i - aFunc->iPcode, i, zTrue).constBuffer ()); } switch (i->iCode) { case cdOpen: aFunc->openBlock (i->iText); i++; break; case cdClose: aFunc->closeBlock (); i++; break; case cdSize: push (aFunc->findVar (pop ())->iSize); i++; break; case cdRSize: { ZString varName (pop ()); aFunc->findVar (pureVarName (varName))->resize (varName); i++; break; } case cdTrace: if (iTraceMode & traceMsgs) trace ('>', pop ().constBuffer ()); else pop (); i++; break; case cdExist: { ZString ret (One); try { Variable *var = aFunc->findVar (pop (), zFalse); if (!var || var->iIsExtern || var->iIndex < 0 || var->iIndex >= var->size ()) ret = Zero; } // try catch (const ZException & exc) { ret = Zero; } // catch push (ret); i++; break; } case cdNeg: checkNum (*iTos); *iTos = ZString (-iTos->asDouble ()); i++; break; case cdNot: if (isNumber (iTos->constBuffer ())) *iTos = iTos->asDouble ()? Zero : One; else *iTos = *iTos == "" ? One : Zero; i++; break; case cdLoad: *iTos = aFunc->findVar (*iTos)->value (); i++; break; case cdStore: { Variable *var = aFunc->findVar (pop ()); var->set (pop ()); i++; break; } case cdStorC: { Variable *var = aFunc->findVar (pop ()); var->set (pop (), zTrue); i++; break; } case cdPush: push (decodeString (i->iText)); i++; break; case cdPop: pop (); i++; break; case cdDupl: push (*iTos); i++; break; case cdDivI: i2 = pop ().asInt (); if (!i2) throwExcept (msgDivZero); checkNum (*iTos); *iTos = ZString (iTos->asInt () / i2); i++; break; case cdMod: i2 = pop ().asInt (); if (!i2) throwExcept (msgDivZero); checkNum (*iTos); *iTos = ZString (iTos->asInt () % i2); i++; break; case cdMul: v2 = pop (); checkNum (v2); checkNum (*iTos); *iTos = ZString (iTos->asDouble () * v2.asDouble ()); i++; break; case cdDiv: d2 = pop ().asDouble (); if (!d2) throwExcept (msgDivZero); checkNum (*iTos); *iTos = ZString (iTos->asDouble () / d2); i++; break; case cdAdd: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos += v2; else *iTos = ZString (iTos->asDouble () + v2.asDouble ()); i++; break; case cdSub: v2 = pop (); checkNum (v2); checkNum (*iTos); *iTos = ZString (iTos->asDouble () - v2.asDouble ()); i++; break; case cdCat: v2 = pop (); *iTos += v2; i++; break; case cdMulV: v = aFunc->findVar (pop ()); v2 = pop (); checkNum (v2); checkNum (v->value ()); v->set (v->value ().asDouble () * v2.asDouble ()); i++; break; case cdDivV: v = aFunc->findVar (pop ()); d2 = pop ().asDouble (); if (!d2) throwExcept (msgDivZero); checkNum (v->value ()); v->set (v->value ().asDouble () / d2); i++; break; case cdDivIV: v = aFunc->findVar (pop ()); i2 = pop ().asInt (); if (!i2) throwExcept (msgDivZero); checkNum (v->value ()); v->set (v->value ().asInt () / i2); i++; break; case cdModV: v = aFunc->findVar (pop ()); i2 = pop ().asInt (); if (!i2) throwExcept (msgDivZero); checkNum (v->value ()); v->set (v->value ().asInt () % i2); i++; break; case cdAddV: v = aFunc->findVar (pop ()); v2 = pop (); if (!isNumber (v->value ().constBuffer ()) || !isNumber (v2.constBuffer ())) v->set (v->value () + v2); else v->set (v->value ().asDouble () + v2.asDouble ()); i++; break; case cdSubV: v = aFunc->findVar (pop ()); v2 = pop (); checkNum (v2); checkNum (v->value ()); v->set (v->value ().asDouble () - v2.asDouble ()); i++; break; case cdCatV: v = aFunc->findVar (pop ()); v2 = pop (); v->set (v->value () + v2); i++; break; case cdIncV: v = aFunc->findVar (pop ()); checkNum (v->value ()); v->set (v->value ().asDouble () + 1.0); i++; break; case cdDecV: v = aFunc->findVar (pop ()); checkNum (v->value ()); v->set (v->value ().asDouble () - 1.0); i++; break; case cdLss: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = *iTos < v2 ? One : Zero; else *iTos = iTos->asDouble () < v2.asDouble ()? One : Zero; i++; break; case cdLeq: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = *iTos <= v2 ? One : Zero; else *iTos = iTos->asDouble () <= v2.asDouble ()? One : Zero; i++; break; case cdGtr: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = *iTos > v2 ? One : Zero; else *iTos = iTos->asDouble () > v2.asDouble ()? One : Zero; i++; break; case cdGeq: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = *iTos >= v2 ? One : Zero; else *iTos = iTos->asDouble () >= v2.asDouble ()? One : Zero; i++; break; case cdEql: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = *iTos == v2 ? One : Zero; else *iTos = iTos->asDouble () == v2.asDouble ()? One : Zero; i++; break; case cdNeq: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = *iTos != v2 ? One : Zero; else *iTos = iTos->asDouble () != v2.asDouble ()? One : Zero; i++; break; case cdAnd: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = (iTos->size () > 0 && v2.size () > 0) ? One : Zero; else *iTos = (iTos->asDouble () != 0.0 && v2.asDouble () != 0.0) ? One : Zero; i++; break; case cdOr: v2 = pop (); if (!isNumber (v2.constBuffer ()) || !isNumber (iTos->constBuffer ())) *iTos = (iTos->size () > 0 || v2.size () > 0) ? One : Zero; else *iTos = (iTos->asDouble () != 0.0 || v2.asDouble () != 0.0) ? One : Zero; i++; break; case cdJmp: i = loAddr + i->iAddr; break; case cdJF: { v2 = pop (); ZBoolean ok; if (isNumber (v2.constBuffer ())) ok = v2.asDouble () == 0.0; else ok = v2 == ""; i = ok ? loAddr + i->iAddr : i + 1; break; } case cdJT: { v2 = pop (); ZBoolean ok; if (isNumber (v2.constBuffer ())) ok = v2.asDouble () != 0.0; else ok = v2 != ""; i = ok ? loAddr + i->iAddr : i + 1; break; } case cdCall: exec ((Function *) i->iFunc); i++; head = zTrue; break; case cdRet: return; case cdTry: aFunc->iBlocks->iCatch = i->iAddr; aFunc->iBlocks->iTos = iTos; i++; break; case cdThrow: throw ZException (pop ()); case cdThroV: { v = aFunc->findVar (pop ()); int cnt (v->iSize); ZException exc (v->value ()); for (int i = 1; i < cnt; i++) exc.addAsLast (v->iVals[v->iIndex + i]); throw exc; } case cdAllTV: case cdAllTC: { if (!excpt) throw ZException (msgInvCatch); int cnt (excpt->count ()); Variable *var = aFunc->iBlocks->addVar (decodeString (i->iText) + "[" + ZString (cnt ? cnt : 1) + "]", "", i->iCode == cdAllTC); for (int c = 0; c < cnt; c++) var->iVals[c] = (*excpt)[c]; delete excpt; excpt = 0; i++; break; } case cdAllV: v2 = pop (); aFunc->iBlocks->addVar (v2, pop ()); i++; break; case cdAllC: v2 = pop (); aFunc->iBlocks->addVar (v2, pop (), zTrue); i++; break; case cdAllVR: v2 = pop (); aFunc->iBlocks->addVar (v2, pop (), zFalse, zTrue); i++; break; case cdAllCR: v2 = pop (); aFunc->iBlocks->addVar (v2, pop (), zTrue, zTrue); i++; break; case cdNop: i++; break; default: throwExcept (msgIllgInstr); } // switch if (i < loAddr || i > hiAddr) throwExcept (msgNoReturn); } // try catch (const ZException & exc) { while (aFunc->iBlocks->iPrev && aFunc->iBlocks->iCatch < 0) aFunc->closeBlock (); if (aFunc->iBlocks->iPrev) { i = loAddr + aFunc->iBlocks->iCatch; iTos = aFunc->iBlocks->iTos; aFunc->closeBlock (); if (excpt) delete excpt; excpt = new ZException (exc); } else throw; } // catch } // while } // interpret
ZString ZCsl::dumpInstr (long aAddr, PackedInstruction * aInstr, ZBoolean withStack) { ZFUNCTRACE_DEVELOP ("ZCsl::dumpInstr(long aAddr, PackedInstruction* aInstr, ZBoolean withStack)"); char *opcode; short param (0); switch (aInstr->iCode) { case cdOpen: opcode = "open"; param = 2; break; case cdClose: opcode = "close"; break; case cdSize: opcode = "size"; break; case cdRSize: opcode = "rsize"; break; case cdExist: opcode = "exist"; break; case cdNeg: opcode = "neg"; break; case cdNot: opcode = "not"; break; case cdLoad: opcode = "load"; break; case cdStore: opcode = "store"; break; case cdStorC: opcode = "storc"; break; case cdPush: opcode = "push"; param = 2; break; case cdPop: opcode = "pop"; break; case cdDupl: opcode = "dupl"; break; case cdDivI: opcode = "divi"; break; case cdMod: opcode = "mod"; break; case cdMul: opcode = "mul"; break; case cdDiv: opcode = "div"; break; case cdAdd: opcode = "add"; break; case cdSub: opcode = "sub"; break; case cdCat: opcode = "cat"; break; case cdMulV: opcode = "mulv"; break; case cdDivV: opcode = "divv"; break; case cdDivIV: opcode = "diviv"; break; case cdModV: opcode = "modv"; break; case cdAddV: opcode = "addv"; break; case cdSubV: opcode = "subv"; break; case cdCatV: opcode = "catv"; break; case cdIncV: opcode = "incv"; break; case cdDecV: opcode = "decv"; break; case cdLss: opcode = "lss"; break; case cdLeq: opcode = "leq"; break; case cdGtr: opcode = "gtr"; break; case cdGeq: opcode = "geq"; break; case cdEql: opcode = "eql"; break; case cdNeq: opcode = "neq"; break; case cdAnd: opcode = "and"; break; case cdOr: opcode = "or"; break; case cdJmp: opcode = "jmp"; param = 1; break; case cdJF: opcode = "jf"; param = 1; break; case cdJT: opcode = "jt"; param = 1; break; case cdCall: opcode = "call"; param = 3; break; case cdRet: opcode = "ret"; break; case cdTrace: opcode = "trace"; break; case cdTry: opcode = "try"; param = 1; break; case cdThrow: opcode = "throw"; break; case cdThroV: opcode = "throv"; break; case cdAllTV: opcode = "alltv"; param = 2; break; case cdAllTC: opcode = "alltc"; param = 2; break; case cdAllV: opcode = "allv"; break; case cdAllC: opcode = "allc"; break; case cdAllVR: opcode = "allvr"; break; case cdAllCR: opcode = "allcr"; break; case cdNop: opcode = "nop"; break; default: opcode = "????"; break; } // switch ZString pp; switch (param) { case 1: pp = ZString (aInstr->iAddr); break; case 2: pp = ZString::exp (aInstr->iText); break; case 3: pp = ((Function *) aInstr->iFunc)->iName; break; default:; } // switch char line[80]; if (withStack) { ZString tos (ZString::exp (*iTos)); ZString tos1; if (iTos > iStack) tos1 = ZString::exp (*(iTos - 1)); sprintf (line, "%8ld %-7.6s%-21.20s%-21.20s%-.20s", aAddr, opcode, (char *) pp, (char *) tos, (char *) tos1); } else sprintf (line, "%8ld %-7.6s%-.62s", aAddr, opcode, (char *) pp); return line; } // dumpInstr
static void closeHandle (HKEY aHandle) { ZFUNCTRACE_DEVELOP ("closeHandle(HKEY aHandle)"); if (!isSystemHandle (aHandle)) RegCloseKey (aHandle); } // closeHandle
ZExport0 ZProfile::~ZProfile () { ZFUNCTRACE_DEVELOP ("ZProfile::~ZProfile()"); closeRoot (); } // ~ZProfile