void TableInfo::put(RecordType &rec, UINT n, const String &v) const {
  if(v.length() > m_columns[n].getMaxStringLen()) {
    throwSqlError(SQL_STRING_TOO_LONG,_T("%s:String too long to fit in keyfield[%d]. len=%d. maxlen=%d")
                                     ,__TFUNCTION__,n,(UINT)v.length(),m_columns[n].getMaxStringLen());
  }
  USES_CONVERSION;
  switch(getColumn(n).getType()) {
  case DBTYPE_CSTRING    :
  case DBTYPE_CSTRINGN   :
    { char tmp[MAXRECSIZE+1];
      memset(tmp,0,sizeof(tmp));
      strcpy(tmp,T2A((TCHAR*)v.cstr()));
      putBytes(rec,n,tmp);
    }
    break;
  case DBTYPE_WSTRING    :
  case DBTYPE_WSTRINGN   :
    { wchar_t tmp[MAXRECSIZE+1];
      memset(tmp,0,sizeof(tmp));
      wcscpy(tmp,T2W((TCHAR*)v.cstr()));
      putBytes(rec,n,tmp);
    }
    break;
  default: THROWFIELDNOTSTRING(n);
  }
}
BOOL CExpressionTreeDlg::OnInitDialog() {
  __super::OnInitDialog();

  m_treeCtrl.substituteControl(this, IDC_TREE_EXPRESSION);

  m_layoutManager.OnInitDialog(this);
  m_layoutManager.addControl(IDC_TREE_EXPRESSION  , RELATIVE_SIZE );
  m_layoutManager.addControl(IDCLOSE              , RELATIVE_X_POS);
  m_layoutManager.addControl(IDC_CHECKEXTENDEDINFO, RELATIVE_X_POS);
  m_layoutManager.addControl(IDC_LIST_SYMBOLTABLE , RELATIVE_Y_POS | RELATIVE_WIDTH);

  m_treeCtrl.showTree(m_node, m_extendedInfo);

  const String treeFormName = m_expr.getTreeFormName();
  const String stateName    = m_expr.getStateName();
  const int    nodeCount    = m_expr.getNodeCount();

  String title = getWindowText(this);
  title += format(_T(" - %s form - state %s. %d nodes")
                 ,treeFormName.cstr()
                 ,stateName.cstr()
                 ,nodeCount
                 );
  setWindowText(this, title);

  CListBox *lb = (CListBox*)GetDlgItem(IDC_LIST_SYMBOLTABLE);
  const ExpressionVariableArray variables = m_expr.getSymbolTable().getAllVariables();
  for(size_t i = 0; i < variables.size(); i++) {
    const ExpressionVariableWithValue &v = variables[i];
    lb->InsertString(-1, v.toString().cstr());
  }
  return TRUE;
}
Example #3
0
//-----------------------------------------
void HTTP::getAuthUserPass(char *user, char *pass)
{
	if (arg)
	{
		char *s = stristr(arg,"Basic");
		if (s)
		{
			while (*s)
				if (*s++ == ' ')
					break;
			String str;
			str.set(s,String::T_BASE64);
			str.convertTo(String::T_ASCII);
			s = strstr(str.cstr(),":");
			if (s)
			{
				*s = 0;
				if (user)
					strcpy(user,str.cstr());
				if (pass)
					strcpy(pass,s+1);
			}			
		}
	}
}
Example #4
0
intptr_t ShiftAnd::searchApprox(const String &str, UINT maxErrors) const {
  if (maxErrors == 0) {
    return search(str);
  }
  const UINT64         maskEnd  = m_s;
  CompactArray<UINT64> s;
  s.add(0,(UINT64)~1,maxErrors+1);
  UINT64 *sfirst = &s.first(), *slast = &s.last();
#ifdef _TEST_CLASS
  _tprintf(_T("m_s:%s\n"), sprintbin(maskEnd).cstr());
#endif
  for(const _TUCHAR *cp = str.cstr(), *last = cp + str.length(); cp < last;) {
    const UINT64 mask = m_mask[*cp++];
    UINT64      *sp   = sfirst, olds = *sfirst;
    *sp = (olds | mask) << 1;

    while(sp++ < slast) {
      const UINT64 tmp = *sp;
      /* Substitution is all we care about */
      *sp = (olds & (tmp | mask)) << 1;
      olds = tmp;
    }
#ifdef _TEST_CLASS
    for(sp = sfirst; sp <= slast; sp++) {
      _tprintf(_T("c:%c:%s\n"), *(cp-1), sprintbin(*sp).cstr());
    }
#endif
    if((*slast & maskEnd) == 0) {
      return cp - str.cstr() - m_patternLen;
    }
  }
  return -1;
}
Example #5
0
//------------------------------------------------------------------------------
//!
bool
FltValidator::validate
( const String& input )
{
   uint len;
   String input_nws = input.eatWhites();
   if( sscanf(input_nws.cstr(), "%lf%n", &_value, &len) == 1 )
   {
      if( len != input_nws.size() )
      {
         //Extra character(s)
         return false;
      }
      else
      if( _min <= _value && _value <= _max )
      {
         //Need to check format (reformat, and check that the value hasn't changed)
         double old_value = _value;
         String fmt;
         fmt.format("%%.%df", _frac);
         String tmp;
         tmp.format(fmt.cstr(), _value);
         sscanf(tmp.cstr(), "%lf", &_value);
         return _value == old_value;
      }
      else
      {
         return false;
      }
   }
   else
   {
      return false;
   }
}
Example #6
0
//-----------------------------
void	APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
{
	if (lastPlayID.isSet() && info && info->id.isSame(lastPlayID))
	{

		String tmp;
		tmp.append(info->track.artist);
		tmp.append(" ");
		tmp.append(info->track.title);


		if (!tmp.isSame(trackTitle))
		{
			if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
			{
				trackTitle=tmp;
				clearChannelPopup();
				channelPopup(info->name.cstr(),trackTitle.cstr());
			}
		} else if (!info->comment.isSame(channelComment))
		{
			if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
			{
				channelComment = info->comment;
				clearChannelPopup();
				channelPopup(info->name.cstr(),channelComment.cstr());
			}
		}



	}
}
Example #7
0
void CGridDlg::OnBnClickedButtonDiagram() {
  if(!validate()) return;

  windowToValue();
  const GridParameters v = getCurrentValue();
  PearlDiagram diagram;
  PixRect *tmp = v.calculateImage(getImage(), &diagram);
  SAFEDELETE(tmp);

  const String dumpFileName = createTempFileName(_T("txt"));
  FILE *f = NULL;
  try {
    const String dstr = diagram.toString();
    f = MKFOPEN(dumpFileName,_T("w"));

    _ftprintf(f, _T("%s"), dstr.cstr());
    fclose(f); f = NULL;

    ExternProcess::run(false, _T("c:\\windows\\system32\\notepad.exe"), dumpFileName.cstr(), NULL);
    UNLINK(dumpFileName);
  } catch (Exception e) {
    if(f) { fclose(f); f = NULL; }
    showException(e);
  }
}
unsigned __int64 Tokenizer::getUint64(bool hex) {
  String s = next();
  unsigned __int64 result;
  if(_stscanf(s.cstr(), hex ? _T("%I64x") : _T("%I64u"), &result) != 1) {
    throwException(_T("%s:Expected unsigned __int64:<%s>"), __TFUNCTION__, s.cstr());
  }
  return result;
}
UINT Tokenizer::getUint(bool hex) {
  String s = next();
  UINT result;
  if(_stscanf(s.cstr(), hex ? _T("%x") : _T("%lu"), &result) != 1) {
    throwException(_T("%s:Expected unsigned int:<%s>"), __TFUNCTION__, s.cstr());
  }
  return result;
}
Example #10
0
double Tokenizer::getDouble() {
  String s = next();
  double result;
  if(_stscanf(s.cstr(), _T("%le"), &result) != 1) {
    throwException(_T("%s:Expected double:<%s>"), __TFUNCTION__, s.cstr());
  }
  return result;
}
void StringSearcher::scan(const String &name) {
  if (m_verbose) {
    _ftprintf(stderr, _T("Scanning %-50s             \r"), name.cstr());
  }
  LexFileStream input(name);
  if(!input.ok()) {
    _tperror(name.cstr());
    return;
  }
  FindStringsLex lex;
  lex.newStream(&input);
//  lex.setDebug(true);
  bool lastWasDirective = false;
  InputToken sym;
  while (sym = (InputToken)lex.getNextLexeme()) {
    switch (sym) {
    case DIRECTIVE :
      lastWasDirective = true;
      break;
    case OLDSTRING :
      if(!lastWasDirective) {
        String         tmp = lex.getText();
        SourcePosition pos = lex.getStartPos(); pos.incrColumn();
        _tprintf(_T("%s%s: %s\n"), name.cstr(), pos.toString().cstr(), tmp.trim().cstr());
      }
      lastWasDirective = false;
      break;
    case OLDCHAR   :
      if(m_showOldStrings) {
        if(m_showOldChars) {
          if(!lastWasDirective) {
            String tmp = lex.getText();
            _tprintf(_T("%s%s: %s\n"), name.cstr(), lex.getPos().toString().cstr(), tmp.trim().cstr());
          }
        }
      }
      lastWasDirective = false;
      break;
    case NEWSTRING :
    case NEWCHAR   :
      lastWasDirective = false;
      break;
    case OTHER     :
      lastWasDirective = false;
      break;
    default:
      lastWasDirective = false;
      _ftprintf(stderr,_T("Unexpected symbol:%d\n"), sym);
    }
  }
}
Example #12
0
TableauCostFactors::TableauCostFactors(const String &str) {
  String copy(str);
  for(Tokenizer tok(copy.cstr(),_T(" ,\t\n\r")); tok.hasNext();) {
    String s = tok.next();
    double x;
    if(_stscanf(s.cstr(),_T("%le"),&x) != 1) {
      throwException(_T("TableauCostFactors:Illegal symbol <%s>. Expected number."),s.cstr());
    }
    add(x);
  }
  if(size() == 0) {
    throwException(_T("TableauConstraint:At least one coefficient expected"));
  }
}
Example #13
0
void Console::rectangle(int left, int top, int right, int bottom, FrameType type, WORD color) {
  const FrameChars &f = FrameChars::getFrameChars(type);
  String tmp = spaceString(right-left-1,f.m_horz);
  printf(left  , top   , color, _T("%c"), f.m_ul );
  printf(left+1, top   , color, _T("%s"), tmp.cstr());
  printf(right , top   , color, _T("%c"), f.m_ur );

  for(int y = top+1; y < bottom; y++) {
    printf(left , y, color, _T("%c"), f.m_vert);
    printf(right, y, color, _T("%c"), f.m_vert);
  }
  printf(left  , bottom, color, _T("%c"), f.m_ll );
  printf(left+1, bottom, color, _T("%s"), tmp.cstr());
  printf(right , bottom, color, _T("%c"), f.m_lr );
}
CWMPPlaylist MediaDatabase::createPlayList(const String &name) { // static
  if(name.equalsIgnoreCase(queueName)) {
    throwException(_T("Cannot use name of queue (=%s) as name for playlist"), queueName);
  }
  CWMPPlayer4           &player       = MediaDatabase::getPlayer();
  CWMPPlaylistCollection plCollection = player.GetPlaylistCollection();
  CWMPPlaylistArray      plArray      = plCollection.getByName(name.cstr());
  CWMPPlaylist           result;
  if(plArray.GetCount() > 0) {
    result = plArray.Item(0);
    result.clear();
  } else {
    result = plCollection.newPlaylist(name.cstr());
  }
  return result;
}
Example #15
0
void getEntriesAppend(const char *dirName,
		FileType t,
		List<String> &entries,
		const char *pattern)
{
	OGDF_ASSERT(isDirectory(dirName));

	String filePattern;
	filePattern.sprintf("%s\\%s", dirName, pattern);

	WIN32_FIND_DATA findData;
	HANDLE handle = FindFirstFile(filePattern.cstr(), &findData);

	if (handle != INVALID_HANDLE_VALUE)
	{
		do {
			DWORD isDir = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
			if(isDir && (
				strcmp(findData.cFileName,".") == 0 ||
				strcmp(findData.cFileName,"..") == 0)
			)
				continue;

			if (t == ftEntry || (t == ftFile && !isDir) ||
				(t == ftDirectory && isDir))
			{
				entries.pushBack(findData.cFileName);
			}
		} while(FindNextFile(handle, &findData));

		FindClose(handle);
	}
}
PixRectArray::PixRectArray(const StringArray &fileNames, StringArray &errors) {
  USES_CONVERSION;
  m_updateCounter = 0;
  for(size_t i = 0; i < fileNames.size(); i++) {
    const String &name = fileNames[i];
    try {
      if(FileNameSplitter(name).getExtension().equalsIgnoreCase(_T(".gif"))) {
        int error;
        const char *namea = T2A(name.cstr());
        GifFileType *gifFile = DGifOpenFileName(namea, &error);
        if(gifFile == NULL) {
          throwException(_T("%s"), GifErrorString(error));
        }
        if(DGifSlurp(gifFile) != GIF_OK) {
          const String msg = GifErrorString(gifFile->Error);
          DGifCloseFile(gifFile, &error);
          throwException(_T("%s"), msg.cstr());
        }
        const int imageCount   = gifFile->ImageCount;

        for(int k = 0; k < imageCount; k++) {
          add(new GifPixRect(gifFile, k));
        }
        DGifCloseFile(gifFile, &error);
      } else {
        add(GifPixRect::load(name));
      }
    } catch(Exception e) {
      errors.add(e.what());
    }
  }
}
Example #17
0
boolean String::endsWith(const String &suffix)
{
  if ( _length < suffix._length )
    return 0;

  return strcmp(&_array[_length-suffix._length], suffix.cstr()) == 0;
}
Example #18
0
//read all cluster tree information
bool GmlParser::clusterRead(GmlObject* rootCluster, 
							ClusterGraph& CG)
{

	//the root cluster is only allowed to hold child clusters and
	//nodes in a list

	if (rootCluster->m_valueType != gmlListBegin) return false;

	// read all clusters and nodes
	GmlObject *rootClusterSon = rootCluster->m_pFirstSon;

	for(; rootClusterSon; rootClusterSon = rootClusterSon->m_pBrother) 
	{
		switch(id(rootClusterSon)) 
		{
			case clusterPredefKey:
				{
					//we could delete this, but we aviod the call
					if (rootClusterSon->m_valueType != gmlListBegin) return false;
					// set attributes to default values
					//we currently do not set any values
					cluster c = CG.newCluster(CG.rootCluster());

					//recursively read cluster
					recursiveClusterRead(rootClusterSon, CG, c);

				} //case cluster
				break;
			case vertexPredefKey: //direct root vertices 
				{
					if (rootClusterSon->m_valueType != gmlStringValue) return false;
					String vIDString = rootClusterSon->m_stringValue;

					//we only allow a vertex id as string identification
					if ((vIDString[0] != 'v') &&
						(!isdigit(vIDString[0])))return false; //do not allow labels
					//if old style entry "v"i
					if (!isdigit(vIDString[0])) //should check prefix?
						vIDString[0] = '0'; //leading zero to allow conversion
					int vID = atoi(vIDString.cstr());

					OGDF_ASSERT(m_mapToNode[vID] != 0)

					//we assume that no node is already assigned ! Changed:
					//all new nodes are assigned to root
					//CG.reassignNode(mapToNode[vID], CG.rootCluster());
					//it seems that this may be unnessecary, TODO check
					CG.reassignNode(m_mapToNode[vID], CG.rootCluster());
					//char* vIDChar = new char[vIDString.length()+1];
					//for (int ind = 1; ind < vIDString.length(); ind++)
					//	vIDChar

				}//case vertex
		}//switch
	}//for all rootcluster sons

	return true;
				
}//clusterread
Example #19
0
// --------------------------------------------------
void ADDLOG(const char *str,int id,bool sel,void *data, LogBuffer::TYPE type)
{
	if (guiWnd)
	{

		String sjis; //JP-EX
		int num = SendDlgItemMessage(guiWnd, id,LB_GETCOUNT, 0, 0);
		if (num > 100)
		{
			SendDlgItemMessage(guiWnd, id, LB_DELETESTRING, 0, 0);
			num--;
		}
		sjis = str; //JP-Patch
		sjis.convertTo(String::T_SJIS); //JP-Patch
		//int idx = SendDlgItemMessage(guiWnd, id, LB_ADDSTRING, 0, (LONG)(LPSTR)str);
		int idx = SendDlgItemMessage(guiWnd, id, LB_ADDSTRING, 0, (LONG)(LPSTR)sjis.cstr());
		SendDlgItemMessage(guiWnd, id, LB_SETITEMDATA, idx, (LONG)data);

		if (sel)
			SendDlgItemMessage(guiWnd, id, LB_SETCURSEL, num, 0);

	}

	if (type != LogBuffer::T_NONE)
	{
#if _DEBUG
		OutputDebugString(str);
		OutputDebugString("\n");
#endif
	}

}
Example #20
0
void Tableau::traceDegeneracy(int pivotRow, int pivotColumn, const Real &minRatio) const {
  if(!isTracing(TRACE_WARNINGS)) {
    return;
  }
  const int constraintCount = getConstraintCount();
  String traceString;
  TCHAR *delimiter = EMPTYSTRING;
  for(int r = 1; r <= constraintCount; r++) {
    if(r == pivotRow) {
      continue;
    }
    const TableauRow &row = m_table[r];
    const Real       &ar  = row.m_a[pivotColumn];
    if(ar > EPS) {
      const Real ratio = row.getRightSide() / ar;
      if(ratio == minRatio) {
	    traceString += format(_T("%s%d"),delimiter,r);
        delimiter = _T(",");
      }
    }
  }
  if(traceString.length() > 0) {
    trace(_T("Degenerated rows:[%s]"),traceString.cstr());
  }
}
Example #21
0
static void throwAssertionException(_In_z_ _Printf_format_string_ const TCHAR *format, ...) {
  va_list argptr;
  va_start(argptr, format);
  const String msg = vformat(format,argptr);
  va_end(argptr);
  throwBigRealException(_T("assertIsValidBigReal:%s"), msg.cstr());
}
Example #22
0
void getEntriesAppend(const char *dirName,
	FileType t,
	List<String> &entries,
	const char *pattern)
{
	OGDF_ASSERT(isDirectory(dirName));

 	DIR* dir_p = opendir(dirName);

	dirent* dir_e;
	while ( (dir_e = readdir(dir_p)) != NULL )
	{
		const char *fname = dir_e->d_name;
		if (pattern != 0 && fnmatch(pattern,fname,0)) continue;

		String fullName;
		fullName.sprintf("%s/%s", dirName, fname);

		bool isDir = isDirectory(fullName.cstr());
		if(isDir && (
			strcmp(fname,".") == 0 ||
			strcmp(fname,"..") == 0)
			)
			continue;

		if (t == ftEntry || (t == ftFile && !isDir) ||
			(t == ftDirectory && isDir))
		{
			entries.pushBack(fname);
		}
	}

 	closedir(dir_p);
}
Example #23
0
void XMLDoc::checkLoad() {
  XMLParseErrorPtr pXMLError;
  LONG errorCode = E_FAIL;

  HRESULT hr=m_doc->get_parseError(&pXMLError);
  hr=pXMLError->get_errorCode(&errorCode);
  if(errorCode == S_OK) {
    m_doc->documentElement->normalize();
  } else {
    long line, linePos;
    LONG errorCode;
    BSTR pBURL, pBReason;
    HRESULT hr;

    hr=pXMLError->get_line(&line);
    hr=pXMLError->get_linepos(&linePos);
    hr=pXMLError->get_errorCode(&errorCode);
    hr=pXMLError->get_url(&pBURL);
    hr=pXMLError->get_reason(&pBReason);

    const String msg = format(_T("(%d,%d) : Error(%d) in XML:%s"), line, linePos, errorCode, BSTRToString(pBReason).cstr());

    SysFreeString(pBURL);
    SysFreeString(pBReason);
    throwException(_T("%s"), msg.cstr());
  }
}
Example #24
0
void XMLDoc::getValue(const XMLNodePtr &node, const TCHAR *tagName, double      &value, int instans) {
  String str;
  getValue(node,tagName,str,instans);
  if(_stscanf(str.cstr(),_T("%le"),&value) != 1) {
    throwNotNumericException(tagName, str);
  }
}
Example #25
0
void BitSet::throwIndexOutOfRange(const TCHAR *method, size_t index, _In_z_ _Printf_format_string_ TCHAR const * const format, ...) const {
  va_list argptr;
  va_start(argptr, format);
  const String msg = vformat(format, argptr);
  va_end(argptr);
  throwInvalidArgumentException(method, _T("%s:%s"), msg.cstr(), indexOutOfRangeString(index).cstr());
}
static void handleSingleFile(const String &fileName, FileNameHandler &nameHandler) {
  DirList list = scandir(fileName,SELECTALLBUTDOT,SORTDIRLASTALPHA);
  for(size_t i = 0; i < list.size(); i++) {
    DirListEntry &e = list[i];
    nameHandler.handleFileName(fileName.cstr(),e);
  }
}
Example #27
0
void Tableau::checkInvariant() const {
  const CompactArray<BasisVariable> bv = getBasisVariables();
  const int constraintCount = getConstraintCount();
  for(size_t row = 0; row < bv.size(); row++) {
    const BasisVariable &v       = bv[row];
    const int            col     = v.m_index;
    const String         varName = v.getName();
    if(getObjectFactor(col) != 0) {
      throwException(_T("%s is basic but objectFactor != 0 (=%le)"),varName.cstr(),getDouble(getObjectFactor(col)));
    }
    int count = 0;
    for(int i = 1; i <= constraintCount; i++) {
      const Real &a = m_table[i].m_a[col];
      if(a != 0) {
        count++;
        if(a != 1) {
          throwException(_T("Coefficient [%d][%d] != 1 (=%le) for basisVar %s"),i,col,a,varName.cstr());
        }
      }
    }
    if(count != 1) {
      throwException(_T("BasisVar %s has more than 1 coefficient != 0 in column %d"), varName.cstr(), col);
    }
  }
}
Example #28
0
boolean String::startsWith( const String &prefix, int offset )
{
  if ( offset > _length - prefix._length )
    return 0;

  return strncmp( &_array[offset], prefix.cstr(), prefix._length ) == 0;
}
Example #29
0
	bool String::compare(const String& str,const bool caseSensitive) const
	{
		if (length()!=str.length()) return false;

		if (caseSensitive) {
			for (unsigned long l=0;l<length();++l) {
				if (m_String->c_str()[l]!=str.cstr()[l]) return false;
			}
		} else {
			for (unsigned long l=0;l<length();++l) {
				if (toupper(m_String->c_str()[l])!=toupper(str.cstr()[l])) return false;
			}
		}

		return true;
	}
Example #30
0
void ShiftAnd::compile(const String &pattern, bool ignoreCase) {
  m_patternLen = (int)pattern.length();
  if(m_patternLen >= 64) {
    throwException(_T("<%s> too long for shiftand-search. max length is 63"), pattern.cstr());
  }
  memset(m_mask, -1, sizeof(m_mask));
  for(int i = 0; i < m_patternLen; i++) {
    const _TUCHAR ch = pattern[i];
    m_mask[ch] &= ~((UINT64)1 << i);
    if (ignoreCase) {
      if (_istlower(ch)) {
        m_mask[_toupper(ch)] &= ~((UINT64)1 << i);
      } else if(_istupper(ch)) {
        m_mask[_tolower(ch)] &= ~((UINT64)1 << i);
      }
    }
  }
  m_s = (UINT64)1 << m_patternLen;
#ifdef _TEST_CLASS
  for(int i = 0; i < ARRAYSIZE(m_mask); i++) {
    const UINT64 mask = m_mask[i];
    if(mask != -1) {
      _tprintf(_T("mask[%c]:%s\n"), i, sprintbin(mask).cstr());
    }
  }
#endif
}