/** Performs generalized matrix multiplication
	The flags indicate if any of the three matricies should be transposed.

	- Flags:
		- MUL_A_T = Transpose source matrix A
		- MUL_B_T = Transpose source matrix B
		- MUL_D_T = Transpose destination matrix D

	\pre
	dst = alpha*src1T*src2 
	\endpre
*/
merror mGEMM(Mat* src1, Mat* src2, float alpha, Mat* dst , uint32 flags )
{
	int i, j, k, iend, jend, kend;
	float sum;
	Mat *A = src1;
	Mat *B = src2;
	Mat *D = dst;

	// Are ALL the matrices the same type?
	if(A->type != B->type || A->type != D->type )
	{
		mZero(D);
		return mError(MAT_ERROR_MISMATCHED_TYPES);
	}
	
	// Are A and B multiliable?
	{
		int A_dimension = (flags & MUL_A_T) ? A->rows : A->cols;
		int B_dimension = (flags & MUL_B_T) ? B->cols : B->rows;

		if(A_dimension != B_dimension)
		{
			mZero(D);
			return mError(MAT_MUL_ERROR_MISMATCHED_SIZE_AB);
		}
	}

	//Does the destination have the corerct number of rows?
	{
		int A_dimension = (flags & MUL_A_T) ? A->cols : A->rows;
		int D_dimension = (flags & MUL_D_T) ? D->cols : D->rows;

		if(A_dimension != D_dimension)
		{
			mZero(D);
			return mError(MAT_MUL_ERROR_MISMATCHED_ROWS_D);
		}
	}

	//Does the destination have the corerct number of cols?
	{
		int B_dimension = (flags & MUL_B_T) ? B->rows : B->cols;
		int D_dimension = (flags & MUL_D_T) ? D->rows : D->cols;

		if(B_dimension != D_dimension)
		{
			mZero(D);
			return mError(MAT_MUL_ERROR_MISMATCHED_COLS_D);
		}
	}

	
	iend = (flags & MUL_B_T) ? B->rows : B->cols;
	jend = (flags & MUL_A_T) ? A->cols : A->rows;
	kend = (flags & MUL_A_T) ? A->rows : A->cols;

	switch(flags){
	case 0:	
		/* No transposes. Straight multiply 
		 * indexes:
		 * i = bcol, dcol
		 * j = arow, drow
		 * k = acol, brow
		 */			
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{				
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,j,k) * mGet(B,k,i);
				mSet(D,j,i,alpha*sum);
			}
		}	
		break;		

	case MUL_A_T:
		/* Transpose: A
		 * indexes:
		 * i = bcol, dcol
		 * j = acol, drow
		 * k = arow, brow
		 */				
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,k,i);
				mSet(D,j,i,alpha*sum);
			}
		}	
		break;		

	case MUL_B_T:
		/* Transpose: B
		 * indexes:
		 * i = brow, dcol
		 * j = arow, drow
		 * k = acol, bcol
		 */		
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)				
					sum += mGet(A,j,k) * mGet(B,i,k);				
				mSet(D,j,i,alpha*sum);
			}
		}	
		break;

	case MUL_B_T | MUL_A_T:	
		/* Transpose: A,B
		 * indexes:
		 * i = brow, dcol
		 * j = acol, drow
		 * k = arow, bcol
		 */		
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,i,k);
				mSet(D,j,i,alpha*sum);
			}
		}
		break;

	case MUL_D_T:	
		/* Transpose: D
		 * indexes:
		 * i = bcol, drow
		 * j = arow, dcol
		 * k = acol, brow
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,j,k) * mGet(B,k,i);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;

	case MUL_D_T | MUL_A_T:	
		/* Transpose: D,A
		 * indexes:
		 * i = bcol, drow
		 * j = acol, dcol
		 * k = arow, brow
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,k,i);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;

	case MUL_D_T | MUL_B_T:	
		/* Transpose: D,B
		 * indexes:
		 * i = brow, drow
		 * j = arow, dcol
		 * k = acol, bcol
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,j,k) * mGet(B,i,k);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;

	case MUL_D_T | MUL_B_T | MUL_A_T:
		/* Transpose: D,B,A
		 * indexes:
		 * i = brow, drow
		 * j = acol, dcol
		 * k = arow, bcol
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,i,k);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;
	}

	return MAT_OK;
}
Beispiel #2
0
// New, very very fast function. The only one who should be used, if fact
int mpkgSys::requestInstall(vector<string> package_name, vector<string> package_version, vector<string> package_build, mpkgDatabase *db, DependencyTracker *DepTracker, vector<string> *eList) {
	
	// First of all, check for local packages
	
	vector<int> localPackages;
	vector<bool> isLocal(package_name.size(), false);
	LocalPackage *_p;
	string pkgType;
	for (size_t i=0; i<package_name.size(); i++) {
		pkgType=getExtension(package_name[i]);
		if (pkgType=="txz" || pkgType == "tbz" || pkgType == "tlz" || pkgType=="tgz" || pkgType == "spkg") {
		       if (FileExists(package_name[i])) {
				_p = new LocalPackage(package_name[i]);
				_p->injectFile();
				db->emerge_to_db(&_p->data);
				package_name[i] = _p->data.get_name();
				package_version[i] = _p->data.get_version();
				package_build[i] = _p->data.get_build();
				isLocal[i]=true;
				//printf("\nDetected local package\nFilename: %s\nName:%s\nVersion:%s\n", _p->data.get_filename().c_str(), _p->data.get_name().c_str(), _p->data.get_version().c_str());
				localPackages.push_back(_p->data.get_id());
				delete _p;
			}
		}
	}
	vector<string> errorList;
	//printf("using error list\n");
	// Creating DB cache
	// 1. Creating a request for all packages which are in package_name vector.
	SQLRecord sqlSearch;
	sqlSearch.setSearchMode(SEARCH_IN);
	for (size_t i=0; i<package_name.size(); i++) {
		if (isLocal[i]) {
			continue;
		}
		sqlSearch.addField("package_name", package_name[i]);
	}
	// 2. Requesting database by search array
	PACKAGE_LIST pCache;
	//printf("SLOW GET_PACKAGELIST CALL: %s %d\n", __func__, __LINE__);
	int query_ret = db->get_packagelist(sqlSearch, &pCache, true, false);
	if (query_ret != 0) {
		errorList.push_back(mError("Error querying database"));
		if (eList) *eList = errorList;
		return MPKGERROR_SQLQUERYERROR;
	}
	// 3. Temporary matrix, temporary list (for each package), and result list
	vector<PACKAGE_LIST> tmpMatrix;
	PACKAGE_LIST *tmpList=new PACKAGE_LIST;
	PACKAGE_LIST resultList;
	PACKAGE_LIST uninstallList;
	// 4. Search by cache for installed ones, check for availability and select the appropriate versions
	// 4.1 Building matrix: one vector per list of packages with same name
	for (size_t i=0; i<package_name.size(); i++) {
		delete tmpList;
		tmpList = new PACKAGE_LIST;
		for (size_t t=0; t<pCache.size(); t++) {
			if (pCache.at(t).get_name() == package_name[i]) {
				if (isLocal[i] && pCache[t].get_id()!=localPackages[i]) continue;
				tmpList->add(pCache.at(t));
			}
		}
		tmpMatrix.push_back(*tmpList);
	}
	//printf("tmpMatrix[0] size = %d\n", tmpMatrix[0].size());
	// So, the matrix has been created.
	// In case of any error, collect all of them, and return MPKGERROR_IMPOSSIBLE
	
	// Sizes of tmpMatrix and input vectors are the same, so we can use any of them
	PACKAGE *outPackage = NULL, *installedOne = NULL;
	for (size_t i=0; i<tmpMatrix.size(); i++) {
		delete tmpList;
		tmpList = new PACKAGE_LIST;
		for (size_t t=0; t<tmpMatrix[i].size(); t++) {
			// Filling the tmpList with reachable (=installed or available) ones for each package
			if (tmpMatrix[i].at(t).available(true) || tmpMatrix[i].at(t).installed()) {
				if (package_version[i].empty() || tmpMatrix[i].at(t).get_version() == package_version[i]) {
					if (package_build[i].empty() || package_build[i]==tmpMatrix[i].at(t).get_build()) tmpList->add(tmpMatrix[i][t]);
				}
			}
		}
		// Now, we have a list of all good candidates. We will filter already installed ones separately for better UI output.
		tmpList->initVersioning();
		outPackage = tmpList->getMaxVersion();
		//if (outPackage) printf("outPackage VERSION: %s\n", outPackage->get_fullversion().c_str());
		installedOne = (PACKAGE *) tmpMatrix[i].getInstalledOne();
		if (outPackage == NULL) {
			string errorText = _("Requested package ") + package_name[i];
		       	if (!package_version[i].empty()) errorText += "-" + package_version[i];
			if (!package_build[i].empty()) errorText += "-" + package_build[i];
			if (!installedOne) errorList.push_back(mError(errorText + _(" cannot be found")));
			else errorList.push_back(mError(errorText + _(" is already installed")));
		}
		else {
			//printf("____________________________CHECK FOR UPDATE, installedOne: %p_____________________________\n", installedOne);
			// Check for update
			if (installedOne && outPackage->get_id() != installedOne->get_id()) {
				// This is update
				//printf("added to uninstall: %d\n", installedOne->get_id());
				uninstallList.add(*installedOne);
			}
			resultList.add(*outPackage);
		}
	}
	delete tmpList;
	// Special addition for local packages installed using -z key: check for installed one
	for (size_t i=0; i<isLocal.size(); ++i) {
		if (!isLocal[i]) continue;
		for (size_t t=0; t<pCache.size(); ++t) {
			if (pCache[t].installed() && pCache[t].get_id()!=localPackages[i] && pCache[t].get_name()==package_name[i]) {
				requestUninstall(pCache.get_package_ptr(t), db, DepTracker);
			}
		}
	}
	// Now, check resultList for installed ones and unavailable ones
	for (size_t i=0; i<resultList.size(); i++) {
		if (resultList[i].installed()) {
			mWarning(_("Package ") + resultList[i].get_name() + "-" + resultList[i].get_fullversion() + _(" is already installed"));
		} 
		else {
			if (!resultList[i].available(true)) {
				errorList.push_back(mError(_("Package ") + resultList[i].get_name() + "-" + resultList[i].get_fullversion() + _(" is unavailable")));
			}
		}
	}
	// NEW: ignore already installed packages
	tmpList = new PACKAGE_LIST;
	for (size_t i=0; i<resultList.size(); ++i) {
		if (!resultList[i].installed()) {
			tmpList->add(resultList[i]);
		}
	}
	resultList = *tmpList;
	delete tmpList;
	

	//printf("resultList size = %d\n", resultList.size());
	if (errorList.empty())	{
		// Push to database
		__requestInstallPkgList(&resultList, db, DepTracker);
		for (size_t i=0; i<uninstallList.size(); i++) requestUninstall(uninstallList.get_package_ptr(i), db, DepTracker);

	}
	else {
		mError(_("Errors detected, cannot continue"));
		if (eList) *eList = errorList;
		return MPKGERROR_IMPOSSIBLE;
	}

	if (eList) *eList = errorList;
	return 0;
}
/** Multiply two matricies together (according to matrix algebra) and subtract a 3rd matrix
	This is faster than mGEMM().
	
	\pre
	dst = src1 * src2 - src3;
	\endpre
*/
merror mMulSub(Mat* src1, Mat* src2, Mat* src3, Mat* dst)
{
	int i, j, k, iend, jend, kend;
	int astep, bstep, cstep, dstep;
	float sum;
	float *arow;
	Mat *A = src1;
	Mat *B = src2;
	Mat *C = src3;
	Mat *D = dst;

	// this currently only works for floats. need to add case statement
	if(src1->type != MAT_32F)
	{
		mZero(D);
		return mError(MAT_ERROR_MISMATCHED_TYPES);
	}



	// Are ALL the matrices the same type?
	if(A->type != B->type || A->type != C->type || A->type != D->type)
	{
		mZero(D);
		return mError(MAT_ERROR_MISMATCHED_TYPES);
	}


	// Are A and B multiliable?
	if(A->cols != B->rows)
	{
		mZero(D);
		return mError(MAT_MUL_ERROR_MISMATCHED_SIZE_AB);
	}


	//Does the destination have the corerct number of rows?
	if(A->rows != D->rows)
	{
		mZero(D);
		return mError(MAT_MUL_ERROR_MISMATCHED_ROWS_D);
	}


	//Does the destination have the corerct number of cols?
	if(B->cols != D->cols)
	{
		mZero(D);
		return mError(MAT_MUL_ERROR_MISMATCHED_COLS_D);
	}


	iend = B->cols;
	jend = A->rows;
	kend = A->cols;

	astep = A->cols;
	bstep = B->cols;
	cstep = C->cols;
	dstep = D->cols;

	/* No transposes. Straight multiply 
	 * indexes:
	 * i = bcol, dcol
	 * j = arow, drow
	 * k = acol, brow
	 */			
	for(i = 0 ; i < iend ; i++)
	{
		for(j = 0 ; j < jend ; j++)
		{			
			arow = &A->data.fl[j*astep];
			for(k = 0, sum = 0 ; k < kend ; k++)
			{
				sum += arow[k] * B->data.fl[k*bstep + i];
				//sum += mGet(A,j,k) * mGet(B,k,i);
			}
			D->data.fl[j*dstep + i] = sum - C->data.fl[j*cstep + i];
			//mSet(D,j,i,sum - mGet(C,j,i));
		}
	}

	return MAT_OK;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    int error;
    MIDASmodule module;
    MIDASmodulePlayHandle playHandle;
    static mEchoHandle eh;

    MIDASstartup();

    puts("MIDAS echo effect engine test\n");

    if ( argc != 2 )
    {
        puts("Usage: echo module");
        return 1;
    }

    MIDASsetOption(MIDAS_OPTION_MIXING_MODE, MIDAS_MIX_HIGH_QUALITY);
    if ( !MIDASinit() )
        MIDASerror();
    if ( !MIDASstartBackgroundPlay(0) )
        MIDASerror();

    if ( (error = mEchoInit()) != OK )
        mError(error);

    if ( (module = MIDASloadModule(argv[1])) == NULL )
        MIDASerror();
    
    if ( (playHandle = MIDASplayModule(module, TRUE)) == 0 )
        MIDASerror();

    
    if ( (error = mEchoAddEffect(&simpleEcho, &eh)) != OK )
        mError(error);

    puts("Simple echo - press any key");
    getch();

    if ( (error = mEchoRemoveEffect(eh)) != OK )
        mError(error);

    if ( (error = mEchoAddEffect(&reverseEcho, &eh)) != OK )
        mError(error);

    puts("Channel-reverse echo - press any key");
    getch();

    if ( (error = mEchoRemoveEffect(eh)) != OK )
        mError(error);

    puts("No echo - press any key");
    getch();

    if ( !MIDASstopModule(playHandle) )
        MIDASerror();
    if ( !MIDASfreeModule(module) )
        MIDASerror();

    if ( (error = mEchoClose()) != OK )
        mError(error);
    
    if ( !MIDASstopBackgroundPlay() )
        MIDASerror();
    if ( !MIDASclose() )
        MIDASerror();

    return 0;
}
Beispiel #5
0
void Dialog::execAddableList(string header, vector<string> *menuItems, string tagLimiter)
{
	// Legend:
	// tagLimiter, for exapmle, may be equal to "://" - this means that the value of "ftp://something.com" will be splitted in next way:
	// 	ftp will be a value (or assotiated comment using internal database), and something.com will be a tag.
	string tmp_file, exec_str, value;
	vector<TagPair> menuList;
	vector<string> tmpList;
	int ret;
	unsigned int pos;
	tmp_file = get_tmp_file();

begin:
	exec_str = dialog + " --ok-label \"Удалить\" --cancel-label \"Продолжить\" --extra-button --extra-label \"Добавить\" --menu \"" + header + "\" " + \
			   IntToStr(0) + " " + IntToStr(0) + " " + IntToStr(0);

	menuList.clear();
	if (!tagLimiter.empty())
	{
		for (unsigned int i=0; i<menuItems->size(); i++)
		{
			pos = menuItems->at(i).find(tagLimiter);
			if (pos!=std::string::npos)
			{
				menuList.push_back(TagPair(menuItems->at(i), resolveComment(menuItems->at(i).substr(0, pos))));
			}
			else
			{
				menuList.push_back(TagPair(menuItems->at(i), "Некорректный URL"));
			}
		}
	}
	for (unsigned int i=0; i<menuList.size(); i++)
	{
		exec_str += " \"" + menuList[i].tag + "\" \"" + menuList[i].value + "\" ";
	}
	exec_str += " 2>"+tmp_file;
	ret = system(exec_str.c_str());
	printf("returned %i\n", ret);
	switch(ret)
	{
		case 256: // OK button
			printf("Ok\n");
			return;
			break;
		case 768: // Add button
			value = execInputBox("Введите URL репозитория:", "");
			if (!value.empty())
			{
				menuItems->push_back(value);
			}
			goto begin;
			break;
		case 0:	// Delete button
			mError("delete button");
			value = getReturnValue(tmp_file);
			if (!value.empty())
			{
				if (menuList.size()==1)
				{
					execMsgBox("Список не может быть пустым. Сначала добавьте еще что-нибудь");
					goto begin;
				}
				for (unsigned int i=0; i<menuList.size(); i++)
				{
					if (menuList[i].tag == value)
					{
						tmpList.clear();
						for (unsigned int t=0; t<menuItems->size(); t++)
						{
							if (menuItems->at(t)!=value)
							{
								tmpList.push_back(menuItems->at(t));
							}
						}
						*menuItems = tmpList;
						tmpList.clear();
						mDebug("Deleted " + value);
						goto begin;
					}
				}
				mError("out of cycle");
				goto begin;
			}
			else
			{
				mDebug("empty value");
			}
			goto begin;
			break;
		default: // Cancel, ESC, and other errors
			mError(exec_str);
			mDebug("Returned " +  IntToStr(ret));
			sleep(2);
			
			return;		
/*			if (execYesNo("Действительно прервать?")) abort();
			else goto begin;*/
	}
}
Beispiel #6
0
int main(int argc, char *argv[]) {
	// This should be run as root since libparted requires it.
	if (getuid()) {
		// trying to obtain root UID
		setuid(0);
		if (getuid()) {
			string args;
			for (int i=1; i<argc; ++i) {
				args += string(argv[i]) + " ";
			}
			// Check if we can run via sudo
			if (system("[ \"`sudo -l | grep " + string(argv[0]) + " | grep NOPASSWD`\" = \"\" ]")) return system("sudo " + string(argv[0]) + " " + args);
			else return system("xdg-su -c \"" + string(argv[0]) + " " + args + "\"");
		}
	}
	if (FileExists("/var/run/guisetup_exec.pid")) {
		string pid_locked = ReadFile("/var/run/guisetup_exec.pid").c_str();
		if (isProcessRunning(pid_locked)) {
			fprintf(stderr, "Another setup process %s is alrealy running.\n", pid_locked.c_str());
			return 1;
		}
	}
	pid_t pid = getpid();
	
	
	if (FileExists("/var/run/guisetup.pid")) {
		string pid_locked = ReadFile("/var/run/guisetup.pid").c_str();
		if (isProcessRunning(pid_locked)) {
			fprintf(stderr, "Another setup process %s is alrealy running.\n", pid_locked.c_str());
			return 1;
		}
	}
	WriteFile("/var/run/guisetup.pid", IntToStr(pid));


	setlocale(LC_ALL, "");
	bindtextdomain( "mpkg", "/usr/share/locale");
	textdomain("mpkg");
	
	// For mpkg, note that we copy config to temp directory	
	CONFIG_FILE="/tmp/mpkg.xml";
	mConfig.configName=CONFIG_FILE;
	unlink("/tmp/packages.db");
	unlink("/tmp/mpkg.xml");
	if (!FileExists("/usr/share/setup/packages.db")) {
		mError("Oops, no database template in /usr/share/setup/packages.db!");
		return 1;
	}
	if (!FileExists("/usr/share/setup/mpkg-setup.xml")) {
		mError("Oops, no config template in /usr/share/setup/mpkg-setup.xml!");
		return 1;
	}
	system("cp /usr/share/setup/packages.db /tmp/packages.db");
	system("cp /usr/share/setup/mpkg-setup.xml /tmp/mpkg.xml");

	QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
	QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
	QApplication a(argc, argv);
	QLocale lc;
	QTranslator translator;
	translator.load("guisetup_" + lc.name(), "/usr/share/setup/l10n");
	a.installTranslator(&translator);

	MainWindow w;
	w.show();
	return a.exec();
}
Beispiel #7
0
mpkgErrorReturn callError(mpkgErrorCode err, string details)
{
	setErrorCode(err);
	errorDescription e;
	int ret=0;
	Dialog d(_("error"), "MOPSLinux package system");
	vector<string> menuItems;
	for (unsigned int i=0; i<errorList.size(); i++)
	{
		if (errorList[i].code==err)
		{
			e=errorList[i];
			break;
		}
	}
	
	switch(errorManagerMode)
	{
		case EMODE_CONSOLE:
			// Ugly console mode
			if (e.action.size()==1) // If we have no choice..
			{
				if (e.action[0].ret==MPKG_RETURN_CONTINUE) 
				{
					say("%s\n",e.text.c_str());
					if (!details.empty()) say(_("Details: %s\n"),details.c_str());
				}
				else 
				{
					mError(e.text);
					if (!details.empty()) mError(_("Details: ") + details);
				}
				setErrorReturn(e.action[0].ret);
				break;
			}
			mError(e.text);
eCLI_pickAction:
			mError(_("Choose an action:"));
			for (unsigned int x=0; x<e.action.size(); x++)
			{
				say("\t[%d]  %s\n",x+1, e.action[x].text.c_str());
			}
			cin>>ret;
			if (ret>0 && (unsigned int) ret<=e.action.size())
			{
				// Return value OK, returning
				say(_("You decided to %s\n"), e.action[ret-1].text.c_str());
				setErrorReturn(e.action[ret-1].ret);
			}
			else 
			{
				say(_("Invalid input\n"));
				goto eCLI_pickAction;
			}

			break;
		case EMODE_DIALOG:
		
			if (!details.empty()) details = "\nDetails: " + details;
			// Call dialog event resolver
			for (unsigned int i=0; i<e.action.size(); i++)
			{
				menuItems.push_back(e.action[i].text);
			}
			if (e.action.size()==1) // If we have no choice..
			{
				if (e.action[0].ret==MPKG_RETURN_CONTINUE) 
				{
					d.setTitle("Information", "MOPSLinux package system");
					d.execInfoBox(e.text + details);
				}
				else
				{
					mError(e.text);
					d.execMsgBox(e.text + details);
				}
				setErrorReturn(e.action[0].ret);
				break;
			}

			ret = d.execMenu(e.text, menuItems);
			if (ret>=0 && (unsigned int) ret<e.action.size())
			{
				setErrorReturn(e.action[ret].ret);
			}
			else 
			{
				mError("Aborted");
			}
			break;
		case EMODE_QT:
			// Waiting for GUI error catcher (threaded)
			while ( getErrorReturn() == MPKG_RETURN_WAIT)
			{
				sleep(1);
			}
			break;

		default:
			mError("Unknown UI mode, aborting");
			say("errorManagerMode is %d\n", errorManagerMode);
			if (consoleMode) mError("consoleMode: true");
			else mError("consoleMode: false");
			if (dialogMode) mError("dialogMode: true");
			else mError("dialogMode: false");

			abort();
	}
	return getErrorReturn();
}
Beispiel #8
0
void generateDeps(string tgz_filename, bool updateOnly)
{
	if (mConfig.getValue("add_deps_in_build")=="yes") updateOnly=false;
	if (tgz_filename.empty()) {
		mError("No filename specified");
		return;
	}
	say("Generating dependencies for %s\n",tgz_filename.c_str());
	string current_dir = (string) get_current_dir_name();
	// Create a temporary directory
	string tmpdir = get_tmp_file();
	string dep_out = get_tmp_file();
	unlink(tmpdir.c_str());
	system("mkdir -p " + tmpdir);
	say("Extracting\n");
	system("tar zxf " + tgz_filename + " -C " + tmpdir);
	PackageConfig *p = new PackageConfig(tmpdir+"/install/data.xml");
	PACKAGE pkg;
	if (p->parseOk) xml2package(p->getXMLNode(), &pkg);
	delete p;
	say("Building dependencies\n");
	
	system("env LC_ALL=C requiredbuilder -n -v " + tgz_filename + " > "+ dep_out);
	vector<string> data = ReadFileStrings(dep_out);
	
	string tmp;
	string tail;
	DEPENDENCY d;
	//pkg.get_dependencies()->clear();
	string condptr;
	for (unsigned int i=0; i<data.size(); i++)
	{
		tmp = data[i].substr(0,data[i].find_first_of(" "));
		tail = data[i].substr(tmp.length()+1);
		d.set_package_name(&tmp);

		tmp = tail.substr(0, tail.find_first_of(" "));
		tail = tail.substr(tmp.length()+1);
		condptr=IntToStr(condition2int(hcondition2xml(tmp)));
		d.set_condition(&condptr);

		tmp = tail.substr(0,tail.find_first_of("-"));
		d.set_package_version(&tmp);
		if (*d.get_package_name()!=*pkg.get_name()) {
			// Checking existing dependencies
			bool added=false;
			for (unsigned int t=0; t<pkg.get_dependencies()->size(); t++) {
				if (*d.get_package_name()==*pkg.get_dependencies()->at(t).get_package_name()) {
					pkg.get_dependencies()->at(t) = d;
					added=true;
				}
			}
			if (!added) {
				if (updateOnly) mWarning("Found (possible) missing dependencies: " + d.getDepInfo());
				else pkg.get_dependencies()->push_back(d);
			}
		}
	}
	say(_("Got %d dependencies\n"), pkg.get_dependencies()->size());
	p = new PackageConfig(tmpdir+"/install/data.xml");
	dumpPackage(&pkg, p, tmpdir+"/install/data.xml");
	delete p;
	if (tgz_filename[0]!='/') tgz_filename = current_dir + "/"+getDirectory(tgz_filename);
	system ("cd " + tmpdir + "; buildpkg " + tgz_filename );
	system("rm -rf " + tmpdir);
	delete_tmp_files();
}