ZExport (void) ZDateTime::setFormat (int aFormat) { ZFUNCTRACE_DEVELOP ("ZDateTime::setFormat(int aFormat)"); if (aFormat < 0 || aFormat > 2) ZTHROWEXC ("Invalid format (" + ZString (aFormat) + ")"); iFormat = aFormat; } // setFormat
ZExport(ZPointerlist&) ZPointerlist::addAtPos(long aIndex, void* aPointer) { ZFUNCTRACE_DEVELOP("ZPointerlist::addAtPos(long aIndex, void* aPointer"); if (aIndex > iCount || aIndex < 0) ZTHROWEXC("Invalid index"); if (iCount == iSize) { iSize = iSize ? iSize+iSize : 10; ZTRACE_DEVELOP("iSize "+ZString(iSize)); void** newList = new void*[iSize]; long i = 0; while (i < aIndex) { newList[i] = iList[i]; i++; } // while newList[i++] = aPointer; while (i <= iCount) { newList[i] = iList[i-1]; i++; } // while if (iList) delete [] iList; iList = newList; } else { for (long i = iCount; i > aIndex; i--) iList[i] = iList[i-1]; iList[aIndex] = aPointer; } // if iCount++; return *this; } // addAtPos
ZExport (int) ZProfile::valueType (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::valueType(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); DWORD dataType; if (!RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, &dataType, NULL, NULL) == ERROR_SUCCESS) ZTHROWEXC (ValueNotFound); switch (dataType) { case 1: // String case 2: // ExpandString return String; case 3: // Binary case 7: // MultiString return Binary; case 4: // DWord case 5: // DWordBigEndian return Integer; default:; } // switch return Other; #endif #ifdef ZC_OS2 ZString val (value (aValueName)); if (ZString (val.asLong ()) == val) return Integer; if (val.isPrintable ()) return String; return Binary; #endif } // valueType
ZExport0 ZRegularExpression::ZRegularExpression (const ZString & aExpression, int aOpenFlags) { ZFUNCTRACE_DEVELOP ("ZRegularExpression::ZRegularExpression(const ZString& aExpression, int aOpenFlags)"); iHandle = new regex_t; int cflags (0); if (aOpenFlags & openExtended) cflags |= REG_EXTENDED; if (aOpenFlags & openIgnorecase) cflags |= REG_ICASE; if (aOpenFlags & openNewline) cflags |= REG_NEWLINE; if (aOpenFlags & openNosubreps) cflags |= REG_NOSUB; int err = regcomp ((regex_t *) iHandle, aExpression.constBuffer (), cflags); if (err) { char msg[80]; regerror (err, (regex_t *) iHandle, msg, sizeof (msg)); regfree ((regex_t *) iHandle); delete (regex_t *) iHandle; iHandle = 0; ZTHROWEXC (msg); } // if } // ZRegularExpression
ZExport (ZDateTime &) ZDateTime::setDay (int aDay) { ZFUNCTRACE_DEVELOP ("ZDateTime::setDay(int aDay)"); if (aDay < 1 || aDay > 31) ZTHROWEXC ("Invalid day (" + ZString (aDay) + ")"); iDay = aDay; return *this; } // setDay
ZExport (ZDateTime &) ZDateTime::setMonth (int aMonth) { ZFUNCTRACE_DEVELOP ("ZDateTime::setMonth(int aMonth)"); if (aMonth < 1 || aMonth > 12) ZTHROWEXC ("Invalid month (" + ZString (aMonth) + ")"); iMonth = aMonth; return *this; } // setMonth
ZExport (ZDateTime &) ZDateTime::setSecond (int aSecond) { ZFUNCTRACE_DEVELOP ("ZDateTime::setSecond(int aSecond)"); if (aSecond < 0 || aSecond > 59) ZTHROWEXC ("Invalid month (" + ZString (aSecond) + ")"); iSecond = aSecond; return *this; } // setSecond
ZExport (ZDateTime &) ZDateTime::setMinute (int aMinute) { ZFUNCTRACE_DEVELOP ("ZDateTime::setMinute(int aMinute)"); if (aMinute < 0 || aMinute > 59) ZTHROWEXC ("Invalid month (" + ZString (aMinute) + ")"); iMinute = aMinute; return *this; } // setMinute
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 (ZDateTime &) ZDateTime::setHour (int aHour) { ZFUNCTRACE_DEVELOP ("ZDateTime::setHour(int aHour)"); if (aHour < 0 || aHour > 23) ZTHROWEXC ("Invalid hour (" + ZString (aHour) + ")"); iHour = aHour; return *this; } // setHour
ZExport(void*) ZPointerlist::operator[](long aIndex) const { ZFUNCTRACE_DEVELOP("ZPointerlist::operator[](long aIndex) const"); ZTRACE_DEVELOP("aIndex "+ZString(aIndex)); if (aIndex >= iCount || aIndex < 0) ZTHROWEXC("Invalid index"); return iList[aIndex]; } // operator[]
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
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(ZPointerlist&) ZPointerlist::removeFromPos(long aIndex) { ZFUNCTRACE_DEVELOP("ZPointerlist::removeFromPos(long aIndex)"); if (aIndex >= iCount || aIndex < 0) ZTHROWEXC("Invalid index"); del(iList[aIndex]); for (long i = aIndex+1; i < iCount; i++) iList[i-1] = iList[i]; iCount--; return *this; } // ZPointerlist::removeFromPos
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
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
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 (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