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);
  }
}
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;
}
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;
}
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;
}
Example #5
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 );
}
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());
    }
  }
}
void CChangeOrderDlg::insertMediaFileIntoListBox(size_t pos, const MediaFile &f) {
  CListBox *lb = getListBox();
  String tmp = format(_T("%-38.38s%-36.36s%-36.36s")
                     ,f.getTitle()
                     ,f.getArtist()
                     ,f.getAlbum()
                     );
  int ret = lb->InsertString((int)pos, tmp.cstr());
}
Example #8
0
SOCKET tcpOpen(unsigned short portnr, const char *hostName) {
  SOCKET      s = INVALID_SOCKET;
  SOCKADDR_IN remoteAddr;
  IN_ADDR     RemoteIpAddress;
  INT         err;
  INT         bufferSize = 2048;

  s = socket (AF_INET, SOCK_STREAM, 0);
  if(s == INVALID_SOCKET) {
    throwLastWSAErrorText();
  }
  try {
    err = setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&bufferSize, sizeof(bufferSize));
    if(err == SOCKET_ERROR) {
      throwLastWSAErrorText();
    }

    err = setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&bufferSize, sizeof(bufferSize));
    if(err == SOCKET_ERROR) {
      throwLastWSAErrorText();
    }

    RemoteIpAddress.s_addr = htonl(INADDR_LOOPBACK);

    if(hostName != NULL) {
      PHOSTENT host = gethostbyname(hostName);
      if(host) {
        memcpy(&RemoteIpAddress.s_addr,host->h_addr,host->h_length);
      } else {
        RemoteIpAddress.s_addr = inet_addr(hostName); /* perhaps 999.999.999.999 */
        if(RemoteIpAddress.s_addr == INADDR_NONE) {
          String strHostName = hostName;
          throw TcpException(format(_T("Unknown host:%s"), strHostName.cstr()).cstr());
        }
      }
    }

    ZeroMemory(&remoteAddr, sizeof(remoteAddr));

    remoteAddr.sin_family = AF_INET;
    remoteAddr.sin_port   = htons(portnr);
    remoteAddr.sin_addr   = RemoteIpAddress;

    err = connect(s, (PSOCKADDR) &remoteAddr, sizeof(remoteAddr));
    if(err == SOCKET_ERROR) {
      throwLastWSAErrorText();
    }
    return s;
  } catch(...) {
    if(s != INVALID_SOCKET) {
      closesocket(s);
    }
    throw;
  }
}
Example #9
0
GrammarSymbol::GrammarSymbol(int index, const String &name, SymbolType type, int precedence, const SourcePosition &pos, long terminalCount) : m_first1(terminalCount) {
  if(type == NONTERMINAL && terminalCount == 0) {
    throwException(_T("Cannot add nonterminal <%s> when terminalCount == 0"), name.cstr());
  }

  m_index         = index;
  m_name          = name;
  m_type          = type;
  m_precedence    = precedence;
  m_reachable     = false;
  m_terminate     = false;
  m_deriveEpsilon = false;
  m_pos           = pos;

}
void GrammarParser::parseTermDef() {
  SymbolType type;
  switch(m_token) {
  case TERM    : type = TERMINAL           ; break;
  case LEFT    : type = LEFTASSOC_TERMINAL ; m_currentPrecedence++; break;
  case RIGHT   : type = RIGHTASSOC_TERMINAL; m_currentPrecedence++; break;
  case NONASSOC: type = NONASSOC_TERMINAL  ; m_currentPrecedence++; break;
  }

  while(next() == NAME) {
    String name = m_lex.getText();
    bool ok = true;
    if(m_grammar.findSymbol(name) >= 0) {
      m_lex.error(_T("Terminal %s already defined."), name.cstr());
      ok = false;
    }
    if(ok) {
      m_grammar.addTerminal(name, type, m_currentPrecedence, m_lex.getSourcePos());
    }
  }
}
Example #11
0
bool Database::searchDbName(const String &dbName, SysTableDbData &dbdef) {
  if(dbName.length() > SQLAPI_MAXDBNAME) {
    throwSqlError(SQL_DBNAME_TOO_LONG,_T("Database name <%s> too long"),dbName.cstr());
  }

  if(!DbFile::exist(SYSTEM_DBDATA_FNAME)) {
    return false;
  }

  DataFile dataFile(  SYSTEM_DBDATA_FNAME, DBFMODE_READONLY, NULL);
  KeyFile  indexFile( SYSTEM_DBKEY_FNAME,  DBFMODE_READONLY, NULL);
  KeyType  key;

  KeyFileDefinition keydef(indexFile);
  keydef.put(key, 0, toUpperCase(dbName));

  if(!indexFile.searchMin(RELOP_EQ, key, 1)) {
    return false;
  }

  dataFile.readRecord(keydef.getRecordAddr(key), &dbdef, sizeof(SysTableDbData));
  return true;
}
Example #12
0
void Database::sysTabDbDelete(const String &dbName) {
  LogFile logFile(SYSTEM_DBLOG_FNAME);
  KeyType key;

  DataFile dataFile( SYSTEM_DBDATA_FNAME, DBFMODE_READWRITE, &logFile);
  KeyFile  indexFile(SYSTEM_DBKEY_FNAME,  DBFMODE_READWRITE, &logFile);

  KeyFileDefinition keydef(indexFile);
  keydef.put(key, 0, toUpperCase(dbName));

  if(!indexFile.searchMin(RELOP_EQ, key, 1)) {
    throwSqlError(SQL_DB_NOT_EXIST,_T("Database <%s> doesn't exist"),dbName.cstr());
  }

  logFile.begin();
  try {
    dataFile.remove(keydef.getRecordAddr(key));
    indexFile.remove(key);
  } catch(sqlca) {
    logFile.abort();
    throw;
  }
  logFile.commit();
}
void GrammarParser::parseRightSide(int leftSide) {
  Production prod(leftSide, m_lex.getSourcePos());
  while(m_token == NAME) {
    const String         name = m_lex.getText();
    const SourcePosition pos  = m_lex.getSourcePos();

    next();
    const SymbolModifier modifier   = parseModifier();
    int rightIndex = m_grammar.findSymbol(name);
    if(rightIndex < 0) {
      rightIndex = m_grammar.addNonTerminal(name, pos);
    } else if(m_grammar.isTerminal(rightIndex)) {
      prod.m_precedence = m_grammar.getSymbol(rightIndex).m_precedence;
    }
    prod.m_rightSide.add(RightSideSymbol(rightIndex, modifier));
  }
  if(m_token == PREC) { // %prec specifier
    next();
    switch(m_token) {
    case NUMBER:
      { prod.m_precedence = (short)m_lex.getNumber();
        next();
      }
      break;

    case NAME:
      { const String name = m_lex.getText();
        next();
        int tokenIndex = m_grammar.findSymbol(name);
        bool ok = true;
        if(tokenIndex < 0) {
          m_lex.error(_T("Unknown symbol in %%prec-clause:%s."), name.cstr());
          ok = false;
        } else if(!m_grammar.isTerminal(tokenIndex)) {
          m_lex.error(_T("Symbol %s must be terminal in %%prec-clause."), name.cstr());
          ok = false;
        }
        if(ok) {
          prod.m_precedence = m_grammar.getSymbol(tokenIndex).m_precedence;
        }
      }
      break;

    default:
      m_lex.error(_T("Expected NAME of NUMBER."));
    }
  }

  if(m_token == LCURL) {
    const SourcePosition sourcePos = m_lex.getSourcePos();
    CompactShortArray usedDollar;
    m_actionBody = EMPTYSTRING;
    m_lex.collectBegin();
    next();
    parseActionBody(sourcePos, usedDollar, prod);
    if(m_token != RCURL) {
      m_lex.error(_T("Expected '}'."));
    } else {
      next();
    }
    m_lex.collectEnd();
    SourceText tmp;
    m_lex.getCollected(tmp);
    prod.m_actionBody.m_sourceText = trim(m_actionBody + tmp.m_sourceText);
    prod.m_actionBody.m_pos        = SourcePositionWithName(m_lex.getAbsoluteFileName(), sourcePos);
/*
    printf("body:<%s> at line %d\n",
      prod.m_actionBody.m_sourceText.cstr(),
      prod.m_actionBody.m_lineno);
*/
  }

  m_grammar.addProduction(prod);
}
void GrammarParser::parseProduction() { // m_token == NAME (=leftside of production)
  const String leftName = m_lex.getText();
  int leftIndex = m_grammar.findSymbol(leftName);
  if(leftIndex >= 0) {
    const GrammarSymbol &sym = m_grammar.getSymbol(leftIndex);
    if(sym.m_type != NONTERMINAL) {
      m_lex.error(_T("Symbol %s is a terminal and cannot be on the leftside of a production."), leftName.cstr());
    }
  } else {
    leftIndex = m_grammar.addNonTerminal(leftName, m_lex.getSourcePos());
  }
  next();
  if(m_token != COLON) {
    m_lex.error(_T("Expected ':'."));
  } else {
    next();
  }
  for(bool rightSideDone = false; !rightSideDone;) {
    parseRightSide(leftIndex);
    switch(m_token) {
    case BAR:
      next();
      break;

    case SEMI:
      rightSideDone = true;
      next();
      break;

    case EOI:
      m_lex.error(_T("Unexpected EOI."));
      rightSideDone = true;

    default:
      m_lex.error(_T("Unexpected symbol:'%s'."), m_lex.getText().cstr());
      next();
      break;

    }
  }
}
Example #15
0
CZoomDlg::CZoomDlg(const String &s1, const String &s2, CWnd *pParent) : m_s1(s1), m_s2(s2), CDialog(CZoomDlg::IDD, pParent) {
  m_lines = format(_T("%s\r\n%s"), s1.cstr(), s2.cstr()).cstr();
  m_ignorecase = FALSE;
}
Example #16
0
Tokenizer::Tokenizer(const String &str, const String &delimiters, TCHAR textQualifier, int flags) : m_delimiterSet(MAXCHARVALUE) {
  init(str.cstr(), delimiters.cstr(), textQualifier, flags);
}
Example #17
0
CSize getTextExtent(HDC hdc, const String &s) {
  CSize size;
  GetTextExtentPoint32(hdc, s.cstr(),(int)s.length(), &size);
  return size;
}
TableCursorKey::TableCursorKey(const KeyFileDefinition &keydef, const Tuple *keytuple, UINT fieldCount, RelationType relop) : m_keydef(keydef) {
  m_fieldCount = fieldCount;
  m_key.init();
  m_relop = relop;
  if(relop == RELOP_FALSE || relop == RELOP_TRUE) return;
  if(relop == RELOP_NQ) {
    m_relop = RELOP_TRUE;
    m_fieldCount = 0;
    return;
  }
  if(fieldCount == 0) {
    return;
  }
  if(keytuple == NULL) {
    throwSqlError(SQL_FATAL_ERROR,_T("TableCursorKey:No Tuple specified but field = %d"),fieldCount);
  }
  const Tuple &tuple = *keytuple;
  if(fieldCount > tuple.size()) {
    throwSqlError(SQL_FATAL_ERROR,_T("TableCursorKey:invalid fieldCount (=%d) specified. Tuple.size = %zd")
                                 ,fieldCount,tuple.size());
  }
  for(UINT i = 0; i < fieldCount; i++) {
    DbFieldType tupleType = tuple[i].getType();
    DbFieldType keyType = keydef.getFieldDef(i).getType();

    if(!isCompatibleType(keyType,tupleType)) {
       throwSqlError(SQL_TYPEMISMATCH,_T("Incompatible types in keydefinition(%s) and tupledefinition(%s)")
                     ,getTypeString(keyType)
                     ,getTypeString(tupleType));
    }

    const TupleField &tupField = tuple[i];
    switch(getMainType(tupleType)) {
    case MAINTYPE_NUMERIC :
      { if(!tupField.isDefined()) {
          setUndefinedField(i);
          return;
        }
        double d;
        tupField.get(d);
        if(putField(i,d)) return;
        break;
      }

    case MAINTYPE_STRING  :
      { if(!tupField.isDefined()) {
          setUndefinedField(i);
          return;
        }
        String str;
        tupField.get(str);
        switch(getMainType(keyType)) {
        case MAINTYPE_STRING:
          if(putField(i,str)) return;
          break;
        case MAINTYPE_VARCHAR:
          { varchar vch(str.cstr());
            if(putField(i,vch)) return;
          }
        }
      }
      break;

    case MAINTYPE_VARCHAR :
      { if(!tupField.isDefined()) {
          setUndefinedField(i);
          return;
        }
        varchar vch;
        tupField.get(vch);

        switch(getMainType(keyType)) {
        case MAINTYPE_STRING:
          { String    str((TCHAR*)vch.data());
            if(putField(i,str)) return;
            break;
          }
        case MAINTYPE_VARCHAR:
          if(putField(i,vch)) return;
          break;
        }
      }
      break;

    case MAINTYPE_DATE    :
      { if(!tupField.isDefined()) {
          setUndefinedField(i);
          return;
        }
        Date d;
        tupField.get(d);
        keydef.put(m_key, i, d);
      }
      break;

    case MAINTYPE_TIME    :
      { if(!tupField.isDefined()) {
          setUndefinedField(i);
          return;
        }
        Time d;
        tupField.get(d);
        keydef.put(m_key, i, d);
      }
      break;

    case MAINTYPE_TIMESTAMP:
      { if(!tupField.isDefined()) {
          setUndefinedField(i);
          return;
        }
        Timestamp d;
        tupField.get(d);
        keydef.put(m_key, i, d);
      }
      break;

    default:
      throwSqlError(SQL_FATAL_ERROR,_T("TableCursorKey:Invalid DbMainType :%d")
                                   ,getMainType(tupleType));
      break;
    }
  }
}
Example #19
0
bool Tokenizer::getBool() { // expect "true" or "false"
  String s = next();
  return strToBool(s.cstr());
}
Example #20
0
void setWindowText(CWnd *wnd, const String &str) {
  wnd->SetWindowText(str.cstr());
}
    void testTokenizer(int testid, const TCHAR *str, TCHAR *del, TCHAR tq, int flags, ...) {
      va_list argptr;
      Array<String> expected;
      TCHAR *ex;
      for (va_start(argptr, flags), ex = va_arg(argptr, TCHAR*); ex; ex = va_arg(argptr, TCHAR*)) {
        expected.add(ex);
      }

      size_t i = 0;

      Tokenizer assignTok(str, del, tq, flags);

      for (Tokenizer tok(str, del, tq, flags); tok.hasNext(); i++) {
        assignTok = tok;
        Tokenizer copyConstTok(tok);
        const String nextStr = tok.next();
        const String assignStr = assignTok.next();
        const String copyConstStr = copyConstTok.next();

        if (i >= expected.size()) {
          OUTPUT(_T("Test %d. Too many field in String(%s). expected %d. got %s number %d\n"), testid, str, expected.size(), nextStr.cstr(), i);
          verify(false);
        }
        else {
          if (nextStr != expected[i]) {
            OUTPUT(_T("Test %d. Wrong field in String(%s). field %d =<%s>. expected <%s>\n"), testid, str, i, nextStr.cstr(), expected[i].cstr());
            verify(false);
          }
          if (assignStr != nextStr) {
            OUTPUT(_T("Test %d. Wrong field in assignStr(%s). field %d =<%s>. expected <%s>\n"), testid, str, i, assignStr.cstr(), expected[i].cstr());
            verify(false);
          }
          if (copyConstStr != nextStr) {
            OUTPUT(_T("Test %d. Wrong field in copyConstStr(%s). field %d =<%s>. expected <%s>\n"), testid, str, i, copyConstStr.cstr(), expected[i].cstr());
            verify(false);
          }
        }
        if (assignTok.hasNext() != tok.hasNext()) {
          OUTPUT(_T("Test %d. assignTok.hasNext()(=%s) != tok.hasNext()(=%s)\n"), testid, boolToStr(assignTok.hasNext()), boolToStr(tok.hasNext()));
          verify(false);
        }
        if (copyConstTok.hasNext() != tok.hasNext()) {
          OUTPUT(_T("Test %d. copyConstStr.hasNext()(=%s) != tok.hasNext()(=%s)\n"), testid, boolToStr(copyConstTok.hasNext()), boolToStr(tok.hasNext()));
          verify(false);
        }
      }
      if (i != expected.size()) {
        OUTPUT(_T("Test %d. Too few fields in String(%s). Got %d expected %d\n"), testid, str, i, expected.size());
        verify(false);
      }
    }
