示例#1
0
size_t widetoutf8(const wchar_t* input, size_t inputSize, char* target, size_t targetSize, int32_t* errors)
{
#if UTF8_WCHAR_UTF16
	return utf16toutf8((const utf16_t*)input, inputSize, target, targetSize, errors);
#elif UTF8_WCHAR_UTF32
	return utf32toutf8((const unicode_t*)input, inputSize, target, targetSize, errors);
#else
	return SIZE_MAX;
#endif
}
示例#2
0
文件: smb.c 项目: scolytus/gatling
static int smb_open(struct http_data* h,unsigned short* remotefilename,size_t fnlen,struct stat* ss,enum smb_open_todo todo) {
  char localfilename[1024];
  int64 fd;
  size_t i,j;
  char* x;
  if (ip_vhost(h)==-1 || fnlen/2>sizeof(localfilename))
    return -1;

  fd=-1;
  for (j=0; fd==-1 && j<2; ++j) {
    if (j==0) {
      /* first try latin1 */
      if (utf16tolatin1(localfilename,sizeof(localfilename),remotefilename,fnlen)==0)
	continue;
    } else {
      if (utf16toutf8(localfilename,sizeof(localfilename),remotefilename,fnlen)==0)
	break;
    }
#if 0
    {
      const char* what[] = {"OPEN","STAT","CHDIR"};
      printf("trying \"%s\" for %s\n",localfilename,what[todo]);
    }
#endif
    for (i=0; localfilename[i]; ++i) {
      if (localfilename[i]=='\\')
	localfilename[i]='/';
    }
    x=(char*)localfilename;
    while ((x=strstr(x,"/.")))
      x[1]=':';
    x=(char*)localfilename;
    while (*x=='/') ++x;
    if (todo==WANT_STAT) {
      if (*x==0) x=".";
      if (stat(x,ss)==0) {
	fd=0;
	break;
      }
    } else if (todo==WANT_OPEN) {
      if (*x==0) x=".";
      if (open_for_reading(&fd,x,ss))
	break;
    } else if (todo==WANT_CHDIR) {
      if (!*x || chdir(x)==0) {
	fd=0;
	break;
      }
    }
  }

  return fd;
}
示例#3
0
bool XmlSchema::generateCode(const Char* filename, const Char* pchFilename) const
{
	String headerCode, sourceCode;

	if (!generateCodeForNode(this, headerCode, sourceCode))
	{
		return false;
	}

	String note =
T("///////////////////////////////////////////////////////////////////////////////////////////////////\r\n\
//this file is automatically generated, do not modify.\r\n\
///////////////////////////////////////////////////////////////////////////////////////////////////\r\n");

	String definition = filename;
	int pos1 = definition.find_last_of(T('/'));
	int pos2 = definition.find_last_of(T('\\'));
	int slashPos = std::max(pos1 == String::npos ? -1: pos1,
								pos2 == String::npos ? -1: pos2);
	definition = definition.substr(slashPos + 1, definition.size() - slashPos - 1);
	String headerInclude;
	headerInclude += T("#ifndef __XML_");
	headerInclude += definition;
	headerInclude += T("_H__\r\n#define __XML_");
	headerInclude += definition;
	headerInclude += T("_H__\r\n\r\n#include \"SlimXml.h\"\r\n#include <vector>\r\n\r\n");
	String nameSpace;
	nameSpace = T("namespace ");
	nameSpace += definition;
	nameSpace += T("\r\n{\r\n");

	headerCode = note + headerInclude + nameSpace + headerCode;
	headerCode += T("}\r\n\r\n");
	headerCode += T("#endif\r\n");

	String sourceInclude;
	if (pchFilename != NULL)
	{
		sourceInclude += T("#include \"");
		sourceInclude += pchFilename;
		sourceInclude += T("\"\r\n");
	}
	sourceInclude += T("#include \"");
	sourceInclude += definition;
	sourceInclude += T(".h\"\r\n#include <cassert>\r\n\r\nusing namespace slim;\r\n\r\n");

	sourceCode = note + sourceInclude + nameSpace + sourceCode;
	sourceCode += T("}\r\n");

	assert(filename != NULL);

	String filenameString = filename;
	filenameString += T(".h");

	//header
	std::fstream file;
	file.open(filenameString.c_str(), std::ios_base::out | std::ios_base::binary);
	if (!file.is_open())
	{
		return false;
	}

#ifdef SLIM_USE_WCHAR
	//always write in utf-8
	unsigned char bom[3];
	bom[0] = 0xef;
	bom[1] = 0xbb;
	bom[2] = 0xbf;
	size_t bufferSize = headerCode.size() * 4;
	char* buffer = new char[bufferSize];
	size_t characterCount = utf16toutf8(headerCode.c_str(), headerCode.size(), buffer, bufferSize);
	file.write((char*)bom, 3);
	file.write(buffer, characterCount);
	delete[] buffer;
#else
	file.write(headerCode.c_str(), headerCode.size());
#endif

	file.close();

	//cpp
	filenameString = filename;
	filenameString += T(".cpp");
	file.open(filenameString.c_str(), std::ios_base::out | std::ios_base::binary);
	if (!file.is_open())
	{
		return false;
	}

#ifdef SLIM_USE_WCHAR
	bufferSize = sourceCode.size() * 3;
	buffer = new char[bufferSize];
	characterCount = utf16toutf8(sourceCode.c_str(), sourceCode.size(), buffer, bufferSize);
	file.write((char*)bom, 3);
	file.write(buffer, characterCount);
	delete[] buffer;
#else
	file.write(sourceCode.c_str(), sourceCode.size());
#endif

	file.close();
	return true;
}