Пример #1
0
// Print a description of the token to f.
void JS::Token::print(Formatter &f, bool debug) const
{
    switch (getKind()) {
        case end:
            f << "[end]";
            break;

        case number:
            if (debug)
                f << "[number " << /* getValue() <<  */ ']';
            f << getChars();
            break;

        case unit:
            if (debug)
                f << "[unit]";
            /* no break */
        case string:
            quoteString(f, getChars(), '"');
            break;

        case regExp:
            f << '/' << getIdentifier() << '/' << getChars();
            break;

        case identifier:
            if (debug)
                f << "[identifier]";
            f << getIdentifier();
            break;

        default:
            f << getKind();
    }
}
Пример #2
0
void StoreClassTagMsg(jlong tag, char* classSign, boolean flushFl)
{
	int classDtlSize = getChars(CLASS_TAG) + (strlen(classSign) + getChars(tag) + 1 + 2 /*for '\0'*/) * sizeof(char);
	char* classDtlStr = createString(classDtlSize);
	sprintf(classDtlStr, "%d%c%s%c%ld", CLASS_TAG, MSGDELIMITER, classSign, MSGDELIMITER, tag);
	msgStore.includeMessage(classDtlStr, classDtlSize, flushFl);
}
Пример #3
0
void StoreObjectTag(jlong objectTag, jlong classTag, boolean flushFl)
{
	int totalSz = objectTagSize + getChars(objectTag) + getChars(classTag);
	char* objectTagStr = createString(totalSz);
	sprintf(objectTagStr, "%d%c%ld%c%ld", (int)OBJECT_TAG, MSGDELIMITER, (long)objectTag, MSGDELIMITER, (long)classTag);
	msgStore.includeMessage(objectTagStr, totalSz, flushFl);
}
Пример #4
0
void calculateSize()
{
	int heapMsgCodeLength = getChars(HEAP_REF_INFO);
	int objectTagMsgCodeLength = getChars(OBJECT_TAG);
	int freeTagMsgCodeLength = getChars(DEALLOCATE_OBJECT);

	heapRefDtlSize = heapMsgCodeLength + sizeof(char) * 8 + 1;
	objectTagSize = objectTagMsgCodeLength + 2 * sizeof(char) + 1;
	freeTagSize = freeTagMsgCodeLength + 1 * sizeof(char) + 1;
}
Пример #5
0
    vector<string> generatePalindromes(string s) {
        vector<string> ans;
        if (s.length() == 1) ans.push_back(s); 
        if (s.length() <= 1) return ans;

        const int SIZE = 256;
        int ct[SIZE] = {0}, len = s.length();
        for (int i = 0; i < len; ++ i) ++ ct[s[i]];

        // count number of each char, 
        // and get the index of the char of odd occurrence.
        int odd = 0, odd_index = 0;
        for (int i = 0; i < SIZE; ++ i) {
            if (ct[i] & 1) {
                odd ++;
                odd_index = i;
            }
        }
        
        // iff can have palindromes, get such strings.
        if (((len & 1 == 1) && odd == 1) || (odd == 0)) {
            vector<int> nums = getChars(ct, SIZE); // get half of the chars.
            sort(nums.begin(), nums.end());
            
            do {
                ans.push_back(getPalindrome(nums, len & 1 == 1, odd_index));
            } while (nextPermutation(nums));
        }
        
        return ans;
    }