void ResourceChecker::checkResources(const String &fileName) {
#ifdef DUMPSYMBOLS
  FILE *log = NULL;
#endif

  try {

#ifdef DUMPSYMBOLS
    log = MKFOPEN(_T("c:\\temp\\checkMnemonics.txt"), _T("w"));
#endif
    if (m_verbose) {
      _ftprintf(stderr, _T("Analyzing %s                                                      \r"), fileName.cstr());
    }
    ResourceFile rf(fileName);
    if(!rf.isOk()) {
      rf.listErrors();
      m_ok = false;
    }
    if(!rf.isEmpty()) {

#ifdef DUMPSYMBOLS
      _ftprintf(log, _T("%s\n"), rf.toString().cstr());
#endif
      rf.analyze();
      if(!rf.isOk()) {
        rf.listErrors();
        m_ok = false;
      }
    }

#ifdef DUMPSYMBOLS
    fclose(log);
#endif

  } catch(Exception e) {
#ifdef DUMPSYMBOLS
    if(log) {
      fclose(log);
    }
#endif
    _tprintf(_T("Exception:%s\n"), e.what());
    m_ok = false;
  }
}
Example #23
0
	void String::Splice(int index, int remove_num, const String & str){
		Splice(index, remove_num, str.cstr(), str.num());
	}