示例#1
0
void cpufreq_cpuspeed(unsigned clockspeed)
{
	char freq[10];
	sprintf(freq, "%d", clockspeed * 1000);
	writeStringToFile(SYSFS_CPUFREQ_MAX, freq);
	writeStringToFile(SYSFS_CPUFREQ_SET, freq);
}
示例#2
0
void SourceFileGenerator::generateCode_Namespace(FILE* file, NamespaceNode* namespaceNode, int indentation)
{
	char buf[512];
	if(!namespaceNode->isGlobalNamespace())
	{
		sprintf_s(buf, "namespace %s\n", namespaceNode->m_name->m_str.c_str());
		writeStringToFile(buf, file, indentation);
		writeStringToFile("{\n\n", file, indentation);
	}
	std::vector<MemberNode*> memberNodes;
	namespaceNode->m_memberList->collectMemberNodes(memberNodes);
	size_t count = memberNodes.size();
	for(size_t i = 0; i < count; ++i)
	{
		MemberNode* memberNode = memberNodes[i];
		switch (memberNode->m_nodeType)
		{
		case snt_class:
			generateCode_Class(file, static_cast<ClassNode*>(memberNode), indentation + 1);
			break;
		case snt_namespace:
			generateCode_Namespace(file, static_cast<NamespaceNode*>(memberNode), indentation + 1);
			break;
		}
	}

	if(!namespaceNode->isGlobalNamespace())
	{
		writeStringToFile("}\n\n", file, indentation);
	}
}
示例#3
0
void SourceFileGenerator::generateCode_Class(FILE* file, ClassNode* classNode, int indentation)
{
	if (!classNode->isValueType())
	{
		std::string typeName;
		GetClassName(typeName, classNode);
		generateCode_TemplateHeader(file, classNode, indentation);
		writeStringToFile("::pafcore::Type* ", file, indentation);
		writeStringToFile(typeName.c_str(), file);
		writeStringToFile("::getType()\n", file);
		writeStringToFile("{\n", file, indentation);
		writeStringToFile("return ::RuntimeTypeOf<", file, indentation + 1);
		writeStringToFile(typeName.c_str(), file);
		writeStringToFile(">::RuntimeType::GetSingleton();\n", file);
		writeStringToFile("}\n\n", file, indentation);
	}
	if(!classNode->m_additionalMethods.empty())
	{
		size_t count = classNode->m_additionalMethods.size();
		for(size_t i = 0; i < count; ++i)
		{
			generateCode_AdditionalMethod(file, classNode->m_additionalMethods[i], indentation);
		}
	}
}
示例#4
0
int main( int argc, char** argv )
{
    if( argc != 2 )
    {
        printf( "Nombre d'arguments incorrect. %i\n", argc);
        return -1;
    }

    FILE* file = fopen( argv[0], "r" );
    if( file != NULL )
    {
        unsigned long len;
        char* fileStr = fileToString( file, &len );
        fclose( file );
        char* enc = encryptString( fileStr, len );
        file = fopen( argv[1], "w" );
        writeStringToFile( file, enc );
        fclose( file );
    }
    else
    {
        printf( "Impossible d'ouvrir le fichier %s.\n", argv[0] );
        return -1;
    }

    return 0;
}
示例#5
0
int sendCGIHTTPResponseHeader(http_cgi_response *header)
{
    int i_index = 0;
    int i_success = 0;
    char* cp_cgi_http_response_header = NULL;
    

    if(header == NULL)
        return EXIT_FAILURE;
        
    strAppend(&cp_cgi_http_response_header, "HTTP/1.1 ");
    strAppend(&cp_cgi_http_response_header, header->status);
    strAppend(&cp_cgi_http_response_header, "\n");
    
    for(i_index = 0; i_index < header->i_num_fields; i_index++)
    {
        strAppend(&cp_cgi_http_response_header, header->cpp_header_field_name[i_index]);
        strAppend(&cp_cgi_http_response_header, ": ");
        strAppend(&cp_cgi_http_response_header, header->cpp_header_field_body[i_index]);
        strAppend(&cp_cgi_http_response_header, "\n");
    }
    
    strAppend(&cp_cgi_http_response_header, "\n");
    
    i_success = writeStringToFile(STDOUT_FILENO, cp_cgi_http_response_header);

    return i_success;
}
示例#6
0
文件: util.cpp 项目: nvaller/mcrouter
bool atomicallyWriteFileToDisk(folly::StringPiece contents,
                               const std::string& absFilename) {
  boost::filesystem::path tempFilePath;
  auto tempFileGuard = folly::makeGuard([&tempFilePath]() {
    if (!tempFilePath.empty()) {
      boost::system::error_code ec;
      boost::filesystem::remove(tempFilePath.c_str(), ec);
    }
  });

  try {
    const boost::filesystem::path filePath(absFilename);
    auto fileDir = filePath.parent_path();
    if (fileDir.empty()) {
      return false;
    }
    auto tempFileName = filePath.filename().string() + ".temp-" +
      randomString(/* minLen */ 10, /* maxLen */ 10);
    tempFilePath = fileDir / tempFileName;

    boost::filesystem::create_directories(fileDir);

    if (!writeStringToFile(contents, tempFilePath.string())) {
      return false;
    }

    boost::filesystem::rename(tempFilePath, filePath);
    return true;
  } catch (const boost::filesystem::filesystem_error& e) {
    return false;
  } catch (const boost::system::system_error& e) {
    return false;
  }
}
示例#7
0
void convert::replaceAllStringInFile(const std::string& oldfilename, const std::string& newfilename, const std::string& oldstring, const std::string& newstring)
{
    std::string s = readStringFromFile(oldfilename);
    if (s.length() <= 0) { return; }
    replaceAllString(s, oldstring, newstring);
    writeStringToFile(s, newfilename);
}
示例#8
0
void setNormalizedSleepers(bool on)
{
    int retcode;

    if (on)
    {
        retcode = writeStringToFile(kSchedFeatures, kNormalizedSleepers);
    }
    else
    {
        retcode = writeStringToFile(kSchedFeatures, kNoNormalizedSleepers);
    }
    if (retcode < 0)
    {
        fprintf(stderr, "# %s\n", kDebugfsWarningMsg);
    }
}
示例#9
0
文件: util.cpp 项目: nvaller/mcrouter
bool touchFile(const std::string& path) {
  struct stat fileStats;
  if (stat(path.data(), &fileStats)) {
    if (!writeStringToFile("", path)) {
      return false;
    }
  }
  return utime(path.data(), nullptr) == 0;
}
//using Eigen::MatrixXd;
int main(int argc, char* argv[])
{
	//MatrixXd m;
	//char command = argv[1][0];
	char command = 'E';
	string result;
	switch (command)
	{
	case 'R':
		//cout << readGraphToString(argv[2]);
		//cout << readGraphToString("test.txt");
		result = readGraphToString("facebook_combined.txt");
		writeStringToFile(result, "FaceboolResult.txt");
		break;
	case 'P':
		//cout<<CPM("cpm.txt", 4);
		result = CPM("facebook_combined.txt", 4);
		cout << result << endl;
		writeStringToFile(result, "CPM_result.txt");
		break;
	case 'B':
		//cout << BruteForceClique(argv[2], atoi(argv[3]));
		cout << BruteForceClique("cpm.txt", 3);
		break;
	case 'G':
		//cout << BalancedCommunity(argv[2]);
		cout << BalancedCommunity("Figure6.3.txt");
		break;
	case 'M':
		//cout << ModularCommunity(argv[2]);
		cout << ModularCommunity("facebook_combined.txt");
		break;
	case 'E':
		cout<<CommunityEvolve("facebook_combined.txt");
	default:
		break;
	}
	//BruteForceClique(argv[1], atoi(argv[2]));
	//readUnDirectedGraphToMatrix("facebook_combined.txt");
	//cout << readGraphToString("facebook_combined.txt");
	//cout << BalancedCommunity("Figure6.8.txt");
	//cout << ModularCommunity("facebook_combined.txt");
	return 0;
}
示例#11
0
void SourceFileGenerator::generateCode_TemplateHeader(FILE* file, ClassNode* classNode, int indentation)
{
	if(classNode->m_templateParameters)
	{
		std::vector<TemplateParameterNode*> templateParameterNodes;
		classNode->m_templateParameters->collectParameterNodes(templateParameterNodes);
		writeStringToFile("template<", file, indentation);
		size_t count = templateParameterNodes.size();
		for(size_t i = 0; i < count; ++i)
		{
			if(0 != i)
			{
				writeStringToFile(",", file);
			}
			writeStringToFile("typename ", file);
			writeStringToFile(templateParameterNodes[i]->m_name->m_str.c_str(), file);
		}
		writeStringToFile(">\n", file);
	}
}
示例#12
0
void SourceFileGenerator::generateCode_Program(FILE* file, ProgramNode* programNode, const char* fileName, const char* cppName)
{
	char buf[512];
	std::string pafcorePath;
	GetRelativePath(pafcorePath, fileName, g_options.m_pafcorePath.c_str());
	FormatPathForInclude(pafcorePath);

	writeStringToFile("#pragma once\n\n", file);

	sprintf_s(buf, "#include \"%s.h\"\n", cppName);
	writeStringToFile(buf, file);

	sprintf_s(buf, "#include \"%s%s\"\n", cppName, g_options.m_metaHeaderFilePostfix.c_str());
	writeStringToFile(buf, file);

	sprintf_s(buf, "#include \"%sRefCount.h\"\n\n", pafcorePath.c_str());
	writeStringToFile(buf, file);

	generateCode_Namespace(file, programNode, -1);
}
示例#13
0
void App::saveShaderDialog() {
	char *out_filepath = nullptr;
	nfdresult_t result = NFD_SaveDialog("frag,glsl,fsh,txt", nullptr, &out_filepath);
	SDL_RaiseWindow(sdl_window); // workaround: focus window again after dialog closes

	if (result == NFD_OKAY) {
		if (shader_filepath) free(shader_filepath);
		shader_filepath = out_filepath;

		writeStringToFile(shader_filepath, src_edit_buffer);
		struct stat attr;
		if (!stat(shader_filepath, &attr)) { // file exists
			shader_file_mtime = 0; // force autoreload
		}
	}
}
示例#14
0
void disableCpuScaling()
{
    for (int cpu = 0; cpu < 16; ++cpu) // 16 cores mobile phones, abestos pockets recommended.
    {
        char governor[FILENAME_MAX];
        sprintf(governor, kScalingGovernorFormat, cpu);

        if (writeStringToFile(governor, "performance", kSilentIfMissing) < 0)
        {
            if (cpu > 0 && errno == ENOENT)
            {
                break;  // cpu1 or above not found, ok since we have cpu0.
            }
            fprintf(stderr, "Failed to write to scaling governor file for cpu %d: %d %s",
                    cpu, errno, strerror(errno));
            break;
        }
    }
}
示例#15
0
int sendHTTPAuthorizationResponse(const char* ccp_realm, const char* ccp_nonce)
{
    int i_success = 0;
    char* cp_http_auth_response = NULL;
    char* cp_body = "<html><body>Access Denied!</body></html>";

    if(ccp_realm == NULL || ccp_nonce == NULL)
        return EXIT_FAILURE;
        
    cp_http_auth_response = secPrint2String("HTTP/1.1 %s\n", getStatusCode(STATUS_UNAUTHORIZED));
    strAppend(&cp_http_auth_response, "Server: tiniweb/1.0\n");
    strAppend(&cp_http_auth_response, "Connection: close\n");
    strAppendFormatString(&cp_http_auth_response, 
                          "WWW-Authenticate: Digest realm=\"%s\", nonce=\"%s\"\n", ccp_realm, ccp_nonce);
    strAppendFormatString(&cp_http_auth_response, "Content-Type: %s\n", getContentType(TEXT_HTML));
    strAppendFormatString(&cp_http_auth_response, "Content-Length: %d\n\n", strlen(cp_body));
    strAppendFormatString(&cp_http_auth_response, "%s", cp_body);
    
    i_success = writeStringToFile(STDOUT_FILENO, cp_http_auth_response);
        
    return i_success;
}
示例#16
0
int sendHTTPResponseHeader(int i_status, int i_content_type, int i_content_length)
{     
    int i_success = 0;
    char* cp_http_response_header = NULL;
    
    cp_http_response_header = secPrint2String("HTTP/1.1 %s\n", getStatusCode(i_status));
    strAppend(&cp_http_response_header, "Server: tiniweb/1.0\n");
    strAppend(&cp_http_response_header, "Connection: close\n");
    strAppendFormatString(&cp_http_response_header, "Content-Type: %s\n", getContentType(i_content_type));
    
    if(i_content_length >= 0)
    {
        strAppendFormatString(&cp_http_response_header, "Content-Length: %i\n", i_content_length);
    }
    
    strAppend(&cp_http_response_header, "\n");
    
	
    i_success = writeStringToFile(STDOUT_FILENO, cp_http_response_header);
        
    return i_success;
}
示例#17
0
int sendHTTPResponse(int i_status, int i_content_type, const char* ccp_body)
{
    int i_content_length = 0;
    int i_success = EXIT_SUCCESS;
    
    if(ccp_body != NULL)
    {       
        i_content_length = strlen(ccp_body);
    }
       
    i_success = sendHTTPResponseHeader(i_status, i_content_type, i_content_length);
    
    if(i_success == EXIT_FAILURE)
        return EXIT_FAILURE;
    
    if(ccp_body != NULL)
    {
        i_success = writeStringToFile(STDOUT_FILENO, ccp_body);
    }
        
    return i_success;
}
示例#18
0
Error writeProjectFile(const FilePath& projectFilePath,
                       const RProjectConfig& config)
{  
   // generate project file contents
   boost::format fmt(
      "Version: %1%\n"
      "\n"
      "RestoreWorkspace: %2%\n"
      "SaveWorkspace: %3%\n"
      "AlwaysSaveHistory: %4%\n"
      "\n"
      "EnableCodeIndexing: %5%\n"
      "UseSpacesForTab: %6%\n"
      "NumSpacesForTab: %7%\n"
      "Encoding: %8%\n"
      "\n"
      "RnwWeave: %9%\n"
      "LaTeX: %10%\n");

   std::string contents = boost::str(fmt %
        boost::io::group(std::fixed, std::setprecision(1), config.version) %
        yesNoAskValueToString(config.restoreWorkspace) %
        yesNoAskValueToString(config.saveWorkspace) %
        yesNoAskValueToString(config.alwaysSaveHistory) %
        boolValueToString(config.enableCodeIndexing) %
        boolValueToString(config.useSpacesForTab) %
        config.numSpacesForTab %
        config.encoding %
        config.defaultSweaveEngine %
        config.defaultLatexProgram);

   // write it
   return writeStringToFile(projectFilePath,
                            contents,
                            string_utils::LineEndingNative);
}
示例#19
0
int sendHTTPResponseHeaderExplicit(const char* ccp_status, const char* ccp_content_type, int i_content_length)
{
    int i_success = 0;
    char* cp_http_response_header = NULL;

    if(ccp_content_type == NULL || ccp_status == NULL)
        return EXIT_FAILURE;
        
    cp_http_response_header = secPrint2String("HTTP/1.1 %s\n", ccp_status);
    strAppend(&cp_http_response_header, "Server: tiniweb/1.0\n");
    strAppend(&cp_http_response_header, "Connection: close\n");
    strAppendFormatString(&cp_http_response_header, "Content-Type: %s\n", ccp_content_type);
    
    if(i_content_length >= 0)
    {
        strAppendFormatString(&cp_http_response_header, "Content-Length: %i\n", i_content_length);
    }
    
    strAppend(&cp_http_response_header, "\n");
    
    i_success = writeStringToFile(STDOUT_FILENO, cp_http_response_header);
        
    return i_success;
}
示例#20
0
void SourceFileGenerator::generateCode_AdditionalMethod(FILE* file, MethodNode* methodNode, int indentation)
{
	ClassNode* classNode = static_cast<ClassNode*>(methodNode->m_enclosing);

	generateCode_TemplateHeader(file, classNode, indentation);


	writeStringToFile("inline ", file, indentation);

	std::string typeName;
	GetClassName(typeName, classNode);


	writeStringToFile(typeName.c_str(), file);

	if(0 != methodNode->m_passing)
	{
		generateCode_Token(file, methodNode->m_passing, 0);
	}
	writeStringToFile(g_strSpaces, 1, file);
	writeStringToFile(typeName.c_str(), file);
	writeStringToFile("::", file);

	generateCode_Identify(file, methodNode->m_name, 0);

	generateCode_Token(file, methodNode->m_leftParenthesis, 0);
	std::vector<std::pair<TokenNode*, ParameterNode*>> parameterNodes;
	methodNode->collectParameterNodes(parameterNodes);
	size_t parameterCount = parameterNodes.size();
	for(size_t i = 0; i < parameterCount; ++i)
	{
		if(parameterNodes[i].first)
		{
			generateCode_Token(file, parameterNodes[i].first, 0);
		}
		generateCode_Parameter(file, parameterNodes[i].second, methodNode, 0);
	}
	generateCode_Token(file, methodNode->m_rightParenthesis, 0);
	writeStringToFile("\n", file);
	char buf[512];
	writeStringToFile("{\n", file, indentation);
	if("NewArray" == methodNode->m_name->m_str)
	{
		if(classNode->isValueType())
		{
			sprintf_s(buf, "return new_array<%s>(count);\n", typeName.c_str());
		}
		else
		{
			sprintf_s(buf, "return new_array<::pafcore::RefCountObject<%s>>(count);\n", typeName.c_str());
		}
		writeStringToFile(buf, file, indentation + 1);
	}
	else if("NewArrayARC" == methodNode->m_name->m_str)
	{
		sprintf_s(buf, "return new_array<::pafcore::AtomicRefCountObject<%s>>(count);\n", typeName.c_str());
		writeStringToFile(buf, file, indentation + 1);
	}
	else
	{
		if("New" == methodNode->m_name->m_str || "Clone" == methodNode->m_name->m_str)
		{
			if(classNode->isValueType())
			{
				sprintf_s(buf, "return new %s(", typeName.c_str());
			}
			else
			{
				sprintf_s(buf, "return new ::pafcore::RefCountObject<%s>(", typeName.c_str());
			}
		}
		else
		{
			assert("NewARC" == methodNode->m_name->m_str || "CloneARC" == methodNode->m_name->m_str);
			sprintf_s(buf, "return new ::pafcore::AtomicRefCountObject<%s>(", typeName.c_str());
		}
		writeStringToFile(buf, file, indentation + 1);
		for(size_t i = 0; i < parameterCount; ++i)
		{
			if(i != 0)
			{
				writeStringToFile(", ", file);
			}
			writeStringToFile(parameterNodes[i].second->m_name->m_str.c_str(), file);
		}
		writeStringToFile(");\n", file);
	}
	writeStringToFile("}\n\n", file, indentation);
}
示例#21
0
void App::saveShader() {
	if (!shader_filepath) return;
	writeStringToFile(shader_filepath, src_edit_buffer);
}
示例#22
0
文件: Utility.cpp 项目: fdyjfd/idlcpp
void writeSpaceToFile(FILE* file)
{
	writeStringToFile(" ", 1, file, 0);
}