Пример #6
0
template <> ColumnPtr ColumnConst<String>::convertToFullColumn() const
{
    if (!data_type || typeid_cast<const DataTypeString *>(&*data_type))
    {
        auto res = std::make_shared<ColumnString>();
        ColumnString::Offsets_t & offsets = res->getOffsets();
        ColumnString::Chars_t & vec = res->getChars();

        size_t string_size = data.size() + 1;
        size_t offset = 0;
        offsets.resize(s);
        vec.resize(s * string_size);

        for (size_t i = 0; i < s; ++i)
        {
            memcpy(&vec[offset], data.data(), string_size);
            offset += string_size;
            offsets[i] = offset;
        }

        return res;
    }
    else if (const DataTypeFixedString * type = typeid_cast<const DataTypeFixedString *>(&*data_type))
    {
        size_t n = type->getN();

        if (data.size() > n)
            throw Exception("Too long value for " + type->getName(), ErrorCodes::TOO_LARGE_STRING_SIZE);

        auto res = std::make_shared<ColumnFixedString>(n);
        ColumnFixedString::Chars_t & vec = res->getChars();

        vec.resize_fill(n * s);
        size_t offset = 0;

        for (size_t i = 0; i < s; ++i)
        {
            memcpy(&vec[offset], data.data(), data.size());
            offset += n;
        }

        return res;
    }
    else
        throw Exception("Invalid data type in ColumnConstString: " + data_type->getName(), ErrorCodes::LOGICAL_ERROR);
}
void onCheckSocketError(int status, char* action)
{
	static const int constStrLen = 42;
	if (status != 0)
	{
		int err = WSAGetLastError();
		char* errMsg = (char *)allocateMemory(strlen(action) + getChars(err) + 42);
		sprintf(errMsg, "Error during %s. Winsock error Reference: %d", action, err);
		jvmFunctions.onFatalError(errMsg);
	}
}
Пример #8
0
 void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t) override
 {
     const ColumnPtr column = block.getByPosition(arguments[0]).column;
     if (const ColumnString * col = checkAndGetColumn<ColumnString>(column.get()))
     {
         auto col_res = ColumnString::create();
         ReverseImpl::vector(col->getChars(), col->getOffsets(), col_res->getChars(), col_res->getOffsets());
         block.getByPosition(result).column = std::move(col_res);
     }
     else if (const ColumnFixedString * col = checkAndGetColumn<ColumnFixedString>(column.get()))
     {
         auto col_res = ColumnFixedString::create(col->getN());
         ReverseImpl::vector_fixed(col->getChars(), col->getN(), col_res->getChars());
         block.getByPosition(result).column = std::move(col_res);
     }
     else
         throw Exception(
             "Illegal column " + block.getByPosition(arguments[0]).column->getName() + " of argument of function " + getName(),
             ErrorCodes::ILLEGAL_COLUMN);
 }
int onCleanSocket(int status)
{
	if (status > LISTENING)
	{
		int size = getChars(AGENT_EXIT) + 1;
		char* msgStr = (void*)allocateMemory(size);
		memset(msgStr, 0x0, size);
		sprintf(msgStr, "%d", AGENT_EXIT);
		onSendMessage(&msgStr, &size); // Introduce helper methods and it is to be moved there
		int err = closesocket(clientSocket);
		if (err == SOCKET_ERROR)
			return CLIENT_SOCKET_CLEANUP;
	}
	if (status > IDLE)
	{
		int err = closesocket(listenSocket);
		if (err == SOCKET_ERROR)
			return LISTEN_SOCKET_CLEANUP;
	}
	return NONE;
}
Пример #10
0
	void execute(Block & block, const ColumnNumbers & arguments, size_t result) override
	{
		const ColumnWithTypeAndName & arg_from = block.unsafeGetByPosition(arguments[0]);
		const ColumnWithTypeAndName & arg_charset_from = block.unsafeGetByPosition(arguments[1]);
		const ColumnWithTypeAndName & arg_charset_to = block.unsafeGetByPosition(arguments[2]);
		ColumnWithTypeAndName & res = block.unsafeGetByPosition(result);

		const ColumnConstString * col_charset_from = typeid_cast<const ColumnConstString *>(arg_charset_from.column.get());
		const ColumnConstString * col_charset_to = typeid_cast<const ColumnConstString *>(arg_charset_to.column.get());

		if (!col_charset_from || !col_charset_to)
			throw Exception("2nd and 3rd arguments of function " + getName() + " (source charset and destination charset) must be constant strings.",
				ErrorCodes::ILLEGAL_COLUMN);

		String charset_from = col_charset_from->getData();
		String charset_to = col_charset_to->getData();

		if (const ColumnString * col_from = typeid_cast<const ColumnString *>(arg_from.column.get()))
		{
			auto col_to = std::make_shared<ColumnString>();
			convert(charset_from, charset_to, col_from->getChars(), col_from->getOffsets(), col_to->getChars(), col_to->getOffsets());
			res.column = col_to;
		}
		else if (const ColumnConstString * col_from = typeid_cast<const ColumnConstString *>(arg_from.column.get()))
		{
			auto full_column_holder = col_from->cloneResized(1)->convertToFullColumnIfConst();
			const ColumnString * col_from_full = static_cast<const ColumnString *>(full_column_holder.get());

			auto col_to_full = std::make_shared<ColumnString>();
			convert(charset_from, charset_to, col_from_full->getChars(), col_from_full->getOffsets(), col_to_full->getChars(), col_to_full->getOffsets());

			res.column = std::make_shared<ColumnConstString>(col_from->size(), (*col_to_full)[0].get<String>(), res.type);
		}
		else
			throw Exception("Illegal column passed as first argument of function " + getName() + " (must be ColumnString).",
				ErrorCodes::ILLEGAL_COLUMN);
	}
