Пример #1
0
void WebAppServer::handleConnection(QtWebRequest * request, QtWebResponse * response)
{
    qDebug() << QThread::currentThread() << "handleConnection";

    qDebug() << request->requestPath();
    qDebug() << request->get();


    // Don't forget to have static-files in your output dir or at least a link of it
    if ( request->requestPath() == "/static/styles.css" ) {
        response->serveStaticFile(realPath(QDir::currentPath()) + "static-files", "/static", request);
    }
    else {
        QByteArray body("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"/static/styles.css\"></head>"
                        "<body><h1>Hello</h1></body></html>");

        response->setStatus(QtWebResponse::StatusCode::OK, "OK");
        response->write(body);
        response->end();
    }
}
Пример #2
0
// Load all equipment packs from a certain folder
void CEquipmentManager::LoadEquipmentPacksFromPath(const char* path)
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Equipment Packs");

	ICryPak * pCryPak = gEnv->pCryPak;
	_finddata_t fd;
	string realPath (path);
	realPath.TrimRight("/\\");
	string search (realPath);
	search += "/*.xml";

	intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd );
	if (handle != -1)
	{
		do
		{
			// fd.name contains the profile name
			string filename = path;
			filename += "/" ;
			filename += fd.name;
			
			MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "EquipmentPack XML (%s)", filename.c_str());

			XmlNodeRef rootNode = gEnv->pSystem->LoadXmlFromFile(filename.c_str());

			// load from XML node
			const bool ok = rootNode ? LoadEquipmentPack(rootNode) : false;
			if (!ok)
			{
				GameWarning("[EquipmentMgr]: Cannot load XML file '%s'. Skipping.", filename.c_str());
			}
		} while ( pCryPak->FindNext( handle, &fd ) >= 0 );

		pCryPak->FindClose( handle );
	}
}
Пример #3
0
QStringList KStandardDirs::resourceDirs(const char *type) const
{
    QStringList *candidates = dircache.find(type);

    if (!candidates) { // filling cache
        if (strcmp(type, "socket") == 0)
           const_cast<KStandardDirs *>(this)->createSpecialResource(type);
        else if (strcmp(type, "tmp") == 0)
           const_cast<KStandardDirs *>(this)->createSpecialResource(type);
        else if (strcmp(type, "cache") == 0)
           const_cast<KStandardDirs *>(this)->createSpecialResource(type);

        QDir testdir;

        candidates = new QStringList();
        QStringList *dirs;

        bool restrictionActive = false;
        if (d && d->restrictionsActive)
        {
           if (d->dataRestrictionActive)
              restrictionActive = true;
           else if (d->restrictions["all"])
              restrictionActive = true;
           else if (d->restrictions[type])
              restrictionActive = true;
           d->dataRestrictionActive = false; // Reset
        }

        dirs = relatives.find(type);
        if (dirs)
        {
            bool local = true;
            const QStringList *prefixList = 0;
            if (strncmp(type, "xdgdata-", 8) == 0)
                prefixList = &(d->xdgdata_prefixes);
            else if (strncmp(type, "xdgconf-", 8) == 0)
                prefixList = &(d->xdgconf_prefixes);
            else
                prefixList = &prefixes;

            for (QStringList::ConstIterator pit = prefixList->begin();
                 pit != prefixList->end();
                 ++pit)
            {
                for (QStringList::ConstIterator it = dirs->begin();
                     it != dirs->end(); ++it) {
                    QString path = realPath(*pit + *it);
                    testdir.setPath(path);
                    if (local && restrictionActive)
                       continue;
                    if ((local || testdir.exists()) && !candidates->contains(path))
                        candidates->append(path);
                }
                local = false;
            }
        }
        dirs = absolutes.find(type);
        if (dirs)
            for (QStringList::ConstIterator it = dirs->begin();
                 it != dirs->end(); ++it)
            {
                testdir.setPath(*it);
                if (testdir.exists())
                {
                    QString filename = realPath(*it);
                    if (!candidates->contains(filename))
                        candidates->append(filename);
                }
            }
        dircache.insert(type, candidates);
    }

#if 0
    kdDebug() << "found dirs for resource " << type << ":" << endl;
    for (QStringList::ConstIterator pit = candidates->begin();
	 pit != candidates->end();
	 pit++)
    {
	fprintf(stderr, "%s\n", (*pit).latin1());
    }
#endif


  return *candidates;
}
Пример #4
0
DynamicLib::DynamicLib(const boost::filesystem::path& path) :
    m_name(path),
    m_handle(0)
{

    std::string actualDllName = path.string();
    //std::string::size_type pos = actualDllName.find_last_of(".");

    boost::filesystem::path realPath(actualDllName, boost::filesystem::native);

    boost::filesystem::path currentDirectory(boost::filesystem::initial_path());

    std::string fullPath = boost::filesystem::system_complete(realPath).string();

#ifdef WIN32
    // First, try to get the handle without loading the library.
    // If we can get a handle then it is already loaded.
    HMODULE mod = GetModuleHandle(fullPath.c_str());
    if( mod )
    {
        //std::string error = std::string("ERROR: Plugin ") +
        //    std::string(fullPath.c_str()) + std::string(" is already loaded.");
        //throw UnableToLoadDynamicLibException(error);
        m_handle = mod;
        return;
    }

    m_handle = LoadLibrary(fullPath.c_str());
    if( !m_handle )
    {
        std::stringstream str;
        str << "ERROR loading dll " << fullPath << " ";
        switch(GetLastError())
        {
        case ERROR_MOD_NOT_FOUND:
            str << "The specified DLL could not be found ";
            str << "(" << (long)ERROR_MOD_NOT_FOUND << ").";
            str << "A common reason for this is if the plugin has an implicit ";
            str << "DLL requirement that can't be found.";
            break;

        case ERROR_INVALID_MODULETYPE:
            str << "The operating system cannot run the specified module ";
            str << "(" << (long)ERROR_INVALID_MODULETYPE << ").";
            break;

        case ERROR_TOO_MANY_MODULES:
            str << "Too many dynamic-link modules are attached to this program or dynamic-link module ";
            str << "(" << (long)ERROR_TOO_MANY_MODULES << ").";
            break;

        case ERROR_DLL_INIT_FAILED:
            str << "Dynamic link library (DLL) initialization routine failed ";
            str << "(" << (long)ERROR_DLL_INIT_FAILED << ").";
            break;

        case ERROR_DLL_NOT_FOUND:
            str << "The library file cannot be found ";
            str << "(" << (long)ERROR_DLL_NOT_FOUND << ").";
            break;

        case ERROR_INVALID_DLL:
            str << "The library file is damaged ";
            str << "(" << (long)ERROR_INVALID_DLL << ").";
            break;

        default:
            str << "\tERROR NUMBER = " << GetLastError();
            break;
        }
        throw UnableToLoadDynamicLibException(str.str());
    }
#else

    m_handle = dlopen(actualDllName.c_str(), RTLD_LAZY | RTLD_GLOBAL);
    if( !m_handle )
    {
        cerr << dlerror() << endl;
        throw std::runtime_error("Can't load.");
    }

#endif

}
Пример #5
0
std::string  CompilerFactory::application_path(const std::string &exec_param)
{
  FUNCTION_TRACE;

  std::string exe_param=System::appendExecSuffix(std::string(exec_param));
  std::string  file_path;

  int slash_count=0;
  int i;
  int lg=exe_param.length();
  for (i=0;i<lg;i++)
    if (exe_param[i]==FILE_SEPARATOR_CHAR || exe_param[i]==FILE_SEPARATOR_CHAR_BIS) 
      slash_count++;

  if ( slash_count>0 )
  { /* absolute of relative path */
    file_path=exe_param; 
  }
  else 
  {
    struct stat info;
#if defined(OS_WIN32)
    if (stat(exe_param.c_str(),&info)==0)
    { /* file exists */
      file_path=exe_param; 
    }
    else
#endif
    {
      char *path = getenv( "PATH" );
      if (!path)
      {
        FATAL1("System variable PATH not defined");
      }
      int path_lg=strlen(path);
      int pos1,pos2;
      DEBUG2("getenv(PATH)=%s\n", path);
      for (pos1=0,pos2=0;pos2<path_lg;pos2++)
      {
        if ( (path[pos2]==PATH_SEPARATOR_CHAR) || (pos2==path_lg-1) )
        {
          char *p;

          p=(char*)MALLOC((pos2-pos1+1+1+lg)*sizeof(char));
          memcpy(p,&path[pos1],pos2-pos1);
          if (p[pos2-pos1-1]!=FILE_SEPARATOR_CHAR && p[pos2-pos1-1]!=FILE_SEPARATOR_CHAR_BIS)
          {
            p[pos2-pos1]=FILE_SEPARATOR_CHAR ;
            p[pos2-pos1+1]='\0';
          }
          else
            p[pos2-pos1]='\0';
          strcat(p,exe_param.c_str());
          pos1=pos2+1;
          if (stat(p,&info)==0)
          { /* file exists */
            file_path=std::string(p); 
            break;
          }
          FREE(p);
        }
      }
    }
  }

  if (file_path.empty())
    file_path=exe_param;

  char resolved_file_path[MAX_PATH];
  realPath(file_path.c_str(),resolved_file_path);

  return std::string(resolved_file_path);
}
Пример #6
0
void CompilerFactory::extract_tool_name (const std::string &input, std::string &tool_name,bool suppress_exe_extension,bool &inactive)
{
  FUNCTION_TRACE;
  std::string tool_path;
  {
    std::string appli_path=CompilerFactory::application_path(input.c_str());
    char file_abs[MAX_PATH];
    if (realPath(appli_path.c_str(),file_abs)!=NULL)
      appli_path=std::string(file_abs);
    int lg=appli_path.length();
    int i;
    int pos=-1;
    inactive=false;
    for (i=lg-1;i>=0;i--)
    {
      if (appli_path[i]==FILE_SEPARATOR_CHAR || appli_path[i]==FILE_SEPARATOR_CHAR_BIS)
      {
        pos=i;
        break;
      }
    }
    if (pos!=-1)
      tool_path=appli_path.substr(0,pos+1);
  }

  int i;
  int pos=-1;
  inactive=false;
  int lg=input.length();
  for (i=lg;i>=0;i--)
  {
    if (input[i]==FILE_SEPARATOR_CHAR || input[i]==FILE_SEPARATOR_CHAR_BIS)
    {
      pos=i;
      break;
    }
  }
  int input_pos_lg=strlen(&input[pos+1]);
  DEBUG5("input=%s tool_name=%s pos=%i input_pos_lg=%i\n",input.c_str(),tool_name.c_str(),pos,input_pos_lg);
  bool found=false;
  if (strncasecmp(&(input.c_str())[pos+1],"cs",2)==0)
  {
    tool_name=input.substr(pos+3);
    found=profile_existing(tool_name,tool_path.c_str());
    DEBUG3("tool_name=%s profile_existing=%s\n",tool_name.c_str(),(found?"true":"false"));
  }
  if (!found && (input_pos_lg>3 && strncasecmp(&(input.c_str())[pos+1+input_pos_lg-3],"-cs",3)==0))
  {
    tool_name= input.substr(pos+1);
    tool_name= tool_name.substr(0,tool_name.length()-3);
    found=profile_existing(tool_name,tool_path);
    DEBUG3("tool_name=%s profile_existing=%s\n",tool_name.c_str(),(found?"true":"false"));
  }
  if (!found && (input_pos_lg>7 && strncasecmp(&(input.c_str())[pos+1+input_pos_lg-7],"-cs.exe",7)==0))
  {
    tool_name= input.substr(pos+1);
    tool_name= tool_name.substr(0,tool_name.length()-7);
    tool_name+=".exe";
    found=profile_existing(tool_name,tool_path.c_str());
    DEBUG3("tool_name=%s profile_existing=%s\n",tool_name.c_str(),(found?"true":"false"));
  }
  if (!found)
  {
    inactive=true;
    tool_name= input.substr(pos+1);
    DEBUG2("tool_name (%s) not found\n",tool_name.c_str());
  }

  if (suppress_exe_extension)
  { /*suppression of .exe extension */
    tool_name=System::suppressExecSuffix(tool_name);
    DEBUG2("tool_name=%s\n",tool_name.c_str());
  }
  DEBUG2("tool_name=%s\n",tool_name.c_str());
}
Пример #7
0
void CsLibGen::save_source(const char *filename, const CompilerInterface &compiler_wrapper,const char *default_csexe,bool lock_csexe)
{
  FUNCTION_TRACE;
  int i;
  FILE *f;
  char signature_str[CHAINE_LEN];
  char tmp[CHAINE_LEN];
  char indexstr[CHAINE_LEN];
  char *default_csexe_escaped=NULL;
  if (default_csexe)
  {
    default_csexe_escaped = (char*)MALLOC(strlen(default_csexe)*2+1) ;
    escape(default_csexe,default_csexe_escaped);
  }
  DEBUG1("==== begin generating __cs_libgen.cs source code ====\n");

  if (filename==NULL)
    f=stdout;
  else
    f=fopen(filename,"w");

  if (f==NULL)
  {
    FATAL2("Could not open %s with write access\n",filename);
  }
  if (nb_data==0)
  {
    WARNING1("No object files compiled with code coverage support\n");
  }
  fputs_trace("#pragma warning disable\n",f);
  fputs_trace("using System;\n",f);
  fputs_trace("using System.IO;\n",f);
  fputs_trace("using System.Text;\n",f);
  if (compiler_wrapper.setupMS())
    fputs_trace("using System.Runtime.InteropServices;\n",f);
  fputs_trace("class CoverageScanner\n",f);
  fputs_trace("{\n",f);
  if (lock_csexe)
  {
    fputs_trace("const int  CS_TIMEOUT=3000;\n",f);
  }
  fputs_trace("static string __cs_appname=\"",f);
  fputs_trace(default_csexe_escaped,f);
  fputs_trace(".csexe\";\n",f);
  fputs_trace("static System.IO.Stream __fopenread(string name) { return new FileStream(name,FileMode.Create,FileAccess.Read); }\n",f);
  fputs_trace("static System.IO.Stream __fopenappend(string name) { return new FileStream(name,FileMode.Append,FileAccess.Write); }\n",f);
  fputs_trace("static System.IO.Stream __fopenwrite(string name) { return new FileStream(name,FileMode.Create,FileAccess.Write); }\n",f);
  fputs_trace("static void __remove(string name) { System.IO.File.Delete(name); }\n",f);
  fputs_trace("static void __fputs(string data,System.IO.Stream stream) { System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();stream.Write(encoding.GetBytes(data),0,data.Length); }\n",f);
  fputs_trace("static string __fgets(System.IO.Stream stream) \n",f);
  fputs_trace(" { byte[] bytes= new byte[1024];  int numBytesToRead=1024; int numBytesRead=0; int n=stream.Read(bytes,numBytesRead,numBytesToRead); return Encoding.ASCII.GetString(bytes,0,n);}\n",f);
  fputs_trace("static void __fclose(System.IO.Stream stream) { stream.Close(); }\n",f);
  fputs_trace("static string __cs_testname=\"\";\n",f);
  fputs_trace("static string __cs_teststate=\"\";\n",f);

  /* Custom IO delegates */
  fputs_trace("public delegate string __cs_fgets_delegate(System.IO.Stream stream);\n",f);
  fputs_trace("public delegate void __cs_fputs_delegate(string s, System.IO.Stream stream);\n",f);
  fputs_trace("public delegate System.IO.Stream __cs_fopenappend_delegate(string path);\n",f);
  fputs_trace("public delegate System.IO.Stream __cs_fopenread_delegate(string path);\n",f);
  fputs_trace("public delegate System.IO.Stream __cs_fopenwrite_delegate(string path);\n",f);
  fputs_trace("public delegate void __cs_fclose_delegate(System.IO.Stream fp);\n",f);
  fputs_trace("public delegate void __cs_remove_delegate(string n);\n",f);
  /* Custom IO */
  fputs_trace("static __cs_fgets_delegate __cs_fgets =  new __cs_fgets_delegate(__fgets);\n",f);
  fputs_trace("static __cs_fputs_delegate __cs_fputs =  new __cs_fputs_delegate(__fputs);\n",f);
  fputs_trace("static __cs_fopenappend_delegate __cs_fopenappend =  new __cs_fopenappend_delegate(__fopenappend);\n",f);
  fputs_trace("static __cs_fopenread_delegate __cs_fopenread =  new __cs_fopenread_delegate(__fopenread);\n",f);
  fputs_trace("static __cs_fopenwrite_delegate __cs_fopenwrite =  new __cs_fopenwrite_delegate(__fopenwrite);\n",f);
  fputs_trace("static __cs_fclose_delegate __cs_fclose =  new __cs_fclose_delegate(__fclose);\n",f);
  fputs_trace("static __cs_remove_delegate __cs_remove =  new __cs_remove_delegate(__remove);\n",f);

  fputs_trace("static string __out_buffer=\"\";\n",f);
  fputs_trace("static string cs_fgets(System.IO.Stream stream)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  return __cs_fgets(stream);\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static void cs_fputs(string s, System.IO.Stream stream)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  const int max_lg=1024;\n",f);
  fputs_trace("  int lg=s.Length;\n",f);
  fputs_trace("  int __out_buffer_lg=__out_buffer.Length;\n",f);
  fputs_trace("  if  (lg+__out_buffer_lg>=max_lg)\n",f);
  fputs_trace("  {\n",f);
  fputs_trace("    if (__out_buffer_lg>0) __cs_fputs(__out_buffer,stream);\n",f);
  fputs_trace("    __out_buffer=\"\";\n",f);
  fputs_trace("  }\n",f);
  fputs_trace("  if  (lg>=max_lg)\n",f);
  fputs_trace("  {\n",f);
  fputs_trace("    __cs_fputs(s,stream);\n",f);
  fputs_trace("    return ;\n",f);
  fputs_trace("  }\n",f);
  fputs_trace("  __out_buffer+=s;\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static System.IO.Stream cs_fopenappend(string path)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  __out_buffer=\"\";\n",f);
  fputs_trace("  return __cs_fopenappend(path);\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static System.IO.Stream cs_fopenread(string path)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  __out_buffer=\"\";\n",f);
  fputs_trace("  return __cs_fopenread(path);\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static System.IO.Stream cs_fopenwrite(string path)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  __out_buffer=\"\";\n",f);
  fputs_trace("  return __cs_fopenwrite(path);\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static void cs_fclose(System.IO.Stream fp)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  if (__out_buffer.Length!=0) __cs_fputs(__out_buffer,fp);\n",f);
  fputs_trace("  __out_buffer=\"\";\n",f);
  fputs_trace("  __cs_fclose(fp);\n",f);
  fputs_trace("}\n",f);
  fputs_trace("public static \n",f);
  fputs_trace("void ",f);
  fputs_trace(" __coveragescanner_set_custom_io(",f);
  fputs_trace("__cs_fgets_delegate cs_fgets,\n",f);
  fputs_trace("__cs_fputs_delegate cs_fputs,\n",f);
  fputs_trace("__cs_fopenappend_delegate cs_fopenappend,\n",f);
  fputs_trace("__cs_fopenread_delegate cs_fopenread,\n",f);
  fputs_trace("__cs_fopenwrite_delegate cs_fopenwrite,\n",f);
  fputs_trace("__cs_fclose_delegate cs_fclose,\n",f);
  fputs_trace("__cs_remove_delegate cs_remove\n",f);
  fputs_trace(")\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  __cs_fgets=cs_fgets;\n",f);
  fputs_trace("  __cs_fputs=cs_fputs;\n",f);
  fputs_trace("  __cs_fopenappend=cs_fopenappend;\n",f);
  fputs_trace("  __cs_fopenread=cs_fopenread;\n",f);
  fputs_trace("  __cs_fopenwrite=cs_fopenwrite;\n",f);
  fputs_trace("  __cs_fclose=cs_fclose;\n",f);
  fputs_trace("  __cs_remove=cs_remove;\n",f);
  fputs_trace("}\n",f);

  fputs_trace("struct __cs_exec_t { public int size; public int signature; public string name;public int []values;} ;\n",f);
  fputs_trace("static __cs_exec_t []__cs_exec= null;\n",f);

  /* Checksum for lockfile */
  fputs_trace("static int __checksum_over_coverage()\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  int i,item;\n",f);
  fputs_trace("  int chksum=0;\n",f);
  fputs_trace("  for (item=0;__cs_exec[item].name!=null;item++)\n",f);
  fputs_trace("  {\n",f);
  fputs_trace("    for (i=0;i<__cs_exec[item].size;i++)\n",f);
  fputs_trace("      {\n",f);
  fputs_trace("          chksum += __cs_exec[item].values[i];\n",f);
  fputs_trace("      }\n",f);
  fputs_trace("  }\n",f);
  fputs_trace("  return chksum;\n",f);
  fputs_trace("}\n",f);
  fputs_trace("\n",f);

  /* init function of the table */
  fputs_trace("static string __cs_int2hex(int v)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  string h=\"\";\n",f);
  fputs_trace("  int i;\n",f);
  fputs_trace("  for (i=0;i<8;i++)\n",f);
  fputs_trace("  {\n",f);
  fputs_trace("    char c;\n",f);
  fputs_trace("    c=(char)((v>>(4*(7-i))) & 0xF);\n",f);
  fputs_trace("    if (c<=9)\n",f);
  fputs_trace("      c+='0';\n",f);
  fputs_trace("    else\n",f);
  fputs_trace("      c+=(char)('A'-10);\n",f);
  fputs_trace("    h+=c;\n",f);
  fputs_trace("  }\n",f);
  fputs_trace("  return h;\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static void __cs_sem_init()\n",f);
  fputs_trace("{\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static int __cs_sem_lock()\n",f);
  fputs_trace("{\n",f);
  if (lock_csexe)
  {
    fputs_trace("  System.DateTime start_time=System.DateTime.Now;\n",f);
    fputs_trace("  System.DateTime end_time;\n",f);
    fputs_trace("  string lockfile;\n",f);
    fputs_trace("  string str;\n",f);
    fputs_trace("  string str2;\n",f);
    fputs_trace("  System.IO.Stream f=null;\n\n",f);
    fputs_trace("  if (__cs_fgets==null) return 1;\n",f);
    fputs_trace("  str=\"cs:\";\n",f);
    fputs_trace("  str+=__cs_int2hex(System.Diagnostics.Process.GetCurrentProcess().Id);\n",f);
    fputs_trace("  str+=\":\";\n",f);
    fputs_trace("  str+=__cs_int2hex(start_time.Second*1000+start_time.Minute*60000+start_time.Millisecond);\n",f);
    fputs_trace("  str+=\":\";\n",f);
    fputs_trace("  str+=__cs_int2hex(__checksum_over_coverage());\n",f);
    fputs_trace("  lockfile=__cs_appname;\n",f);
    fputs_trace("  lockfile+=\".lck\";\n",f);
    fputs_trace("  start_time=System.DateTime.Now;\n",f);
    fputs_trace("  for (end_time=start_time;(end_time-start_time).Seconds<CS_TIMEOUT;end_time=System.DateTime.Now)\n",f);
    fputs_trace("  {\n",f);
    fputs_trace("    int canlock=0;\n",f);
    fputs_trace("    try {\n",f);
    fputs_trace("      f=cs_fopenread(lockfile);\n",f);
    fputs_trace("    } \n",f);
    fputs_trace("    catch \n",f);
    fputs_trace("    {\n",f);
    fputs_trace("      canlock=1;\n",f);
    fputs_trace("      f=null;\n",f);
    fputs_trace("    }\n",f);
    fputs_trace("    if (f!=null)\n",f);
    fputs_trace("    {\n",f);
    fputs_trace("      try {\n",f);
    fputs_trace("        f=cs_fopenread(lockfile);\n",f);
    fputs_trace("        str2=cs_fgets(f);  \n",f);
    fputs_trace("        cs_fclose(f);\n",f);
    fputs_trace("        if (str2==\"\")\n",f);
    fputs_trace("          canlock=1;\n",f);
    fputs_trace("      } catch {}\n",f);
    fputs_trace("    } \n",f);
    fputs_trace("    if (canlock==1)\n",f);
    fputs_trace("    {\n",f);
    fputs_trace("      try \n",f);
    fputs_trace("      {\n",f);
    fputs_trace("        f=cs_fopenwrite(lockfile);  \n",f);
    fputs_trace("        cs_fputs(str,f);  \n",f);
    fputs_trace("        cs_fclose(f);\n",f);
    fputs_trace("        f=cs_fopenread(lockfile);  \n",f);
    fputs_trace("        str2=cs_fgets(f);  \n",f);
    fputs_trace("        cs_fclose(f);\n",f);
    fputs_trace("        if (str2==str)\n",f);
    fputs_trace("          return 1;\n",f);
    fputs_trace("      } catch {}\n",f);
    fputs_trace("    }\n",f);
    fputs_trace("  }\n",f);
    fputs_trace("  return 0;\n",f);
  }
  else
    fputs_trace("  return 1;\n",f);
  fputs_trace("}\n",f);
  fputs_trace("static void __cs_sem_unlock()\n",f);
  fputs_trace("{\n",f);
  if (lock_csexe)
  {
    fputs_trace("try \n",f);
    fputs_trace("{\n",f);
    fputs_trace("  string lockfile;\n",f);
    fputs_trace("  if (__cs_fgets==null) return ;\n",f);
    fputs_trace("  lockfile=__cs_appname;\n",f);
    fputs_trace("  lockfile+=\".lck\";\n",f);
    fputs_trace("  if (__cs_remove!=null)\n",f);
    fputs_trace("    __cs_remove(lockfile);\n",f);
    fputs_trace("  else\n",f);
    fputs_trace("  {\n",f);
    fputs_trace("    System.IO.Stream f;\n\n",f);
    fputs_trace("    f=cs_fopenwrite(lockfile);  \n",f);
    fputs_trace("    cs_fclose(f);\n",f);
    fputs_trace("  }\n",f);
    fputs_trace("} catch {}\n",f);
  }
  fputs_trace("}\n",f);
  fputs_trace("static void __cs_exec_init()\n",f);
  fputs_trace("{\n",f);
  fputs_trace("try \n",f);
  fputs_trace("{\n",f);

  fputs_trace("  if (__cs_exec!=null) return ;\n\n",f);
  fputs_trace("  __cs_exec_t []exectab = new __cs_exec_t[",f);
  sprintf(tmp,"%lu",nb_data+1);
  fputs_trace(tmp,f);
  fputs_trace("  ];\n\n",f);
  fputs_trace("  __cs_exec=exectab;\n\n",f);
  for (i=0;i<nb_data;i++)
  {
    char table_name[INSTRUMENTATION_CODE_MAX_LENGTH] ;
    char filename_abs[MAX_PATH];
    realPath(datas[i].filename,filename_abs);
    Source::instrumentation_table(filename_abs,table_name);

    fputs_trace("  /* ",f);
    fputs_trace(filename_abs,f);
    fputs_trace(" */\n",f);
    sprintf(indexstr,"%i",i);
    sprintf(tmp,"  __cs_exec[%i]",i);

    fputs_trace(tmp,f);
    fputs_trace(".signature=",f);
    sprintf(signature_str,"%lu",datas[i].signature);
    fputs_trace(signature_str,f);
    fputs_trace(";\n",f);

    fputs_trace(tmp,f);
    fputs_trace(".name=",f);
    fputs_trace("\"",f);
    {
      char table_name[INSTRUMENTATION_CODE_MAX_LENGTH] ;
      char filename_abs_escape[MAX_PATH*2];
      char filename_abs[MAX_PATH];
      realPath(datas[i].filename,filename_abs);
      Source::instrumentation_table(filename_abs,table_name);
      escape(filename_abs,filename_abs_escape);
      fputs_trace(filename_abs_escape,f);
    }
    fputs_trace("\";\n",f);

    fputs_trace(tmp,f);
    fputs_trace(".values=",f);
    fputs_trace(table_name,f);
    fputs_trace(".val;\n",f);

    fputs_trace(tmp,f);
    fputs_trace(".size=",f);
    fputs_trace(table_name,f);
    fputs_trace(".nb;\n",f);
  }
  sprintf(tmp,"  __cs_exec[%i]",i);
  fputs_trace(tmp,f);
  fputs_trace(".signature=0;\n",f);

  fputs_trace(tmp,f);
  fputs_trace(".name=null;\n",f);

  fputs_trace(tmp,f);
  fputs_trace(".values=null;\n",f);

  fputs_trace(tmp,f);
  fputs_trace(".size=0;\n",f);
  fputs_trace("} catch {}\n",f);
  fputs_trace("}\n",f);


  /* __coveragescanner_save */
  fputs_trace("public static \n",f);
  fputs_trace("void ",f);
  fputs_trace(" __coveragescanner_save()\n",f);
  fputs_trace("{\n",f);
  fputs_trace("try \n",f);
  fputs_trace("{\n",f);
  fputs_trace("  int i,item;\n",f);
  fputs_trace("  System.IO.Stream f;\n\n",f);

  fputs_trace("  __cs_sem_init();\n",f);
  fputs_trace("  __cs_exec_init();\n",f);
  fputs_trace("  if (__cs_sem_lock()==0) return ;\n",f);
  fputs_trace("  f=cs_fopenappend(__cs_appname);\n",f);
  fputs_trace("  if (f==null) return ;\n",f);

  fputs_trace("  try {\n",f);
  fputs_trace("  if (__cs_testname!=\"\") {\n",f);
  fputs_trace("    cs_fputs(\"*\",f);\n",f);
  fputs_trace("    cs_fputs(__cs_testname,f);\n",f);
  fputs_trace("    cs_fputs(\"\\n\",f);\n",f);
  fputs_trace("  }\n",f);

  fputs_trace("  cs_fputs(\"# Measurements\\n\",f);\n",f);

  /* Recording code */
  fputs_trace("  for (item=0;__cs_exec[item].name!=null;item++)\n",f);
  fputs_trace("  {\n",f);
  fputs_trace("    if (__cs_exec[item].size==0) continue;\n",f);
  fputs_trace("    bool empty=true;\n",f);
  fputs_trace("    for (i=0;i<__cs_exec[item].size;i++)\n",f);
  fputs_trace("      {\n",f);
  fputs_trace("          if (__cs_exec[item].values[i]!=0)\n",f);
  fputs_trace("             empty=false;\n",f);
  fputs_trace("      }\n",f);
  fputs_trace("    if (empty) continue;\n",f);
  fputs_trace("    cs_fputs(\"/\",f);\n",f);
  fputs_trace("    cs_fputs(Convert.ToString(__cs_exec[item].size),f);\n",f);
  fputs_trace("    cs_fputs(\":\",f);\n",f);
  fputs_trace("    cs_fputs(Convert.ToString(__cs_exec[item].signature),f);\n",f);
  fputs_trace("    cs_fputs(\":\",f);\n",f);
  fputs_trace("    cs_fputs(__cs_exec[item].name,f);\n",f);
  fputs_trace("    cs_fputs(\"\\n\",f);\n",f);

  fputs_trace("    cs_fputs(\"\\\\\",f);\n",f);

  fputs_trace("    for (i=0;i<__cs_exec[item].size;i++)\n",f);

  fputs_trace("      {\n",f);
  fputs_trace("        {\n",f);
  fputs_trace("          switch (__cs_exec[item].values[i])\n",f);
  fputs_trace("          {\n",f);
  fputs_trace("            case 1:\n",f);
  fputs_trace("              cs_fputs(\"+\",f);\n",f);
  fputs_trace("              break;\n",f);
  fputs_trace("            case 0:\n",f);
  fputs_trace("              cs_fputs(\"-\",f);\n",f);
  fputs_trace("              break;\n",f);
  fputs_trace("            default:\n",f);
  fputs_trace("              cs_fputs(__cs_int2hex(__cs_exec[item].values[i]),f);\n",f);
  fputs_trace("              break;\n",f);
  fputs_trace("          }\n",f);
  fputs_trace("        }\n",f);
  fputs_trace("        __cs_exec[item].values[i]=0;\n",f);
  fputs_trace("      }\n",f);
  fputs_trace("    cs_fputs(\"\\n\",f);\n",f);
  fputs_trace("  }\n",f);

  /* saving the execution statue */
  fputs_trace("  if (__cs_teststate!=\"\") {\n",f);
  fputs_trace("    cs_fputs(\"!\",f);\n",f);
  fputs_trace("    cs_fputs(__cs_teststate,f);\n",f);
  fputs_trace("    cs_fputs(\"\\n\",f);\n",f);
  fputs_trace("    __cs_teststate=\"\";\n",f);
  fputs_trace("  }\n",f);

  fputs_trace("  cs_fclose(f);\n",f);
  fputs_trace("  } catch  { cs_fclose(f); }\n",f);
  fputs_trace("  __cs_sem_unlock();\n",f);
  fputs_trace("} catch {}\n",f);
  fputs_trace("}\n",f);
  fputs_trace("\n",f);

  /* __coveragescanner_testname */
  fputs_trace("public static \n",f);
  fputs_trace("void ",f);
  fputs_trace(" __coveragescanner_testname(string name)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  __cs_testname=name;\n",f);
  fputs_trace("}\n",f);

  /* __coveragescanner_filename */
  fputs_trace("public static \n",f);
  fputs_trace("void ",f);
  fputs_trace(" __coveragescanner_filename(string name)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("try \n",f);
  fputs_trace("{\n",f);
  fputs_trace("  __cs_appname=name;\n",f);
  fputs_trace("  __cs_appname+=\".csexe\";\n",f);
  fputs_trace("} catch {}\n",f);
  fputs_trace("}\n",f);

  /* __coveragescanner_clear */
  fputs_trace("public static \n",f);
  fputs_trace("void ",f);
  fputs_trace(" __coveragescanner_clear()\n",f);
  fputs_trace("{\n",f);
  fputs_trace("try \n",f);
  fputs_trace("{\n",f);
  fputs_trace("  int i,item;\n",f);
  fputs_trace("  __cs_sem_init();\n",f);
  fputs_trace("  __cs_exec_init();\n",f);
  fputs_trace("  for (item=0;__cs_exec[item].values!=null;item++)\n",f);
  fputs_trace("    for (i=0;i<__cs_exec[item].size;i++)\n",f);
  fputs_trace("        __cs_exec[item].values[i]=0;\n",f);
  fputs_trace("} catch {}\n",f);
  fputs_trace("}\n",f);
  fputs_trace("\n",f);

  /* __coveragescanner_teststate */
  fputs_trace("public static \n",f);
  fputs_trace("void ",f);
  fputs_trace(" __coveragescanner_teststate(string state)\n",f);
  fputs_trace("{\n",f);
  fputs_trace("  __cs_teststate=state;\n",f);
  fputs_trace("}\n",f);

  if (!compiler_wrapper.customSetup())
  {
    fputs_trace("static bool __cs_default_exit=true;\n",f);
    fputs_trace("static void __cs_exit()\n",f);
    fputs_trace("{\n",f);
    fputs_trace("  __coveragescanner_save();\n",f);
    fputs_trace("}\n",f);
    fputs_trace("static void __cs_exit_default()\n",f);
    fputs_trace("{\n",f);
    fputs_trace("  if (__cs_default_exit)\n",f);
    fputs_trace("    __cs_exit();\n",f);
    fputs_trace("}\n",f);
    fputs_trace("static void __cs_init()\n",f);
    fputs_trace("{\n",f);
    fputs_trace("  try {\n",f);
    fputs_trace("  __coveragescanner_filename(System.Environment.GetCommandLineArgs()[0]);\n",f);
    fputs_trace("  } catch\n",f);
    fputs_trace("  {__coveragescanner_filename(\"",f);
    fputs_trace(default_csexe_escaped,f);
    fputs_trace("\");}\n",f);
    fputs_trace("}\n",f);
  }
  fputs_trace("public class __cs_lib_t {\n",f);
  fputs_trace("  public",f);
  fputs_trace("  __cs_lib_t()\n",f);
  fputs_trace("    {\n",f);
  if (!compiler_wrapper.customSetup())
    fputs_trace("       CoverageScanner.__cs_init();\n",f);
  fputs_trace("    }\n",f);
  if (!compiler_wrapper.customSetup())
  {
    fputs_trace("  ~__cs_lib_t()\n",f);
    fputs_trace("    {\n",f);
    fputs_trace("       CoverageScanner.__cs_exit();\n",f);
    fputs_trace("    }\n",f);
  }
  fputs_trace("};\n",f);
  fputs_trace("}\n",f);

  if (filename!=NULL)
    fclose(f);
  DEBUG1("==== end generating __cs_libgen.cs source code ====\n");
  FREE(default_csexe_escaped);
}
Пример #8
0
bool CFontThumbnail::create(const QString &path, int width, int height, QImage &img)
{
    QString  realPath(path);
    KTempDir *tempDir = 0;

    KFI_DBUG << "Create font thumbnail for:" << path << endl;

    // Is this a appliaction/vnd.kde.fontspackage file? If so, extract 1 scalable font...
    if(Misc::isPackage(path) || "application/zip"==KMimeType::findByFileContent(path)->name())
    {
        KZip zip(path);

        if(zip.open(QIODevice::ReadOnly))
        {
            const KArchiveDirectory *zipDir=zip.directory();

            if(zipDir)
            {
                QStringList fonts(zipDir->entries());

                if(fonts.count())
                {
                    QStringList::ConstIterator it(fonts.begin()),
                                               end(fonts.end());

                    for(; it!=end; ++it)
                    {
                        const KArchiveEntry *entry=zipDir->entry(*it);

                        if(entry && entry->isFile())
                        {
                            delete tempDir;
                            tempDir=new KTempDir(KStandardDirs::locateLocal("tmp", KFI_TMP_DIR_PREFIX));
                            tempDir->setAutoRemove(true);

                            ((KArchiveFile *)entry)->copyTo(tempDir->name());

                            QString mime(KMimeType::findByPath(tempDir->name()+entry->name())->name());

                            if(mime=="application/x-font-ttf" || mime=="application/x-font-otf" ||
                               mime=="application/x-font-type1")
                            {
                                realPath=tempDir->name()+entry->name();
                                break;
                            }
                            else
                                ::unlink(QFile::encodeName(tempDir->name()+entry->name()).data());
                        }
                    }
                }
            }
        }
    }

    QColor bgnd(Qt::black);

    bgnd.setAlpha(0);
    img=itsEngine.draw(realPath, KFI_NO_STYLE_INFO, 0, QApplication::palette().text().color(), bgnd, width, height, true);

    delete tempDir;
    return !img.isNull();
}