string AstVar::vlArgType(bool named, bool forReturn, bool forFunc) const {
    if (forReturn) named=false;
    if (forReturn) v3fatalSrc("verilator internal data is never passed as return, but as first argument");
    string arg;
    if (isWide() && isInOnly()) arg += "const ";
    AstBasicDType* bdtypep = basicp();
    bool strtype = bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::STRING;
    if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::CHARPTR) {
	arg += "const char*";
    } else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::SCOPEPTR) {
	arg += "const VerilatedScope*";
    } else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::DOUBLE) {
	arg += "double";
    } else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::FLOAT) {
	arg += "float";
    } else if (strtype) {
	if (isInOnly()) arg += "const ";
	arg += "string";
    } else if (widthMin() <= 8) {
	arg += "CData";
    } else if (widthMin() <= 16) {
	arg += "SData";
    } else if (widthMin() <= VL_WORDSIZE) {
	arg += "IData";
    } else if (isQuad()) {
	arg += "QData";
    } else if (isWide()) {
	arg += "WData";  // []'s added later
    }
    if (isWide() && !strtype) {
	arg += " (& "+name();
	arg += ")["+cvtToStr(widthWords())+"]";
    } else {
	if (forFunc && (isOutput() || (strtype && isInput()))) arg += "&";
	if (named) arg += " "+name();
    }
    return arg;
}
string AstVar::cPubArgType(bool named, bool forReturn) const {
    if (forReturn) named=false;
    string arg;
    if (isWide() && isInOnly()) arg += "const ";
    if (widthMin() == 1) {
	arg += "bool";
    } else if (widthMin() <= VL_WORDSIZE) {
	arg += "uint32_t";
    } else if (isWide()) {
	arg += "uint32_t";  // []'s added later
    } else {
	arg += "vluint64_t";
    }
    if (isWide()) {
	if (forReturn) v3error("Unsupported: Public functions with >64 bit outputs; make an output of a public task instead");
	arg += " (& "+name();
	arg += ")["+cvtToStr(widthWords())+"]";
    } else {
	if (isOutput() && !forReturn) arg += "&";
	if (named) arg += " "+name();
    }
    return arg;
}
void ICQClient::setAIMInfo(ICQUserData *data)
{
    if (getState() != Connected)
        return;
    bool bWide = isWide(data->FirstName.ptr) ||
                 isWide(data->LastName.ptr) ||
                 isWide(data->MiddleName.ptr) ||
                 isWide(data->Maiden.ptr) ||
                 isWide(data->Nick.ptr) ||
                 isWide(data->Zip.ptr) ||
                 isWide(data->Address.ptr) ||
                 isWide(data->City.ptr);
    string country;
    for (const ext_info *e = getCountryCodes(); e->szName; e++){
        if (e->nCode == data->Country.value){
            country = e->szName;
            break;
        }
    }
    snac(ICQ_SNACxFAM_LOCATION, ICQ_SNACxLOC_SETxDIRxINFO);
    string encoding = bWide ? "unicode-2-0" : "us-ascii";
    m_socket->writeBuffer.tlv(0x1C, encoding.c_str());
    m_socket->writeBuffer.tlv(0x0A, (unsigned short)0x01);
    encodeString(data->FirstName.ptr, 0x01, bWide);
    encodeString(data->LastName.ptr, 0x02, bWide);
    encodeString(data->MiddleName.ptr, 0x03, bWide);
    encodeString(data->Maiden.ptr, 0x04, bWide);
    encodeString(country.c_str(), 0x06, bWide);
    encodeString(data->Address.ptr, 0x07, bWide);
    encodeString(data->City.ptr, 0x08, bWide);
    encodeString(data->Nick.ptr, 0x0C, bWide);
    encodeString(data->Zip.ptr, 0x0D, bWide);
    encodeString(data->State.ptr, 0x21, bWide);
    sendPacket(false);

    ICQUserData *ownerData = &this->data.owner;
    set_str(&ownerData->FirstName.ptr, data->FirstName.ptr);
    set_str(&ownerData->LastName.ptr, data->LastName.ptr);
    set_str(&ownerData->MiddleName.ptr, data->MiddleName.ptr);
    set_str(&ownerData->Maiden.ptr, data->Maiden.ptr);
    set_str(&ownerData->Address.ptr, data->Address.ptr);
    set_str(&ownerData->City.ptr, data->City.ptr);
    set_str(&ownerData->Nick.ptr, data->Nick.ptr);
    set_str(&ownerData->Zip.ptr, data->Zip.ptr);
    set_str(&ownerData->State.ptr, data->State.ptr);
    ownerData->Country.value = data->Country.value;
}
void ICQClient::encodeString(const QString &m, const char *type, unsigned short charsetTlv, unsigned short infoTlv)
{
    bool bWide = isWide(m);
    string content_type = type;
    content_type += "; charset=\"";
    if (bWide){
        unsigned short *unicode = new unsigned short[m.length()];
        unsigned short *t = unicode;
        for (int i = 0; i < (int)(m.length()); i++)
            *(t++) = htons(m[i].unicode());
        content_type += "unicode-2\"";
        m_socket->writeBuffer.tlv(charsetTlv, content_type.c_str());
        m_socket->writeBuffer.tlv(infoTlv, (char*)unicode, (unsigned short)(m.length() * sizeof(unsigned short)));
        delete[] unicode;
    }else{
        content_type += "us-ascii\"";
        m_socket->writeBuffer.tlv(charsetTlv, content_type.c_str());
        m_socket->writeBuffer.tlv(infoTlv, m.latin1());
    }
}
string AstVar::vlEnumType() const {
    string arg;
    AstBasicDType* bdtypep = basicp();
    bool strtype = bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::STRING;
    if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::CHARPTR) {
	return "VLVT_PTR";
    } else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::SCOPEPTR) {
	return "VLVT_PTR";
    } else if (strtype) {
	arg += "VLVT_STRING";
    } else if (widthMin() <= 8) {
	arg += "VLVT_UINT8";
    } else if (widthMin() <= 16) {
	arg += "VLVT_UINT16";
    } else if (widthMin() <= VL_WORDSIZE) {
	arg += "VLVT_UINT32";
    } else if (isQuad()) {
	arg += "VLVT_UINT64";
    } else if (isWide()) {
	arg += "VLVT_WDATA";
    }
    // else return "VLVT_UNKNOWN"
    return arg;
}
static bool isWide(const char *text)
{
    if ((text == NULL) || (*text == 0))
        return false;
    return isWide(QString::fromUtf8(text));
}