Пример #11
0
  e->RELEASE_CHARS(path, chars);
}

extern "C" JNIEXPORT jstring JNICALL
Java_java_io_File_toCanonicalPath(JNIEnv* /*e*/, jclass, jstring path)
{
  // todo
  return path;
}

extern "C" JNIEXPORT jstring JNICALL
Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path)
{
#ifdef PLATFORM_WINDOWS
# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  string_t chars = getChars(e, path);
  if (chars) {
    const unsigned BufferSize = MAX_PATH;
    char_t buffer[BufferSize];
    DWORD success = GetFullPathNameW(chars, BufferSize, buffer, 0);
    releaseChars(e, path, chars);

    if (success) {
      return e->NewString
        (reinterpret_cast<const jchar*>(buffer), wcslen(buffer));
    }
  }

  return path;
# else
  string_t chars = getChars(e, path);
Пример #12
0
void test() {
	use(getChars().x);
}
Пример #13
0
String MD5Builder::toString(void){
  char out[32];
  getChars(out);
  return String(out);
}
Пример #14
0
static int attrsOk(XmlBuffer * xb, const XmlElement * e, XmlAttr * r,
                   const char *tag, int etag)
{
   unsigned int n;
   char *ptr, wa[32];
   char msg1[] = { "Unknown attribute in list for " };
   char msg2[] = { "Bad attribute list for " };
   char word[32];

   for (n = 0; (e + n)->attr; n++)
      wa[n] = 0;

   xb->eTagFound = 0;
   for (skipWS(xb); isalpha(*xb->cur); skipWS(xb)) {
//      for (n=0; n < a.size(); n++) {
      for (n = 0; (e + n)->attr; n++) {
         if (wa[n] == 1)
            continue;
         if (getWord(xb, (e + n)->attr, 0)) {
            if (!isalnum(*xb->cur)) {
               skipWS(xb);
               if (getChar(xb, '=')) {
                  (r + n)->attr = getValue(xb, (e + n)->attr);
                  wa[n] = 1;
                  goto ok;
               }
               else
                  Throw(xb, "'=' expected in attribute list");
            }
         }
      }
      strncpy(word, xb->cur, 10);
      word[10] = 0;
      ptr = (char *) alloca(strlen(tag) + strlen(msg1) + 8 + 20);
      strcpy(ptr, msg1);
      strcat(ptr, tag);
      strcat(ptr, " (");
      strcat(ptr, word);
      strcat(ptr, ")");
      Throw(xb, ptr);
    ok:;
   }

   if (getChars(xb, "/>")) {
      xb->eTagFound = 1;
      xb->etag = etag;
      return 1;
   }

   else if (getChar(xb, '>'))
      return 1;

   else if (getChars(xb, "?>") && strcmp(tag, "?xml") == 0) {
      xb->eTagFound = 1;
      xb->etag = etag;
      return 1;
   }

   ptr = (char *) alloca(strlen(tag) + strlen(msg2) + 96);
   strcpy(ptr, msg2);
   strcat(ptr, tag);
   strcat(ptr, ": ");
   strncpy(word, xb->cur, 30);
   word[30]=0;
   strcat(ptr, word);
   strcat(ptr," ");
   strcat(ptr, tag);
   Throw(xb, ptr);
   return -1;
}