Example #1
0
// Parses one line from the .m2i file.
// File pos must be after reading the initial status char
//
// <file type char>:<dosname>:<cbmname><cr><lf>
//
// at dosname 12 chars is written, at cbmname 16 chars
//
uchar M2I::parseLine(QString* dosName, QString* cbmName)
{
    if(m_hostFile.atEnd())
        return 0;  // no more records
    // ftype + fsName + cbmName + separators + LF
    QList<QByteArray> qData = m_hostFile.read(1 + 256 + 16 + 3 + 1).split(':');
    // must be three splits.
    if(qData.count() < 3)
        return 0;

    // first one ONLY the fs type.
    if(qData.at(0).count() not_eq 1)
        return 0;
    uchar fsType(qData.at(0).at(0));

    if(qData.at(1).isEmpty())
        return 0;
    if(0 not_eq dosName)
        *dosName = qData.at(1);

    // must be ending with a CR, the cbm string must be 16 chars long.
    if(!qData.at(2).endsWith("\r") or qData.at(2).length() not_eq 17)
        return 0;
    QString cbmStr(qData.at(2));
    cbmStr.chop(1);
    if(0 not_eq cbmName)
        *cbmName = cbmStr;

    return fsType;
} // parseLine
// Copy the return string without null terminator into outAddr_.
LmResult LmParameter::setOutChar(void *dataPtr,
	                	 const char *src,
				 ComUInt32 lengthInBytes)
{
  LmResult result = LM_OK;

#ifdef LANGMAN
  if (lengthInBytes > outSize_)
  {
    lengthInBytes = outSize_;
    result = LM_PARAM_OVERFLOW;
  }

  str_cpy_all((char*)dataPtr + outDataOffset(), src, (Lng32)lengthInBytes);

  // Copy length into varchar length indicator
  switch (outVCLenIndSize())
  {
    case 0:
      break;

    case 2:
      {
        ComUInt16 tempLen = (ComUInt16) lengthInBytes;
        memcpy((char*)dataPtr + outVCLenIndOffset(), &tempLen, sizeof(short));
        break;
      }
    case 4:
      memcpy((char*)dataPtr + outVCLenIndOffset(), &lengthInBytes,
             sizeof(Int32));
      break;

    default:
      LM_ASSERT1(0, "Unknown varchar indicator length.");
      break;
  }

  // Blank-pad FIXED char types.
  if (DFS2REC::isSQLFixedChar(fsType()))
  {
     if (outSize_ > lengthInBytes)
     {
       switch (encodingCharSet_)
       {
         case CharInfo::ISO88591 :
         case CharInfo::SJIS :
         case CharInfo::UTF8 :
           str_pad((char*)dataPtr + outDataOffset_ + lengthInBytes,
                   (Lng32)(outSize_ - lengthInBytes),
		   ' ');
           break;

         case CharInfo::UNICODE :
           wc_str_pad((NAWchar*)((char*)dataPtr + outDataOffset_ +
                                 lengthInBytes),
                      (Lng32)(outSize_ - lengthInBytes)/2,
                      unicode_char_set::space_char());
           break;

         default :
           char msg[256];
           sprintf(msg, "Unknown Character set value: %d", encodingCharSet_);
	   LM_ASSERT1(0, msg);
           break;
       }
     }
  }

#endif

  return result;
}