⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compile.cpp

📁 linux 下 源代码测试系统 用 tar 打开
💻 CPP
字号:
/* * $File: compile.cpp * $Author: Jiakai -- gy_jk@126.com * $Date: Mon Mar 23 23:15:55 2009 *//*Copyright (C) (2008) (Jiakai) <gy_jk@126.com>This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "compile.h"#include "common.h"#include <cstdlib>#include <string>#include <cstring>#include <cstdio>#include <fstream>using namespace std;//---------------Function Statements-----------------------static void argreplace(string &str, const char *src);//---------------------------------------------------------Compile_status::Compile_status() : compiler_output(NULL) {}Compile_status::~Compile_status() {delete []compiler_output;}void compile(const char *source, const Conf &conf, Compile_status &cs){	char command_[COMPILE_MAX_CONF_LENGTH];	const char *ext = source;	while (*ext)		ext ++;	while (*ext != '.')		ext --;	ext ++;	if (!conf.read("compiler.command", ext, command_, COMPILE_MAX_CONF_LENGTH))	{		cs.success = false;		const char REASON[] = "Failed to read the configuration file.";		cs.compiler_output = new char[strlen(REASON) + 1];		strcpy(cs.compiler_output, REASON);		return;	}	string command(command_);	argreplace(command, source);	string tempfile(TEMP_DIRECTORY);	tempfile += "complier_output";	command += " 2>" + tempfile + " 1>>" + tempfile;	if (system(command.c_str()))	{		ifstream fin(tempfile.c_str());		string output;		while (fin)		{			string x;			getline(fin, x);			if (!x.empty())			{				output += x;				output += "\n";			}		}		cs.compiler_output = new char[output.length() + 1];		strcpy(cs.compiler_output, output.c_str());		cs.success = false;	} else cs.success = true;	remove(tempfile.c_str());}void argreplace(string &str, const char *src){	string tmp(src);	string::size_type pos = tmp.length() - 1;	while (tmp[pos] != '.')		pos --;	tmp.erase(pos);	string::size_type loc = str.find("%s", 0);	while (loc != string::npos)	{		str.replace(loc, 2, tmp);		loc = str.find("%s", 0);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -