void IntlParametersBlock::processParametersBlock(ProcessString* processString, ClumpletWriter& pb)
{
	const char* tagName = NULL;
	try
	{
		for (pb.rewind(); !pb.isEof(); )
		{
			UCHAR tag = pb.getClumpTag();
			string s;

			tagName = NULL;
			switch (checkTag(tag, &tagName))
			{
			case TAG_SKIP:
				pb.moveNext();
				break;

			case TAG_STRING:
				pb.getString(s);
				processString(s);
				pb.deleteClumplet();
				pb.insertString(tag, s);
				break;

			case TAG_COMMAND_LINE:
				pb.getString(s);
				processCommandLine(processString, s);
				pb.deleteClumplet();
				pb.insertString(tag, s);
				break;
			}
		}
	}
	catch (const Firebird::status_exception& st)
	{
		LocalStatus ls;
		CheckStatusWrapper l(&ls);
		st.stuffException(&l);
		if ((l.getState() & IStatus::STATE_ERRORS) && (l.getErrors()[1] == isc_bad_conn_str) && tagName)
		{
			Arg::Gds newErrors(isc_intl_char);
			newErrors << tagName;

			const ISC_STATUS* errors = l.getErrors();
			newErrors << Arg::StatusVector(errors + 2);		// skip isc_bad_conn_str

			l.setErrors(newErrors.value());
			status_exception::raise(&l);
		}

		// other case leave exception as is
		throw;
	}
}
//--------------------------------------------------------------
// move current working directory up tree until file is found
void mgOSFindWD(
  const char* fileName)
{
  WCHAR* oldCWD = _wgetcwd(NULL, 0);
  if (oldCWD == NULL)
    throw new mgException("unable to get _getcwd");
  mgString cwd(oldCWD);
  //mgDebug("CWD is %s", (const char*) cwd);

  BOOL changed = false;
  while (true)
  {
    mgString name;
    if (cwd.endsWith("\\"))
      name.format("%s%s", (const char*) cwd, fileName);
    else name.format("%s\\%s", (const char*) cwd, fileName);

    WCHAR* wideName;
    int wideLen;
    name.toWCHAR(wideName, wideLen);
    struct _stat filestat;
    BOOL found = 0 == _wstat(wideName, &filestat);
    delete wideName; wideName = NULL;

    if (found)
    {
//      mgDebug("found %s", (const char*) name);
      break;
    }
    else
    {
      // remove last directory from cwd
      int slash = cwd.reverseFind(cwd.length(), '\\');
      if (slash != -1)
      {
        cwd.deleteAt(slash, cwd.length()-slash);
        changed = true;
      }
      else 
      {
        // no more directories. file not found.
        mgString start(oldCWD);
        throw new mgException("mgOSFindWD cannot find %s from %s", 
          (const char*) fileName, (const char*) start);
      }
    }
  }

  // set the new working directory
  if (changed)
  {
    // move errors.txt to new location
    WCHAR* wideOld;
    int lenOld;
    mgString oldErrors(oldCWD);
    oldErrors += "\\errors.txt";
    oldErrors.toWCHAR(wideOld, lenOld);

    mgString newErrors(cwd);
    newErrors += "\\errors.txt";
    WCHAR* wideNew;
    int lenNew;
    newErrors.toWCHAR(wideNew, lenNew);
    MoveFileEx(wideOld, wideNew, MOVEFILE_REPLACE_EXISTING);

    delete wideOld; wideOld = NULL;
    delete wideNew; wideNew = NULL;

    if (0 != _chdir(cwd))
      throw new mgException("unable to _chdir(%s)", (const char*) cwd);
  }
  free(oldCWD); oldCWD = NULL;
}