示例#1
0
文件: main.cpp 项目: GitCrush/dynare
int main(int argc, char** argv)
{
    DynareParams params(argc, argv);
    if (params.help) {
        params.printHelp();
        return 0;
    }
    if (params.version) {
        printf("Dynare++ v. %s. Copyright (C) 2004-2011, Ondra Kamenik\n",
               DYNVERSION);
        printf("Dynare++ comes with ABSOLUTELY NO WARRANTY and is distributed under\n");
        printf("GPL: modules integ, tl, kord, sylv, src, extern and documentation\n");
        printf("LGPL: modules parser, utils\n");
        printf(" for GPL  see http://www.gnu.org/licenses/gpl.html\n");
        printf(" for LGPL see http://www.gnu.org/licenses/lgpl.html\n");
        return 0;
    }
    THREAD_GROUP::max_parallel_threads = params.num_threads;

    try {
        // make journal name and journal
        std::string jname(params.basename);
        jname += ".jnl";
        Journal journal(jname.c_str());

        // make dynare object
        Dynare dynare(params.modname, params.order, params.ss_tol, journal);
        // make list of shocks for which we will do IRFs
        vector<int> irf_list_ind;
        if (params.do_irfs_all)
            for (int i = 0; i < dynare.nexog(); i++)
                irf_list_ind.push_back(i);
        else
            irf_list_ind = ((const DynareNameList&)dynare.getExogNames()).selectIndices(params.irf_list);

        // write matlab files
        FILE* mfd;
        std::string mfile1(params.basename);
        mfile1 += "_f.m";
        if (NULL == (mfd=fopen(mfile1.c_str(), "w"))) {
            fprintf(stderr, "Couldn't open %s for writing.\n", mfile1.c_str());
            exit(1);
        }
        ogdyn::MatlabSSWriter writer0(dynare.getModel(), params.basename.c_str());
        writer0.write_der0(mfd);
        fclose(mfd);

        std::string mfile2(params.basename);
        mfile2 += "_ff.m";
        if (NULL == (mfd=fopen(mfile2.c_str(), "w"))) {
            fprintf(stderr, "Couldn't open %s for writing.\n", mfile2.c_str());
            exit(1);
        }
        ogdyn::MatlabSSWriter writer1(dynare.getModel(), params.basename.c_str());
        writer1.write_der1(mfd);
        fclose(mfd);

        // open mat file
        std::string matfile(params.basename);
        matfile += ".mat";
        mat_t* matfd = Mat_Create(matfile.c_str(), NULL);
        if (matfd == NULL) {
            fprintf(stderr, "Couldn't open %s for writing.\n", matfile.c_str());
            exit(1);
        }

        // write info about the model (dimensions and variables)
        dynare.writeMat(matfd, params.prefix);
        // write the dump file corresponding to the input
        dynare.writeDump(params.basename);


        system_random_generator.initSeed(params.seed);

        tls.init(dynare.order(),
                 dynare.nstat()+2*dynare.npred()+3*dynare.nboth()+
                 2*dynare.nforw()+dynare.nexog());

        Approximation app(dynare, journal, params.num_steps, params.do_centralize, params.qz_criterium);
        try {
            app.walkStochSteady();
        } catch (const KordException& e) {
            // tell about the exception and continue
            printf("Caught (not yet fatal) Kord exception: ");
            e.print();
            JournalRecord rec(journal);
            rec << "Solution routine not finished (" << e.get_message()
                << "), see what happens" << endrec;
        }

        std::string ss_matrix_name(params.prefix);
        ss_matrix_name += "_steady_states";
        ConstTwoDMatrix(app.getSS()).writeMat(matfd, ss_matrix_name.c_str());

        // check the approximation
        if (params.check_along_path || params.check_along_shocks
                || params.check_on_ellipse) {
            GlobalChecker gcheck(app, THREAD_GROUP::max_parallel_threads, journal);
            if (params.check_along_shocks)
                gcheck.checkAlongShocksAndSave(matfd, params.prefix,
                                               params.getCheckShockPoints(),
                                               params.getCheckShockScale(),
                                               params.check_evals);
            if (params.check_on_ellipse)
                gcheck.checkOnEllipseAndSave(matfd, params.prefix,
                                             params.getCheckEllipsePoints(),
                                             params.getCheckEllipseScale(),
                                             params.check_evals);
            if (params.check_along_path)
                gcheck.checkAlongSimulationAndSave(matfd, params.prefix,
                                                   params.getCheckPathPoints(),
                                                   params.check_evals);
        }

        // write the folded decision rule to the Mat-4 file
        app.getFoldDecisionRule().writeMat(matfd, params.prefix);

        // simulate conditional
        if (params.num_condper > 0 && params.num_condsim > 0) {
            SimResultsDynamicStats rescond(dynare.numeq(), params.num_condper, 0);
            ConstVector det_ss(app.getSS(),0);
            rescond.simulate(params.num_condsim, app.getFoldDecisionRule(), det_ss, dynare.getVcov(), journal);
            rescond.writeMat(matfd, params.prefix);
        }

        // simulate unconditional
        //const DecisionRule& dr = app.getUnfoldDecisionRule();
        const DecisionRule& dr = app.getFoldDecisionRule();
        if (params.num_per > 0 && params.num_sim > 0) {
            SimResultsStats res(dynare.numeq(), params.num_per, params.num_burn);
            res.simulate(params.num_sim, dr, dynare.getSteady(), dynare.getVcov(), journal);
            res.writeMat(matfd, params.prefix);

            // impulse response functions
            if (! irf_list_ind.empty()) {
                IRFResults irf(dynare, dr, res, irf_list_ind, journal);
                irf.writeMat(matfd, params.prefix);
            }
        }

        // simulate with real-time statistics
        if (params.num_rtper > 0 && params.num_rtsim > 0) {
            RTSimResultsStats rtres(dynare.numeq(), params.num_rtper, params.num_burn);
            rtres.simulate(params.num_rtsim, dr, dynare.getSteady(), dynare.getVcov(), journal);
            rtres.writeMat(matfd, params.prefix);
        }

        Mat_Close(matfd);

    } catch (const KordException& e) {
        printf("Caugth Kord exception: ");
        e.print();
        return e.code();
    } catch (const TLException& e) {
        printf("Caugth TL exception: ");
        e.print();
        return 255;
    } catch (SylvException& e) {
        printf("Caught Sylv exception: ");
        e.printMessage();
        return 255;
    } catch (const DynareException& e) {
        printf("Caught Dynare exception: %s\n", e.message());
        return 255;
    } catch (const ogu::Exception& e) {
        printf("Caught ogu::Exception: ");
        e.print();
        return 255;
    } catch (const ogp::ParserException& e) {
        printf("Caught parser exception: %s\n", e.message());
        return 255;
    }

    return 0;
}
void tst_QScriptJSTestSuite::runTestFunction(int testIndex)
{
    if (!(testIndex & 1)) {
        // data
        QTest::addColumn<TestRecord>("record");
        bool hasData = false;

        QString testsShellPath = testsDir.absoluteFilePath("shell.js");
        QString testsShellContents = readFile(testsShellPath);

        QDir subSuiteDir(subSuitePaths.at(testIndex / 2));
        QString subSuiteShellPath = subSuiteDir.absoluteFilePath("shell.js");
        QString subSuiteShellContents = readFile(subSuiteShellPath);

        QDir testSuiteDir(subSuiteDir);
        testSuiteDir.cdUp();
        QString suiteJsrefPath = testSuiteDir.absoluteFilePath("jsref.js");
        QString suiteJsrefContents = readFile(suiteJsrefPath);
        QString suiteShellPath = testSuiteDir.absoluteFilePath("shell.js");
        QString suiteShellContents = readFile(suiteShellPath);

        QFileInfoList testFileInfos = subSuiteDir.entryInfoList(QStringList() << "*.js", QDir::Files);
        foreach (QFileInfo tfi, testFileInfos) {
            if ((tfi.fileName() == "shell.js") || (tfi.fileName() == "browser.js"))
                continue;

            QString abspath = tfi.absoluteFilePath();
            QString relpath = testsDir.relativeFilePath(abspath);
            QString excludeMessage;
            if (isExcludedFile(relpath, &excludeMessage)) {
                QTest::newRow(relpath.toLatin1()) << TestRecord(excludeMessage, relpath);
                continue;
            }

            QScriptEngine eng;
            QScriptValue global = eng.globalObject();
            global.setProperty("print", eng.newFunction(qscript_void));
            global.setProperty("quit", eng.newFunction(qscript_quit));
            global.setProperty("options", eng.newFunction(qscript_options));

            eng.evaluate(testsShellContents, testsShellPath);
            if (eng.hasUncaughtException()) {
                QStringList bt = eng.uncaughtExceptionBacktrace();
                QString err = eng.uncaughtException().toString();
                qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
                break;
            }

            eng.evaluate(suiteJsrefContents, suiteJsrefPath);
            if (eng.hasUncaughtException()) {
                QStringList bt = eng.uncaughtExceptionBacktrace();
                QString err = eng.uncaughtException().toString();
                qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
                break;
            }

            eng.evaluate(suiteShellContents, suiteShellPath);
            if (eng.hasUncaughtException()) {
                QStringList bt = eng.uncaughtExceptionBacktrace();
                QString err = eng.uncaughtException().toString();
                qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
                break;
            }

            eng.evaluate(subSuiteShellContents, subSuiteShellPath);
            if (eng.hasUncaughtException()) {
                QStringList bt = eng.uncaughtExceptionBacktrace();
                QString err = eng.uncaughtException().toString();
                qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
                break;
            }

            QScriptValue origTestCaseCtor = global.property("TestCase");
            QScriptValue myTestCaseCtor = eng.newFunction(qscript_TestCase);
            myTestCaseCtor.setData(origTestCaseCtor);
            global.setProperty("TestCase", myTestCaseCtor);

            global.setProperty("gTestfile", tfi.fileName());
            global.setProperty("gTestsuite", testSuiteDir.dirName());
            global.setProperty("gTestsubsuite", subSuiteDir.dirName());
            QString testFileContents = readFile(abspath);
//                qDebug() << relpath;
            eng.evaluate(testFileContents, abspath);
            if (eng.hasUncaughtException() && !relpath.endsWith("-n.js")) {
                QStringList bt = eng.uncaughtExceptionBacktrace();
                QString err = eng.uncaughtException().toString();
                qWarning("%s\n%s\n", qPrintable(err), qPrintable(bt.join("\n")));
                continue;
            }

            QScriptValue testcases = global.property("testcases");
            if (!testcases.isArray())
                testcases = global.property("gTestcases");
            int count = testcases.property("length").toInt32();
            if (count == 0)
                continue;

            hasData = true;
            QString title = global.property("TITLE").toString();
            for (int i = 0; i < count; ++i) {
                QScriptValue kase = testcases.property(i);
                QString description = kase.property("description").toString();
                QScriptValue expect = kase.property("expect");
                QScriptValue actual = kase.property("actual");
                bool passed = kase.property("passed").toBoolean();
                int lineNumber = kase.property("__lineNumber__").toInt32();

                TestRecord rec(description, passed,
                               actual.toString(), expect.toString(),
                               relpath, lineNumber);

                QTest::newRow(description.toLatin1()) << rec;
            }
        }
        if (!hasData)
            QTest::newRow("") << TestRecord(); // dummy
    } else {
pgsRecord pgsNumber::record() const
{
	pgsRecord rec(1);;
	rec.insert(0, 0, this->clone());
	return rec;
}
示例#4
0
 int numDecodings(string s) {
     memset(dp, -1, sizeof(dp));
     return rec(0, s);
 }
 int minDepth(TreeNode* root) {
     if(root == NULL) return 0;
     return rec(root);
 }
示例#6
0
	static inline A0 cot_eval(const A0& z, const A0&,  const int n )
	{
	  const A0 y = base_tan_eval(z); 
	  if (n == 1) return rec(y);  else return -y; 
	}
示例#7
0
void rec(int M1[5][5], int M2[5][5], int i, int j)
{int I,J;
z++;
if(z>3000)
{
	//printf("\nzzzzzzzzzzz\n");
	int flag=1,r=0,c=0,ii,jj,f=0,k,p=pc;
	//display(aa);
	for(k=0;k<25;k++){
		if(aa[aai[k]][aaj[k]]/10==p)
		{	r=aai[k];c=aaj[k]; ////printf("\ntrap : %d %d\n",r,c);
		break;}
	}
	
	
if((aa[0][0]/10==0 && aa[0][1]/10==3-p && aa[1][0]/10==3-p))
		{
			r=0;c=0;	//printf("\ntrap1 : %d %d\n",r,c);
		}
		else if((aa[0][4]/10==0 && aa[0][3]/10==3-p && aa[1][4]/10==3-p))
		{
			r=0;c=4;
		}
		else if((aa[4][0]/10==0 && aa[4][1]/10==3-p && aa[3][0]/10==3-p))
		{
			r=4;c=0;
		}
		else if((aa[4][4]/10==0 && aa[3][4]/10==3-p && aa[4][3]/10==3-p))
		{
			r=4;c=4;
		}
		else if(aa[0][0]==0)
		{r=0;c=0;		//printf("\ntrap2 : %d %d\n",r,c);
		}
		else if(aa[0][4]==0)
		{
			r=0;c=4;
		}
		else if(aa[4][0]==0)
		{
			r=4;c=0;
		}
		else if(aa[4][4]==0)
		{
			r=4;c=4;
		}
		else
		{
			for(k=0;k<9;k++)
			{
				ii=ia[k];jj=ja[k];
				////printf("^^\n%d\n%d\n",ii,jj);
				//	if(aa[i][j]==0 && aa[i-1][j]/10==3-p && aa[i+1][j]/10==3-p && aa[i][j+1]/10==3-p && aa[i][j-1]/10==3-p)
				//	{
				//		r=i;c=j;f=1;break;
				//	}
					if(aa[ii][jj]/10==p && aa[ii][jj]%10==3 && aa[ii-1][jj]/10==3-p && aa[ii+1][jj]/10==3-p && aa[ii][jj+1]/10==3-p && aa[ii][jj-1]/10==3-p)
					{
						r=ii;c=jj;f=1;break;//printf("1 : r:%d c:%d",r,c);
					}
					
			
			}
		
			if(ii==0 && jj>0 && jj<4 && aa[ii][jj]/10==p && aa[ii][jj]%10==2 && aa[ii][jj-1]/10==3-p && aa[ii][jj+1]/10==3-p && aa[ii+1][jj]/10==3-p )
					{
						r=ii;c=jj;////printf("2 : r:%d c:%d",r,c);
					}
			else if(ii==4 && jj<4 && jj>0 && aa[ii][jj]/10==p && aa[ii][jj]%10==2 && aa[ii][jj+1]/10==3-p && aa[ii][jj-1]/10==3-p && aa[ii-1][jj]/10==3-p )
					{
						r=ii;c=jj;////printf("3 : r:%d c:%d",r,c);
					}
			else if(jj==0 && ii>0 && ii<4 && aa[ii][jj]/10==p && aa[ii][jj]%10==2 && aa[ii-1][jj]/10==3-p && aa[ii+1][jj]/10==3-p && aa[ii][jj+1]/10==3-p )
					{
						r=ii;c=jj;////printf("4 : r:%d c:%d",r,c);
					}
			else if(jj==4 && ii>0 && ii<4 && aa[ii][jj]/10==p && aa[ii][jj]%10==2 && aa[ii-1][jj]/10==3-p && aa[ii+1][jj]/10==3-p && aa[ii][jj-1]/10==3-p )
					{
						r=ii;c=jj;////printf("5 : r:%d c:%d",r,c);
					}
			
					
			else if(ii==0 && jj==0 && aa[ii][jj]/10==p && aa[ii+1][jj]/10==3-p && aa[ii][jj+1]/10==3-p)	
			{
				r=ii+1;c=jj;//printf("6 : r:%d c:%d",r,c);
			}
			else if(ii==0 && jj==4 && aa[ii][jj]/10==p && aa[ii+1][jj]/10==3-p && aa[ii-1][jj]/10==3-p)	
			{
				r=ii+1;c=jj;////printf("7 : r:%d c:%d",r,c);
			}
			else if(ii==4 && jj==0 && aa[ii][jj]/10==p && aa[ii-1][jj]/10==3-p && aa[ii][jj+1]/10==3-p)	
			{
				r=ii;c=jj+1;////printf("8 : r:%d c:%d",r,c);
			}	
			else if(ii==4 && jj==4 && aa[ii][jj]/10==p && aa[ii-1][jj]/10==3-p && aa[ii][jj-1]/10==3-p)	
			{
				r=ii-1;c=jj;////printf("9 : r:%d c:%d",r,c);
			}
			
			
			
			
			int var=0,balls=0;f=0;////printf("##\n");
			//display(aa);
			for(k=0;k<9;k++)
			{
				ii=ia[k];jj=ja[k];
				
					if(aa[ii][jj]/10==p && aa[ii][jj]%10==3)
					{
						//printf("\n!!r: %d c: %d\n",ii,jj);
						if(aa[ii][jj-1]/10==p)
							{var++;	balls+=aa[ii][jj-1]%10;}
						if(aa[ii][jj+1]/10==p)
							{var++;	balls+=aa[ii][jj+1]%10;}
						if(aa[ii-1][jj-1]/10==p)
							{var++;	balls+=aa[ii-1][jj-1]%10;}
						if(aa[ii-1][jj+1]/10==p)
							{var++;	balls+=aa[ii-1][jj+1]%10;}
						if(aa[ii-1][jj]/10==p)
							{var++;	balls+=aa[ii-1][jj]%10;}
						if(aa[ii+1][jj-1]/10==p)
							{var++;	balls+=aa[ii+1][jj-1]%10;}
						if(aa[ii+1][jj+1]/10==p)
							{var++;	balls+=aa[ii+1][jj+1]%10;}
						if(aa[ii+1][jj]/10==p)
							{var++;	balls+=aa[ii+1][jj]%10;}
							
						if(var>=3 && balls>=8)
						{
							r=ii;c=jj;f=1;//printf("14 : r:%d c:%d",r,c);
							break;
						}
					}
			
			}
			
			if(aa[0][0]/10==p && aa[0][1]/10==p && aa[1][0]/10==p && aa[0][1]%10==2 && aa[1][0]%10==2 && ((aa[1][1]!=0) || aa[2][0]/10!=0 || aa[0][2]/10!=0))
			{
				r=ii;c=jj;//printf("10 : r:%d c:%d",r,c);
			} 
			else if(aa[4][0]/10==p && aa[3][0]/10==p && aa[4][1]/10==p && aa[4][1]%10==2 && aa[3][0]%10==2 && ((aa[3][1]!=0) || aa[2][0]/10!=0 || aa[4][2]/10!=0))
			{
				r=ii;c=jj;////printf("11 : r:%d c:%d",r,c);
			} 
			else if(aa[4][4]/10==p && aa[4][3]/10==p && aa[3][4]/10==p && aa[3][4]%10==2 && aa[4][3]%10==2 && ((aa[3][3]!=0) || aa[2][4]/10!=0 || aa[4][2]/10!=0))
			{
				r=ii;c=jj;////printf("12 : r:%d c:%d",r,c);
			} 
			else if(aa[0][4]/10==p && aa[0][3]/10==p && aa[1][4]/10==p && aa[0][3]%10==2 && aa[1][4]%10==2 && ((aa[1][3]!=0) || aa[0][2]/10!=0 || aa[2][4]/10!=0))
			{
				r=ii;c=jj;////printf("13 : r:%d c:%d",r,c);
			} 
			
			//printf("\n####\n");
			
			
			if(ii==0 && jj!=0 && jj!=4 && ((aa[ii][jj]%10>0 && aa[ii][jj]/10==p) || aa[ii][jj]==0))
			{
				r=ii;jj=c;////printf("15 : r:%d c:%d",r,c);
			}		
			else if(ii==4 && jj!=0 && jj!=4 && ((aa[ii][jj]%10>0 && aa[ii][jj]/10==p) || aa[ii][jj]==0))
			{
				r=ii;jj=c;////printf("16 : r:%d c:%d",r,c);
			}
			else if(jj==4 && ii!=0 && ii!=4 && ((aa[ii][jj]%10>0 && aa[ii][jj]/10==p) || aa[ii][jj]==0))
			{
				r=ii;jj=c;////printf("17 : r:%d c:%d",r,c);
			}
			else if(jj==0 && ii!=0 && ii!=4 && ((aa[ii][jj]%10>0 && aa[ii][jj]/10==p) || aa[ii][jj]==0))
			{
				r=ii;jj=c;////printf("18 : r:%d c:%d",r,c);
			}
			
			//printf("\n@#\n");
			
			for(k=0;k<9;k++)
			{
				ii=ia[k];jj=ja[k];
				
					if(aa[ii][jj]/10==p && aa[ii][jj]%10>=1 && aa[ii-1][jj]/10==3-p && aa[ii-1][jj]%10!=3 && aa[ii+1][jj]/10==3-p && aa[ii+1][jj]%10!=3  && aa[ii][jj+1]/10==3-p && aa[ii][jj+1]%10!=3  && aa[ii][jj-1]/10==3-p && aa[ii][jj-1]%10!=3 )
					{
						r=ii;c=jj;f=1;////printf("19 : r:%d c:%d",r,c);
						break;
					}		
				
			}
			//printf("!!\n");
		}

printf("%d %d",r,c);
exit(1);
}



if(i == 0 && j == 0)
{
if(M1[i][j]%10>2)
M1[i][j]=pc*10+((M1[i][j]%10)-2);
else
M1[i][j] = 0; 
M1[i+1][j]%=10; M1[i+1][j]= M1[i+1][j]+pc*10+1;   
M1[i][j+1]%=10; M1[i][j+1]= M1[i][j+1]+pc*10+1;
}
else if(i == 0 && j == 4)
{
if(M1[i][j]%10>2)
M1[i][j]=pc*10+((M1[i][j]%10)-2);
else
M1[i][j] = 0; 
M1[i+1][j]%=10; M1[i+1][j]= M1[i+1][j]+pc*10+1;
M1[i][j-1]%=10; M1[i][j-1]= M1[i][j-1]+pc*10+1;
}
else if(i == 4 && j == 0)
{
if(M1[i][j]%10>2)
M1[i][j]=pc*10+((M1[i][j]%10)-2);
else
M1[i][j] = 0; 
M1[i-1][j]%=10; M1[i-1][j]= M1[i-1][j]+pc*10+1;
M1[i][j+1]%=10; M1[i][j+1]= M1[i][j+1]+pc*10+1;
}
else if(i == 4 && j == 4)
{
if(M1[i][j]%10>2)
M1[i][j]=pc*10+((M1[i][j]%10)-2);
else
M1[i][j] = 0; 
M1[i-1][j]%=10; M1[i-1][j]= M1[i-1][j]+pc*10+1;
M1[i][j-1]%=10; M1[i][j-1]= M1[i][j-1]+pc*10+1;
}
else if(j == 0)
{

if(M1[i][j]%10>3)
M1[i][j]=pc*10+((M1[i][j]%10)-3);
else
M1[i][j] = 0; 
M1[i-1][j]%=10; M1[i-1][j]= M1[i-1][j]+pc*10+1;
M1[i+1][j]%=10; M1[i+1][j]= M1[i+1][j]+pc*10+1;
M1[i][j+1]%=10; M1[i][j+1]= M1[i][j+1]+pc*10+1;
}
else if(i == 0)
{

if(M1[i][j]%10>3)
M1[i][j]=pc*10+((M1[i][j]%10)-3);
else
M1[i][j] = 0; 
M1[i][j-1]%=10; M1[i][j-1]= M1[i][j-1]+pc*10+1;
M1[i][j+1]%=10; M1[i][j+1]= M1[i][j+1]+pc*10+1;
M1[i+1][j]%=10; M1[i+1][j]= M1[i+1][j]+pc*10+1;
}
else if(j == 4)
{

if(M1[i][j]%10>3)
M1[i][j]=pc*10+((M1[i][j]%10)-3);
else
M1[i][j] = 0; 
M1[i][j-1]%=10; M1[i][j-1]= M1[i][j-1]+pc*10+1;
M1[i+1][j]%=10; M1[i+1][j]= M1[i+1][j]+pc*10+1;
M1[i-1][j]%=10; M1[i-1][j]= M1[i-1][j]+pc*10+1;
}
else if(i == 4)
{

if(M1[i][j]%10>3)
M1[i][j]=pc*10+((M1[i][j]%10)-3);
else
M1[i][j] = 0; 
M1[i][j-1]%=10; M1[i][j-1]= M1[i][j-1]+pc*10+1;
M1[i][j+1]%=10; M1[i][j+1]= M1[i][j+1]+pc*10+1;
M1[i-1][j]%=10; M1[i-1][j]= M1[i-1][j]+pc*10+1;
}
else
{

if(M1[i][j]%10>4)
M1[i][j]=pc*10+((M1[i][j]%10)-4);
else
M1[i][j] = 0; 
M1[i][j-1]%=10; M1[i][j-1]= M1[i][j-1]+pc*10+1;
M1[i][j+1]%=10; M1[i][j+1]= M1[i][j+1]+pc*10+1;
M1[i+1][j]%=10; M1[i+1][j]= M1[i+1][j]+pc*10+1;
M1[i-1][j]%=10; M1[i-1][j]= M1[i-1][j]+pc*10+1;
}
if(i == 0 && j == 0)
{
if(checkMat(M1,i+1,j) == 1)
rec(M1,M2,i+1,j);
if(checkMat(M1,i,j+1) == 1)
rec(M1,M2,i,j+1);
}
else if(i == 0 && j == 4)
{
if(checkMat(M1,i+1,j) == 1)
rec(M1,M2,i+1,j);
if(checkMat(M1,i,j-1) == 1)
rec(M1,M2,i,j-1);
}
else if(i == 4 && j == 0)
{
if(checkMat(M1,i-1,j) == 1)
rec(M1,M2,i-1,j);
if(checkMat(M1,i,j+1) == 1)
rec(M1,M2,i,j+1);
}
else if(i == 4 && j == 4)
{
if(checkMat(M1,i-1,j) == 1)
rec(M1,M2,i-1,j);
if(checkMat(M1,i,j-1) == 1)
rec(M1,M2,i,j-1);
}
else if(j == 0)
{
if(checkMat(M1,i-1,j) == 1)
{
rec(M1,M2,i-1,j);}
if(checkMat(M1,i+1,j) == 1)
{
rec(M1,M2,i+1,j);}
if(checkMat(M1,i,j+1) == 1)
{
rec(M1,M2,i,j+1);}

}
else if(i == 0)
{
if(checkMat(M1,i,j-1) == 1)
{
rec(M1,M2,i,j-1);}
if(checkMat(M1,i,j+1) == 1)
{
rec(M1,M2,i,j+1);}
if(checkMat(M1,i+1,j) == 1)
{
rec(M1,M2,i+1,j);}
}
else if(j == 4)
{
if(checkMat(M1,i,j-1) == 1)
{
rec(M1,M2,i,j-1);}
if(checkMat(M1,i+1,j) == 1)
{
rec(M1,M2,i+1,j);}
if(checkMat(M1,i-1,j) == 1)
{
rec(M1,M2,i-1,j);}
}
else if(i == 4)
{
if(checkMat(M1,i,j-1) == 1)
{
rec(M1,M2,i,j-1);}
if(checkMat(M1,i,j+1) == 1)
{
rec(M1,M2,i,j+1);}
if(checkMat(M1,i-1,j+1) == 1)
{
rec(M1,M2,i-1,j);}
}
else
{
if(checkMat(M1,i,j-1) == 1)
{
rec(M1,M2,i,j-1);}
if(checkMat(M1,i,j+1) == 1)
{
rec(M1,M2,i,j+1);}
if(checkMat(M1,i+1,j) == 1)
{
rec(M1,M2,i+1,j);}
if(checkMat(M1,i-1,j) == 1)
{rec(M1,M2,i-1,j);}
}
for(I = 0; I < 5; I++)
{
for(J=0;J<5;J++)
M2[I][J] = M1[I][J];
}
}
示例#8
0
void SkPicturePlayback::handleOp(SkReader32* reader,
                                 DrawType op,
                                 uint32_t size,
                                 SkCanvas* canvas,
                                 const SkMatrix& initialMatrix) {
    switch (op) {
        case NOOP: {
            SkASSERT(size >= 4);
            reader->skip(size - 4);
        } break;
        case CLIP_PATH: {
            const SkPath& path = fPictureData->getPath(reader);
            uint32_t packed = reader->readInt();
            SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
            bool doAA = ClipParams_unpackDoAA(packed);
            size_t offsetToRestore = reader->readInt();
            SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
            canvas->clipPath(path, regionOp, doAA);
            if (canvas->isClipEmpty() && offsetToRestore) {
                reader->setOffset(offsetToRestore);
            }
        } break;
        case CLIP_REGION: {
            SkRegion region;
            reader->readRegion(&region);
            uint32_t packed = reader->readInt();
            SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
            size_t offsetToRestore = reader->readInt();
            SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
            canvas->clipRegion(region, regionOp);
            if (canvas->isClipEmpty() && offsetToRestore) {
                reader->setOffset(offsetToRestore);
            }
        } break;
        case CLIP_RECT: {
            const SkRect& rect = reader->skipT<SkRect>();
            uint32_t packed = reader->readInt();
            SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
            bool doAA = ClipParams_unpackDoAA(packed);
            size_t offsetToRestore = reader->readInt();
            SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
            canvas->clipRect(rect, regionOp, doAA);
            if (canvas->isClipEmpty() && offsetToRestore) {
                reader->setOffset(offsetToRestore);
            }
        } break;
        case CLIP_RRECT: {
            SkRRect rrect;
            reader->readRRect(&rrect);
            uint32_t packed = reader->readInt();
            SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
            bool doAA = ClipParams_unpackDoAA(packed);
            size_t offsetToRestore = reader->readInt();
            SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
            canvas->clipRRect(rrect, regionOp, doAA);
            if (canvas->isClipEmpty() && offsetToRestore) {
                reader->setOffset(offsetToRestore);
            }
        } break;
        case PUSH_CULL: break;  // Deprecated, safe to ignore both push and pop.
        case POP_CULL:  break;
        case CONCAT: {
            SkMatrix matrix;
            reader->readMatrix(&matrix);
            canvas->concat(matrix);
            break;
        }
        case DRAW_ATLAS: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkImage* atlas = fPictureData->getImage(reader);
            const uint32_t flags = reader->readU32();
            const int count = reader->readU32();
            const SkRSXform* xform = (const SkRSXform*)reader->skip(count * sizeof(SkRSXform));
            const SkRect* tex = (const SkRect*)reader->skip(count * sizeof(SkRect));
            const SkColor* colors = nullptr;
            SkXfermode::Mode mode = SkXfermode::kDst_Mode;
            if (flags & DRAW_ATLAS_HAS_COLORS) {
                colors = (const SkColor*)reader->skip(count * sizeof(SkColor));
                mode = (SkXfermode::Mode)reader->readU32();
            }
            const SkRect* cull = nullptr;
            if (flags & DRAW_ATLAS_HAS_CULL) {
                cull = (const SkRect*)reader->skip(sizeof(SkRect));
            }
            canvas->drawAtlas(atlas, xform, tex, colors, count, mode, cull, paint);
        } break;
        case DRAW_BITMAP: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader));
            const SkPoint& loc = reader->skipT<SkPoint>();
            canvas->drawBitmap(bitmap, loc.fX, loc.fY, paint);
        } break;
        case DRAW_BITMAP_RECT: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader));
            const SkRect* src = get_rect_ptr(reader);   // may be null
            const SkRect& dst = reader->skipT<SkRect>();     // required
            SkCanvas::SrcRectConstraint constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
            canvas->legacy_drawBitmapRect(bitmap, src, dst, paint, constraint);
        } break;
        case DRAW_BITMAP_MATRIX: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader));
            SkMatrix matrix;
            reader->readMatrix(&matrix);

            SkAutoCanvasRestore acr(canvas, true);
            canvas->concat(matrix);
            canvas->drawBitmap(bitmap, 0, 0, paint);
        } break;
        case DRAW_BITMAP_NINE: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader));
            const SkIRect& src = reader->skipT<SkIRect>();
            const SkRect& dst = reader->skipT<SkRect>();
            canvas->drawBitmapNine(bitmap, src, dst, paint);
        } break;
        case DRAW_CLEAR:
            canvas->clear(reader->readInt());
            break;
        case DRAW_DATA: {
            // This opcode is now dead, just need to skip it for backwards compatibility
            size_t length = reader->readInt();
            (void)reader->skip(length);
            // skip handles padding the read out to a multiple of 4
        } break;
        case DRAW_DRRECT: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            SkRRect outer, inner;
            reader->readRRect(&outer);
            reader->readRRect(&inner);
            canvas->drawDRRect(outer, inner, paint);
        } break;
        case BEGIN_COMMENT_GROUP:
            reader->readString();
            // deprecated (M44)
            break;
        case COMMENT:
            reader->readString();
            reader->readString();
            // deprecated (M44)
            break;
        case END_COMMENT_GROUP:
            // deprecated (M44)
            break;
        case DRAW_IMAGE: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkImage* image = fPictureData->getImage(reader);
            const SkPoint& loc = reader->skipT<SkPoint>();
            canvas->drawImage(image, loc.fX, loc.fY, paint);
        } break;
        case DRAW_IMAGE_NINE: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkImage* image = fPictureData->getImage(reader);
            const SkIRect& center = reader->skipT<SkIRect>();
            const SkRect& dst = reader->skipT<SkRect>();
            canvas->drawImageNine(image, center, dst, paint);
        } break;
        case DRAW_IMAGE_RECT_STRICT:
        case DRAW_IMAGE_RECT: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            const SkImage* image = fPictureData->getImage(reader);
            const SkRect* src = get_rect_ptr(reader);   // may be null
            const SkRect& dst = reader->skipT<SkRect>();     // required
            // DRAW_IMAGE_RECT_STRICT assumes this constraint, and doesn't store it
            SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectConstraint;
            if (DRAW_IMAGE_RECT == op) {
                // newer op-code stores the constraint explicitly
                constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
            }
            canvas->legacy_drawImageRect(image, src, dst, paint, constraint);
        } break;
        case DRAW_OVAL: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            canvas->drawOval(reader->skipT<SkRect>(), paint);
        } break;
        case DRAW_PAINT:
            canvas->drawPaint(*fPictureData->getPaint(reader));
            break;
        case DRAW_PATCH: {
            const SkPaint& paint = *fPictureData->getPaint(reader);

            const SkPoint* cubics = (const SkPoint*)reader->skip(SkPatchUtils::kNumCtrlPts *
                                                                 sizeof(SkPoint));
            uint32_t flag = reader->readInt();
            const SkColor* colors = nullptr;
            if (flag & DRAW_VERTICES_HAS_COLORS) {
                colors = (const SkColor*)reader->skip(SkPatchUtils::kNumCorners * sizeof(SkColor));
            }
            const SkPoint* texCoords = nullptr;
            if (flag & DRAW_VERTICES_HAS_TEXS) {
                texCoords = (const SkPoint*)reader->skip(SkPatchUtils::kNumCorners *
                                                         sizeof(SkPoint));
            }
            SkAutoTUnref<SkXfermode> xfer;
            if (flag & DRAW_VERTICES_HAS_XFER) {
                int mode = reader->readInt();
                if (mode < 0 || mode > SkXfermode::kLastMode) {
                    mode = SkXfermode::kModulate_Mode;
                }
                xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode));
            }
            canvas->drawPatch(cubics, colors, texCoords, xfer, paint);
        } break;
        case DRAW_PATH: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            canvas->drawPath(fPictureData->getPath(reader), paint);
        } break;
        case DRAW_PICTURE:
            canvas->drawPicture(fPictureData->getPicture(reader));
            break;
        case DRAW_PICTURE_MATRIX_PAINT: {
            const SkPaint* paint = fPictureData->getPaint(reader);
            SkMatrix matrix;
            reader->readMatrix(&matrix);
            const SkPicture* pic = fPictureData->getPicture(reader);
            canvas->drawPicture(pic, &matrix, paint);
        } break;
        case DRAW_POINTS: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            SkCanvas::PointMode mode = (SkCanvas::PointMode)reader->readInt();
            size_t count = reader->readInt();
            const SkPoint* pts = (const SkPoint*)reader->skip(sizeof(SkPoint)* count);
            canvas->drawPoints(mode, count, pts, paint);
        } break;
        case DRAW_POS_TEXT: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            TextContainer text;
            get_text(reader, &text);
            size_t points = reader->readInt();
            const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(SkPoint));
            canvas->drawPosText(text.text(), text.length(), pos, paint);
        } break;
        case DRAW_POS_TEXT_TOP_BOTTOM: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            TextContainer text;
            get_text(reader, &text);
            size_t points = reader->readInt();
            const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(SkPoint));
            const SkScalar top = reader->readScalar();
            const SkScalar bottom = reader->readScalar();
            if (!canvas->quickRejectY(top, bottom)) {
                canvas->drawPosText(text.text(), text.length(), pos, paint);
            }
        } break;
        case DRAW_POS_TEXT_H: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            TextContainer text;
            get_text(reader, &text);
            size_t xCount = reader->readInt();
            const SkScalar constY = reader->readScalar();
            const SkScalar* xpos = (const SkScalar*)reader->skip(xCount * sizeof(SkScalar));
            canvas->drawPosTextH(text.text(), text.length(), xpos, constY, paint);
        } break;
        case DRAW_POS_TEXT_H_TOP_BOTTOM: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            TextContainer text;
            get_text(reader, &text);
            size_t xCount = reader->readInt();
            const SkScalar* xpos = (const SkScalar*)reader->skip((3 + xCount) * sizeof(SkScalar));
            const SkScalar top = *xpos++;
            const SkScalar bottom = *xpos++;
            const SkScalar constY = *xpos++;
            if (!canvas->quickRejectY(top, bottom)) {
                canvas->drawPosTextH(text.text(), text.length(), xpos, constY, paint);
            }
        } break;
        case DRAW_RECT: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            canvas->drawRect(reader->skipT<SkRect>(), paint);
        } break;
        case DRAW_RRECT: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            SkRRect rrect;
            reader->readRRect(&rrect);
            canvas->drawRRect(rrect, paint);
        } break;
        case DRAW_SPRITE: {
            /* const SkPaint* paint = */ fPictureData->getPaint(reader);
            /* const SkBitmap bitmap = */ shallow_copy(fPictureData->getBitmap(reader));
            /* int left = */ reader->readInt();
            /* int top = */ reader->readInt();
            // drawSprite removed dec-2015
        } break;
        case DRAW_TEXT: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            TextContainer text;
            get_text(reader, &text);
            SkScalar x = reader->readScalar();
            SkScalar y = reader->readScalar();
            canvas->drawText(text.text(), text.length(), x, y, paint);
        } break;
        case DRAW_TEXT_BLOB: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            const SkTextBlob* blob = fPictureData->getTextBlob(reader);
            SkScalar x = reader->readScalar();
            SkScalar y = reader->readScalar();
            canvas->drawTextBlob(blob, x, y, paint);
        } break;
        case DRAW_TEXT_TOP_BOTTOM: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            TextContainer text;
            get_text(reader, &text);
            const SkScalar* ptr = (const SkScalar*)reader->skip(4 * sizeof(SkScalar));
            // ptr[0] == x
            // ptr[1] == y
            // ptr[2] == top
            // ptr[3] == bottom
            if (!canvas->quickRejectY(ptr[2], ptr[3])) {
                canvas->drawText(text.text(), text.length(), ptr[0], ptr[1], paint);
            }
        } break;
        case DRAW_TEXT_ON_PATH: {
            const SkPaint& paint = *fPictureData->getPaint(reader);
            TextContainer text;
            get_text(reader, &text);
            const SkPath& path = fPictureData->getPath(reader);
            SkMatrix matrix;
            reader->readMatrix(&matrix);
            canvas->drawTextOnPath(text.text(), text.length(), path, &matrix, paint);
        } break;
        case DRAW_VERTICES: {
            SkAutoTUnref<SkXfermode> xfer;
            const SkPaint& paint = *fPictureData->getPaint(reader);
            DrawVertexFlags flags = (DrawVertexFlags)reader->readInt();
            SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readInt();
            int vCount = reader->readInt();
            const SkPoint* verts = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint));
            const SkPoint* texs = nullptr;
            const SkColor* colors = nullptr;
            const uint16_t* indices = nullptr;
            int iCount = 0;
            if (flags & DRAW_VERTICES_HAS_TEXS) {
                texs = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint));
            }
            if (flags & DRAW_VERTICES_HAS_COLORS) {
                colors = (const SkColor*)reader->skip(vCount * sizeof(SkColor));
            }
            if (flags & DRAW_VERTICES_HAS_INDICES) {
                iCount = reader->readInt();
                indices = (const uint16_t*)reader->skip(iCount * sizeof(uint16_t));
            }
            if (flags & DRAW_VERTICES_HAS_XFER) {
                int mode = reader->readInt();
                if (mode < 0 || mode > SkXfermode::kLastMode) {
                    mode = SkXfermode::kModulate_Mode;
                }
                xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode));
            }
            canvas->drawVertices(vmode, vCount, verts, texs, colors, xfer, indices, iCount, paint);
        } break;
        case RESTORE:
            canvas->restore();
            break;
        case ROTATE:
            canvas->rotate(reader->readScalar());
            break;
        case SAVE:
            // SKPs with version < 29 also store a SaveFlags param.
            if (size > 4) {
                SkASSERT(8 == size);
                reader->readInt();
            }
            canvas->save();
            break;
        case SAVE_LAYER_SAVEFLAGS_DEPRECATED: {
            const SkRect* boundsPtr = get_rect_ptr(reader);
            const SkPaint* paint = fPictureData->getPaint(reader);
            auto flags = SkCanvas::LegacySaveFlagsToSaveLayerFlags(reader->readInt());
            canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, flags));
        } break;
        case SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016: {
            const SkRect* boundsPtr = get_rect_ptr(reader);
            const SkPaint* paint = fPictureData->getPaint(reader);
            canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, reader->readInt()));
        } break;
        case SAVE_LAYER_SAVELAYERREC: {
            SkCanvas::SaveLayerRec rec(nullptr, nullptr, nullptr, 0);
            const uint32_t flatFlags = reader->readInt();
            if (flatFlags & SAVELAYERREC_HAS_BOUNDS) {
                rec.fBounds = &reader->skipT<SkRect>();
            }
            if (flatFlags & SAVELAYERREC_HAS_PAINT) {
                rec.fPaint = fPictureData->getPaint(reader);
            }
            if (flatFlags & SAVELAYERREC_HAS_BACKDROP) {
                const SkPaint* paint = fPictureData->getPaint(reader);
                rec.fBackdrop = paint->getImageFilter();
            }
            if (flatFlags & SAVELAYERREC_HAS_FLAGS) {
                rec.fSaveLayerFlags = reader->readInt();
            }
            canvas->saveLayer(rec);
        } break;
        case SCALE: {
            SkScalar sx = reader->readScalar();
            SkScalar sy = reader->readScalar();
            canvas->scale(sx, sy);
        } break;
        case SET_MATRIX: {
            SkMatrix matrix;
            reader->readMatrix(&matrix);
            matrix.postConcat(initialMatrix);
            canvas->setMatrix(matrix);
        } break;
        case SKEW: {
            SkScalar sx = reader->readScalar();
            SkScalar sy = reader->readScalar();
            canvas->skew(sx, sy);
        } break;
        case TRANSLATE: {
            SkScalar dx = reader->readScalar();
            SkScalar dy = reader->readScalar();
            canvas->translate(dx, dy);
        } break;
        default:
            SkASSERTF(false, "Unknown draw type: %d", op);
    }
}
示例#9
0
 static BOOST_FORCEINLINE A0 cot_eval(const A0&z, const iA0& n )
 {
   const A0 y = base_tancot_eval(z);
   return bs::if_else(bs::is_equal(n, One<iA0>()),rec(y),-y);
 }
示例#10
0
int main(){

//int a[5][5]={{11,12,12,0,0},{11,0,13,0,0},{0,0,0,0,22},{22,13,23,0,0},{0,21,0,0,21}};
/*int a[5][5] = {{11,0,12,21,21},
					{11,23,13,23,11},
					{11,21,23,11,11},
					{22,0,23,12,11},
					{12,21,22,11,21}}; */
int n=5,p,fl=0,r=0,c=0,i,j,count=0,count2=0,diff=-999,b,pli,plj,pl2,d,max,flg=0,k;
//int a[5][5];//={{11,12,12,12,21},{12,11,11,13,0},{11,11,13,12,11},{11,13,13,12,0},{21,12,12,0,21}};
int a[5][5];//={{21,11,11,12,11},{12,12,11,12,12},{12,13,13,12,11},{11,13,0,12,12},{11,11,12,22,21}};
int M1[5][5], M2[5][5];

//Taking input matrix

for(i=0;i<n;i++){
for( j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
}
//taking players-code 
//display(a);
scanf("%d",&p);
pc = p;
/*while(flag){
r=rand()%5;//randomly placing output
c=rand()%5;
if(a[r][c]/10==p||a[r][c]/10==0)//check randomly generated box to be 
flag=0;
} */
//count = 
//acquire(a,p);
//b = checkMat(a,2,3);
//rec(M1,M2,3,2);

for(i = 0; i<5;i++)
{//printf("\n-4: ***********\n");
for(j=0;j<5;j++)
{
	if(a[i][j]/10!=p)continue;
copy(M2,a);copy(aa,a);//printf("\n-1: i:%d j:%d r:%d c:%d\n",i,j,r,c);
M2[i][j]%=10;
M2[i][j]++;
M2[i][j]+=(10*p);
b=checkMat(M2,i,j);
//printf("\nb:%d\n",b);
if(b==1)
{//	//printf("\n-2: r:%d c:%d\n",r,c);
rec(M2,M1,i,j);// printf("\n-2: r:%d c:%d\n",r,c);
 count=acquire(M1,3-p);
if(count==0)
{
	r=i;c=j;flg=1;//printf("\n-3: r:%d c:%d\n",r,c);
}
else if((count==1 || count==2 || count==3 ) && nz(M1)<10)
{
	r=i;c=j;flg=1;
}
}

}
}
////printf("\n0: r:%d c:%d\n",r,c);
		if(a[0][0]/10==3-p && a[0][1]/10==p && a[1][0]/10==p && a[0][1]%10==2 )
		{
			r=0;c=1;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		else if(a[0][0]/10==3-p && a[1][0]/10==p && a[0][0]/10==p && a[1][0]%10==2 )
		{
			r=1;c=0;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		else if(a[0][4]/10==3-p && a[0][3]/10==p && a[1][4]/10==p && a[0][3]%10==2 )
		{
			r=0;c=3;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		else if(a[0][4]/10==3-p && a[0][3]/10==p && a[1][4]/10==p && a[1][4]%10==2 )
		{
			r=1;c=4;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		else if(a[4][0]/10==3-p && a[3][0]/10==p && a[4][1]/10==p && a[4][1]%10==2 )
		{
			r=4;c=1;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		else if(a[4][0]/10==3-p && a[3][0]/10==p && a[4][1]/10==p && a[3][0]%10==2 )
		{
			r=3;c=0;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		else if(a[4][4]/10==3-p && a[3][4]/10==p && a[4][3]/10==p && a[3][4]%10==2 )
		{
			r=3;c=4;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		else if(a[4][4]/10==3-p && a[3][4]/10==p && a[4][3]/10==p && a[4][3]%10==2 )
		{
			r=4;c=3;flg=1;////printf("\n1: r:%d c:%d\n",r,c);|| a[1][0]%2==0)
		}
		
		else if((a[0][0]/10==p && a[0][1]/10==3-p && a[1][0]/10==3-p && (a[0][1]%10==2 || a[1][0]%2==0)))
		{
			r=0;c=0;flg=1;//printf("\n-8: r:%d c:%d\n",r,c);
		}
		else if((a[0][4]/10==p && a[0][3]/10==3-p && a[1][4]/10==3-p && (a[1][4]%10==2 || a[0][3]%2==0)))
		{
			r=0;c=4;flg=1; ////printf("!!1");
		}
		else if((a[4][0]/10==p && a[4][1]/10==3-p && a[3][0]/10==3-p && (a[4][1]%10==2 || a[3][0]%2==0)))
		{
			r=4;c=0;flg=1;
		}
		else if((a[4][4]/10==p && a[3][4]/10==3-p && a[4][3]/10==3-p && (a[3][4]%10==2 || a[4][3]%2==0)))
		{
			r=4;c=4;flg=1;
		}
		
		else if(a[0][0]/10==0 && a[0][1]/10==3-p && a[1][0]/10==3-p&& a[0][1]%10!=2 && a[1][0]%10!=2)
		{
			r=0;c=0;flg=1;//printf("\n1: r:%d c:%d\n",r,c);
		}
		else if((a[0][4]/10==0 && a[0][3]/10==3-p && a[1][4]/10==3-p) && a[0][3]%10!=2 && a[1][4]%10!=2)
		{
			r=0;c=4;flg=1;////printf("!!2");
		}
		else if((a[4][0]/10==0 && a[4][1]/10==3-p && a[3][0]/10==3-p) && a[4][1]%10!=2 && a[3][0]%10!=2)
		{
			r=4;c=0;flg=1;
		}
		else if((a[4][4]/10==0 && a[3][4]/10==3-p && a[4][3]/10==3-p) && a[4][3]%10!=2 && a[3][4]%10!=2)
		{
			r=4;c=4;flg=1;
		}
		
		
		else if((a[0][0]/10==0 && (a[0][1]/10==3-p || a[1][0]/10==3-p))&& nz(a)>8 && a[0][1]%10!=2 && a[1][0]%10!=2)
		{
			r=0;c=0;flg=1;//printf("\n2: r:%d c:%d\n",r,c);
		}
		else if((a[0][4]/10==0 && (a[0][3]/10==3-p || a[1][4]/10==3-p))&& nz(a)>8 && a[0][3]%10!=2 && a[1][4]%10!=2)
		{
			r=0;c=4;flg=1;////printf("!!3");
		}
		else if((a[4][0]/10==0 && (a[4][1]/10==3-p || a[3][0]/10==3-p))&& nz(a)>8 && a[4][1]%10!=2 && a[3][0]%10!=2)
		{
			r=4;c=0;flg=1;
		}
		else if((a[4][4]/10==0 && (a[3][4]/10==3-p || a[4][3]/10==3-p))&& nz(a)>8 && a[4][3]%10!=2 && a[3][4]%10!=2)
		{
			r=4;c=4;flg=1;
		}
		else if((a[0][1]/10==p && a[0][1]%10==2)  && a[0][0]/10==3-p)
		{
			r=0;c=1;flg=1;
		}
		else if((a[1][0]/10==p && a[1][0]%10==2)  && a[0][0]/10==3-p)
		{
			r=1;c=0;flg=1;
		}
			else if((a[4][1]/10==p && a[4][1]%10==2)  && a[4][0]/10==3-p)
		{
			r=4;c=1;flg=1;
		}
			else if((a[3][0]/10==p && a[3][0]%10==2)  && a[4][0]/10==3-p)
		{
			r=3;c=0;flg=1;
		}
			else if((a[3][4]/10==p && a[3][4]%10==2)  && a[4][4]/10==3-p)
		{
			r=3;c=4;flg=1;
		}
			else if((a[4][3]/10==p && a[4][3]%10==2)  && a[4][4]/10==3-p)
		{
			r=4;c=3;flg=1;
		}
			else if((a[0][3]/10==p && a[0][3]%10==2)  && a[0][4]/10==3-p)
		{
			r=0;c=3;flg=1;
		}
			else if((a[1][4]/10==p && a[1][4]%10==2)  && a[0][4]/10==3-p)
		{
			r=1;c=4;flg=1;
		}
		else if(a[0][0]==0&& nz(a)>8 && a[0][1]%10!=2 && a[1][0]%10!=2)
		{r=0;c=0;flg=1;//printf("\n3: r:%d c:%d\n",r,c);
		}
		else if(a[0][4]==0&& nz(a)>8 && a[0][3]%10!=2 && a[1][4]%10!=2)
		{
			r=0;c=4;flg=1;////printf("!!4");
		}
		else if(a[4][0]==0&& nz(a)>8 && a[4][1]%10!=2 && a[3][0]%10!=2)
		{
			r=4;c=0;flg=1;
		}
		else if(a[4][4]==0&& nz(a)>8 && a[4][3]%10!=2 && a[3][4]%10!=2)
		{
			r=4;c=4;flg=1;
		}
		else if(a[0][0]!=0 && a[0][4]!=0 && a[4][0]!=0 && a[4][4]!=0 && a[2][2]/10!=3-p &&  nz(a)>10)
		{
		/*	if((a[0][0]/10 == 3-p && a[0][1]/10==3-p && a[1][0]/10==3-p)) 
				{r=1;c=1;flg=1;}
			else if (a[0][4]/10 == 3-p && a[0][3]/10==3-p && a[1][4]/10==3-p)
			{ r = 3; c = 1; flg = 1;}
			
			else if(a[4][0]/10 == 3-p && a[3][0]/10==3-p && a[4][1]/10==3-p )
			{
				r=3,c=1;flg=1;
			}
			else if(a[4][4]/10 == 3-p && a[4][3]/10==3-p && a[3][4]/10==3-p )
			{
				r=3,c=3;flg=1;
			}
			else
			{				*/
				r=2;c=2;flg=1;
		//	}
		}

if(flg==0){
max=-999;//printf("\nrec\n");
for(k=0;k<25;k++)
{	i=mati[k];j=matj[k];

copy(M2,a);

d=M2[i][j];z=0;pl2 = 0;
if((p==1 && (d != 21 && d != 22 && d != 23)) || (p==2 && (d != 11 && d != 12 && d != 13)))
{	if((a[0][0]==(p*10+1) && i==0 && j==0 && a[0][1]==0 && a[1][0]==0)	|| (a[0][4]==(p*10+1) && i==0 && j==4 && a[0][3]==0 && a[1][4]==0) ||(a[4][0]==(p*10+1) && i==4 && j==0 && a[4][1]==0 && a[0][3]==0)||(a[4][4]==(p*10+1) && i==4 && j==4 && a[4][3]==0 && a[3][4]==0))			
	continue;
M2[i][j]%=10;
M2[i][j]++;
M2[i][j]+=(10*p);
b=checkMat(M2,i,j);
if(b==1)
{copy(aa,a);rec(M2,M1,i,j); 
 count=acquire(M1,p);
 count2=acquire(M1,3-p);
 
if(count2==0)
{
	r=i;c=j;fl=1;break;
}
}
else
{
count=acquire(M2,p);
count2=acquire(M2,3-p);
if(count2==0)
{
	r=i;c=j;fl=1;break;
}
}
diff=count-count2;
if(diff > max)
{
max = diff;r = i;c = j;
}
}
}

}

printf("%d %d",r,c);//outputs your move
}
示例#11
0
static void clockTimer_callback(void* o) {  
	u16 s;
	u8 i1, i2;

	// static event_t e;
	// e.type = kEventTimer;
	// e.data = 0;
	// event_post(&e);
	// print_dbg("\r\ntimer.");

	// clock_phase++;
	// if(clock_phase>1) clock_phase=0;
	// (*clock_pulse)(clock_phase);

	if(shape_counter) {
		if(shape_counter == 1) {
			s = 0;
			for(i1=0;i1<3;i1++)
				if(min_y + i1 < 16)
				for(i2=0;i2<3;i2++) {
					s <<= 1;
					if(min_x + i2 < 16)
					if(key_map[(min_y+i1)*16+(min_x+i2)]) s |= 1;
				}
			// print_dbg("\r\nfound shape pattern: ");
			// print_dbg_ulong(s);

			for(i1=0;i1<15;i1++)
				if(s == SHAPE_PATTERN[i1]) break;

			if(i1 < 9) {
				if(r_status != rOff) 
					rec(i1, min_x, min_y + SHAPE_OFF_Y[i1]);
				shape(i1, min_x, min_y + SHAPE_OFF_Y[i1]);
				legato = 1;
			}
			else if(i1 < 15) {
				// MAGICS
				if(i1==9)
					all_edit = 1;
				else if(i1==10)
					pattern_linearize();
				else if(i1==11)
					pattern_time_half();
				else if(i1==12)
					pattern_time_double();
				else if(i1==13) {
					if(p_select<15)
						p_select++;
					else
						p_select = 0;
					play();
				}
				else if(i1==14) {
					if(p_select > 0)
						p_select--;
					else
						p_select = 15;
					play();
				}
			}
			else {
				if(r_status != rOff)
					rec(0,last_x,last_y);
				shape(0, last_x, last_y);
				legato = 1;
			}
		}
		
		shape_counter--;
	}

	if(edge_counter) {
		if(edge_counter == 1) {
			gpio_clr_gpio_pin(B00);
			edge_state = 0;
			monomeFrameDirty++;
			// print_dbg("\r\ntrig done.");
		}

		edge_counter--;
	}

	if(r_status == rRec) {
		rec_timer++;
	}

	if(p_playing) {
		if(p_timer == 0) {

			if(p_play_pos == es.p[p_select].length && !es.p[p_select].loop) {
				// print_dbg("\r\nPATTERN DONE");
				p_playing = 0;
			}
			else {
				if(p_play_pos == es.p[p_select].length && es.p[p_select].loop) {
					// print_dbg("\r\nLOOP");
					p_play_pos = 0;
					p_timer_total = 0;
				}

				u8 i = p_play_pos;
				p_timer = es.p[p_select].e[i].interval;

				s8 x = es.p[p_select].e[i].x + es.p[p_select].x;
				s8 y = es.p[p_select].e[i].y + es.p[p_select].y;

				if(x<0) x = 0;
				else if(x>15) x=15;
				if(y<0) y = 0;
				else if(y>7) y=7;


				// print_dbg("\r\n");
				// print_dbg_ulong(i);
				// print_dbg(" : ");
				// print_dbg_ulong(es.p[p_select].e[i].shape);
				// print_dbg(" @ (");
				// print_dbg_ulong(es.p[p_select].e[i].x);
				// print_dbg(", ");
				// print_dbg_ulong(es.p[p_select].e[i].y);
				// print_dbg(")   NEXT: ");
				// print_dbg_ulong(es.p[p_select].e[i].interval);

				pattern_shape(es.p[p_select].e[i].shape, (u8)x, (u8)y);


				p_play_pos++;

			}
		}
		else p_timer--;

		p_timer_total++;

		monomeFrameDirty++;
	}

	if(r_status == rRec || all_edit || !VARI) {
		blinker++;
		if(blinker == 48)
			blinker = 0;
		if(blinker == 0 || blinker == 24)
			monomeFrameDirty++;
	}
}
示例#12
0
 TreeNode* buildTree(std::vector<int>& inorder, std::vector<int>& postorder)
 {
     return rec(inorder, 0, inorder.size(), postorder, 0, postorder.size());
 }
void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
                                          const SkRect& clippedSrcRect,
                                          const SkRect& clippedDstRect,
                                          SkCanvas::SrcRectConstraint constraint,
                                          const SkMatrix& viewMatrix,
                                          const SkMatrix& srcToDstMatrix,
                                          const GrClip& clip,
                                          const SkPaint& paint) {
    // Specifying the texture coords as local coordinates is an attempt to enable more GrDrawOp
    // combining by not baking anything about the srcRect, dstRect, or viewMatrix, into the texture
    // FP. In the future this should be an opaque optimization enabled by the combination of
    // GrDrawOp/GP and FP.
    const SkMaskFilter* mf = paint.getMaskFilter();
    // The shader expects proper local coords, so we can't replace local coords with texture coords
    // if the shader will be used. If we have a mask filter we will change the underlying geometry
    // that is rendered.
    bool canUseTextureCoordsAsLocalCoords = !use_shader(producer->isAlphaOnly(), paint) && !mf;

    bool doBicubic;
    GrSamplerParams::FilterMode fm =
        GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, srcToDstMatrix,
                                        &doBicubic);
    const GrSamplerParams::FilterMode* filterMode = doBicubic ? nullptr : &fm;

    GrTextureProducer::FilterConstraint constraintMode;
    if (SkCanvas::kFast_SrcRectConstraint == constraint) {
        constraintMode = GrTextureAdjuster::kNo_FilterConstraint;
    } else {
        constraintMode = GrTextureAdjuster::kYes_FilterConstraint;
    }

    // If we have to outset for AA then we will generate texture coords outside the src rect. The
    // same happens for any mask filter that extends the bounds rendered in the dst.
    // This is conservative as a mask filter does not have to expand the bounds rendered.
    bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf;

    // Check for optimization to drop the src rect constraint when on bilerp.
    if (filterMode && GrSamplerParams::kBilerp_FilterMode == *filterMode &&
        GrTextureAdjuster::kYes_FilterConstraint == constraintMode && coordsAllInsideSrcRect) {
        SkMatrix combinedMatrix;
        combinedMatrix.setConcat(viewMatrix, srcToDstMatrix);
        if (can_ignore_bilerp_constraint(*producer, clippedSrcRect, combinedMatrix,
                                         fRenderTargetContext->isUnifiedMultisampled())) {
            constraintMode = GrTextureAdjuster::kNo_FilterConstraint;
        }
    }

    const SkMatrix* textureMatrix;
    SkMatrix tempMatrix;
    if (canUseTextureCoordsAsLocalCoords) {
        textureMatrix = &SkMatrix::I();
    } else {
        if (!srcToDstMatrix.invert(&tempMatrix)) {
            return;
        }
        textureMatrix = &tempMatrix;
    }
    sk_sp<GrFragmentProcessor> fp(producer->createFragmentProcessor(
        *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode,
        fRenderTargetContext->getColorSpace()));
    if (!fp) {
        return;
    }

    GrPaint grPaint;
    if (!SkPaintToGrPaintWithTexture(fContext.get(), fRenderTargetContext.get(), paint, viewMatrix,
                                     fp, producer->isAlphaOnly(), &grPaint)) {
        return;
    }
    GrAA aa = GrBoolToAA(paint.isAntiAlias());
    if (canUseTextureCoordsAsLocalCoords) {
        fRenderTargetContext->fillRectToRect(clip, std::move(grPaint), aa, viewMatrix,
                                             clippedDstRect, clippedSrcRect);
        return;
    }

    if (!mf) {
        fRenderTargetContext->drawRect(clip, std::move(grPaint), aa, viewMatrix, clippedDstRect);
        return;
    }

    // First see if we can do the draw + mask filter direct to the dst.
    if (viewMatrix.isScaleTranslate()) {
        SkRect devClippedDstRect;
        viewMatrix.mapRectScaleTranslate(&devClippedDstRect, clippedDstRect);

        SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
        if (mf->directFilterRRectMaskGPU(fContext.get(),
                                         fRenderTargetContext.get(),
                                         std::move(grPaint),
                                         clip,
                                         viewMatrix,
                                         rec,
                                         SkRRect::MakeRect(clippedDstRect),
                                         SkRRect::MakeRect(devClippedDstRect))) {
            return;
        }
    }

    SkPath rectPath;
    rectPath.addRect(clippedDstRect);
    rectPath.setIsVolatile(true);
    GrBlurUtils::drawPathWithMaskFilter(this->context(), fRenderTargetContext.get(), this->clip(),
                                        rectPath, std::move(grPaint), aa, viewMatrix, mf,
                                        GrStyle::SimpleFill(), true);
}
示例#14
0
shared_ptr<vector<FileRecordPtr> > Plugin::GetSearchOptions(int owner)
{
	shared_ptr<vector<FileRecordPtr> > out;
	out.reset(new vector<FileRecordPtr>);

/*	if (searchTxt == L"buff") {
		out.reset(new vector<FileRecordPtr>);
	}
*/
	if (owner == -1) {
		// This file isn't owned by anyone, we want to get a suite of options
		// from the available utilities such as "open, enqueue, send email" etc..

		for(uint i = 0; i < loadedPlugins.size(); i++) {
			if (pfuncs[i].PluginUpdateSearch == NULL) continue;
			int NumResults;
			TCHAR* szStrings = StringArrayToTCHAR(SearchStrings);
			SearchResult* res = pfuncs[i].PluginFileOptions( TabbedMatch->fullPath, (int) SearchStrings.GetCount(), szStrings, searchTxt, &NumResults);
			free(szStrings);
			SearchResult* cur = res;
			for(int j = 0; j < NumResults; j++) {
				FileRecordPtr rec(new FileRecord());
				rec->croppedName = cur->DisplayString;
				rec->fullPath = cur->FullPath;
				rec->isHistory = false;
				rec->lowName = rec->croppedName;
				rec->lowName.MakeLower();
				rec->usage = 0;
				rec->owner = (short) i;

				out->push_back(rec);
				cur++;
			}	
			pfuncs[i].PluginFreeResults(res, NumResults);
		}
	} else {

		if (pfuncs[owner].PluginUpdateSearch == NULL) return out;


		int NumResults;

		TCHAR* szStrings = StringArrayToTCHAR(SearchStrings);
		SearchResult* res = pfuncs[owner].PluginUpdateSearch((int) SearchStrings.GetCount(), szStrings, searchTxt, &NumResults);
		free(szStrings);

		SearchResult* cur = res;
		for(int j = 0; j < NumResults; j++) {
			FileRecordPtr rec(new FileRecord());
			rec->croppedName = cur->DisplayString;
			rec->fullPath = cur->FullPath;
			rec->isHistory = false;
			rec->lowName = rec->croppedName;
			rec->lowName.MakeLower();
			rec->usage = 0;
			rec->owner = (short) owner;

			out->push_back(rec);
			cur++;
		}	

		pfuncs[owner].PluginFreeResults(res, NumResults);
	}
	return out;
}
void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath,
                                  SkPath* devPath, SkMatrix* fillToDevMatrix) {
    SkPath  path;

    this->getGlyphContext(glyph)->generatePath(glyph, &path);

    if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) {
        SkFixed dx = glyph.getSubXFixed();
        SkFixed dy = glyph.getSubYFixed();
        if (dx | dy) {
            path.offset(SkFixedToScalar(dx), SkFixedToScalar(dy));
        }
    }

    if (fRec.fFrameWidth > 0 || fPathEffect != NULL) {
        // need the path in user-space, with only the point-size applied
        // so that our stroking and effects will operate the same way they
        // would if the user had extracted the path themself, and then
        // called drawPath
        SkPath      localPath;
        SkMatrix    matrix, inverse;

        fRec.getMatrixFrom2x2(&matrix);
        if (!matrix.invert(&inverse)) {
            // assume fillPath and devPath are already empty.
            return;
        }
        path.transform(inverse, &localPath);
        // now localPath is only affected by the paint settings, and not the canvas matrix

        SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);

        if (fRec.fFrameWidth > 0) {
            rec.setStrokeStyle(fRec.fFrameWidth,
                               SkToBool(fRec.fFlags & kFrameAndFill_Flag));
            // glyphs are always closed contours, so cap type is ignored,
            // so we just pass something.
            rec.setStrokeParams(SkPaint::kButt_Cap,
                                (SkPaint::Join)fRec.fStrokeJoin,
                                fRec.fMiterLimit);
        }

        if (fPathEffect) {
            SkPath effectPath;
            if (fPathEffect->filterPath(&effectPath, localPath, &rec, NULL)) {
                localPath.swap(effectPath);
            }
        }

        if (rec.needToApply()) {
            SkPath strokePath;
            if (rec.applyToPath(&strokePath, localPath)) {
                localPath.swap(strokePath);
            }
        }

        // now return stuff to the caller
        if (fillToDevMatrix) {
            *fillToDevMatrix = matrix;
        }
        if (devPath) {
            localPath.transform(matrix, devPath);
        }
        if (fillPath) {
            fillPath->swap(localPath);
        }
    } else {   // nothing tricky to do
        if (fillToDevMatrix) {
            fillToDevMatrix->reset();
        }
        if (devPath) {
            if (fillPath == NULL) {
                devPath->swap(path);
            } else {
                *devPath = path;
            }
        }

        if (fillPath) {
            fillPath->swap(path);
        }
    }

    if (devPath) {
        devPath->updateBoundsCache();
    }
    if (fillPath) {
        fillPath->updateBoundsCache();
    }
}
示例#16
0
void RegisterJiggleWindow(HWND hWnd, HWND hParent, Control *cont)
{
	JiggleWindow rec(hWnd,hParent,cont);
	jiggleWindows.append(rec);
}
示例#17
0
文件: sf_wmo.c 项目: holger24/AFD
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
#ifdef _WITH_BURST_2
   int              cb2_ret;
#endif
   int              current_toggle,
                    exit_status = TRANSFER_SUCCESS,
                    j,
                    fd,
                    status,
                    loops,
                    rest,
                    blocksize,
                    *wmo_counter,
                    wmo_counter_fd = -1;
#ifdef WITH_ARCHIVE_COPY_INFO
   unsigned int     archived_copied = 0;
#endif
   off_t            no_of_bytes;
   time_t           connected,
#ifdef _WITH_BURST_2
                    diff_time,
#endif
                    end_transfer_time_file,
                    start_transfer_time_file = 0,
                    last_update_time,
                    now;
#ifdef _OUTPUT_LOG
   clock_t          end_time = 0,
                    start_time = 0;
   struct tms       tmsdummy;
#endif
   char             *p_file_name_buffer,
                    *buffer,
                    fullname[MAX_PATH_LENGTH + 1],
                    file_path[MAX_PATH_LENGTH];
   clock_t          clktck;
   struct stat      stat_buf;
   struct job       *p_db;
#ifdef SA_FULLDUMP
   struct sigaction sact;
#endif

   CHECK_FOR_VERSION(argc, argv);

#ifdef SA_FULLDUMP
   /*
    * When dumping core sure we do a FULL core dump!
    */
   sact.sa_handler = SIG_DFL;
   sact.sa_flags = SA_FULLDUMP;
   sigemptyset(&sact.sa_mask);
   if (sigaction(SIGSEGV, &sact, NULL) == -1)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "sigaction() error : %s", strerror(errno));
      exit(INCORRECT);
   }
#endif

   /* Do some cleanups when we exit. */
   if (atexit(sf_wmo_exit) != 0)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "Could not register exit function : %s", strerror(errno));
      exit(INCORRECT);
   }

   /* Initialise variables. */
   local_file_counter = 0;
   files_to_send = init_sf(argc, argv, file_path, WMO_FLAG);
   p_db = &db;
   if ((clktck = sysconf(_SC_CLK_TCK)) <= 0)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "Could not get clock ticks per second : %s",
                 strerror(errno));
      exit(INCORRECT);
   }
   if (fsa->trl_per_process > 0)
   {
      if (fsa->trl_per_process < fsa->block_size)
      {
         blocksize = fsa->trl_per_process;
      }
      else
      {
         blocksize = fsa->block_size;
      }
   }
   else
   {
      blocksize = fsa->block_size;
   }

   if ((signal(SIGINT, sig_kill) == SIG_ERR) ||
       (signal(SIGQUIT, sig_exit) == SIG_ERR) ||
       (signal(SIGTERM, SIG_IGN) == SIG_ERR) ||
       (signal(SIGSEGV, sig_segv) == SIG_ERR) ||
       (signal(SIGBUS, sig_bus) == SIG_ERR) ||
       (signal(SIGHUP, SIG_IGN) == SIG_ERR) ||
       (signal(SIGPIPE, SIG_IGN) == SIG_ERR))
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "signal() error : %s", strerror(errno));
      exit(INCORRECT);
   }

   /* Now determine the real hostname. */
   if (db.toggle_host == YES)
   {
      if (fsa->host_toggle == HOST_ONE)
      {
         (void)strcpy(db.hostname, fsa->real_hostname[HOST_TWO - 1]);
         current_toggle = HOST_TWO;
      }
      else
      {
         (void)strcpy(db.hostname, fsa->real_hostname[HOST_ONE - 1]);
         current_toggle = HOST_ONE;
      }
   }
   else
   {
      (void)strcpy(db.hostname,
                   fsa->real_hostname[(int)(fsa->host_toggle - 1)]);
      current_toggle = (int)fsa->host_toggle;
   }

   /* Connect to remote WMO-server. */
#ifdef FTP_CTRL_KEEP_ALIVE_INTERVAL
   if (fsa->protocol_options & AFD_TCP_KEEPALIVE)
   {
      timeout_flag = transfer_timeout - 5;
      if (timeout_flag < MIN_KEEP_ALIVE_INTERVAL)
      {
         timeout_flag = MIN_KEEP_ALIVE_INTERVAL;
      }
   }
#else
   timeout_flag = OFF;
#endif
   if ((status = wmo_connect(db.hostname, db.port, db.sndbuf_size)) != SUCCESS)
   {
      trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                "WMO connection to <%s> at port %d failed (%d).",
                db.hostname, db.port, status);
      exit(eval_timeout(CONNECT_ERROR));
   }
   else
   {
      if (fsa->debug > NORMAL_MODE)
      {
         trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                      "Connected to port %d.", db.port);
      }
   }
   connected = time(NULL);

   /* Inform FSA that we have finished connecting and */
   /* will now start to transfer data.                */
   if (gsf_check_fsa(p_db) != NEITHER)
   {
#ifdef LOCK_DEBUG
      lock_region_w(fsa_fd, db.lock_offset + LOCK_CON, __FILE__, __LINE__);
#else
      lock_region_w(fsa_fd, db.lock_offset + LOCK_CON);
#endif
      fsa->job_status[(int)db.job_no].connect_status = WMO_ACTIVE;
      fsa->job_status[(int)db.job_no].no_of_files = files_to_send;
      fsa->connections += 1;
#ifdef LOCK_DEBUG
      unlock_region(fsa_fd, db.lock_offset + LOCK_CON, __FILE__, __LINE__);
#else
      unlock_region(fsa_fd, db.lock_offset + LOCK_CON);
#endif
   }

   /* Allocate buffer to read data from the source file. */
   if ((buffer = malloc(blocksize + 1 + 4 /* For bulletin end. */)) == NULL)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "malloc() error : %s", strerror(errno));
      exit(ALLOC_ERROR);
   }

   if (db.special_flag & WITH_SEQUENCE_NUMBER)
   {
      char counter_file_name[MAX_FILENAME_LENGTH];

      (void)snprintf(counter_file_name, MAX_FILENAME_LENGTH, "/%s.%d", db.host_alias, db.port);
      if ((wmo_counter_fd = open_counter_file(counter_file_name, &wmo_counter)) < 0)
      {
         system_log(ERROR_SIGN, __FILE__, __LINE__,
                    "Failed to open counter file `%s'.", counter_file_name);
      }
   }

#ifdef _WITH_BURST_2
   do
   {
      if (burst_2_counter > 0)
      {
         if (fsa->debug > NORMAL_MODE)
         {
            trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL, "WMO Bursting.");
         }
      }
#endif

      /* Send all files. */
      p_file_name_buffer = file_name_buffer;
      p_file_size_buffer = file_size_buffer;
      last_update_time = time(NULL);
      local_file_size = 0;
      for (files_send = 0; files_send < files_to_send; files_send++)
      {
         (void)snprintf(fullname, MAX_PATH_LENGTH + 1, "%s/%s",
                        file_path, p_file_name_buffer);

         if (*p_file_size_buffer > 0)
         {
            int end_length = 0,
                header_length = 0,
                length_type_indicator = 10;

            if (gsf_check_fsa(p_db) != NEITHER)
            {
               fsa->job_status[(int)db.job_no].file_size_in_use = *p_file_size_buffer;
               (void)strcpy(fsa->job_status[(int)db.job_no].file_name_in_use,
                            p_file_name_buffer);
            }

            /* Open local file. */
#ifdef O_LARGEFILE
            if ((fd = open(fullname, O_RDONLY | O_LARGEFILE)) == -1)
#else
            if ((fd = open(fullname, O_RDONLY)) == -1)
#endif
            {
               trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                         "Failed to open local file `%s' : %s",
                         fullname, strerror(errno));
               wmo_quit();
               exit(OPEN_LOCAL_ERROR);
            }
            if (fsa->debug > NORMAL_MODE)
            {
                  trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                               "Open local file `%s'", fullname);
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               start_time = times(&tmsdummy);
            }
#endif

            /*
             * When the contents does not contain a bulletin header
             * it must be stored in the file name.
             */
            if (db.special_flag & FILE_NAME_IS_HEADER)
            {
               int  space_count;
               char *ptr = p_file_name_buffer;

               buffer[length_type_indicator] = 1; /* SOH */
               buffer[length_type_indicator + 1] = '\015'; /* CR */
               buffer[length_type_indicator + 2] = '\015'; /* CR */
               buffer[length_type_indicator + 3] = '\012'; /* LF */
               header_length = 4;
               space_count = 0;

               if (wmo_counter_fd > 0)
               {
                  if (next_counter(wmo_counter_fd, wmo_counter,
                                   MAX_WMO_COUNTER) < 0)
                  {
                     close_counter_file(wmo_counter_fd, &wmo_counter);
                     wmo_counter_fd = -1;
                     wmo_counter = NULL;
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "Failed to get next WMO counter.");
                  }
                  else
                  {
                     if (*wmo_counter < 10)
                     {
                        buffer[length_type_indicator + header_length] = '0';
                        buffer[length_type_indicator + header_length + 1] = '0';
                        buffer[length_type_indicator + header_length + 2] = *wmo_counter + '0';
                     }
                     else if (*wmo_counter < 100)
                          {
                             buffer[length_type_indicator + header_length] = '0';
                             buffer[length_type_indicator + header_length + 1] = (*wmo_counter / 10) + '0';
                             buffer[length_type_indicator + header_length + 2] = (*wmo_counter % 10) + '0';
                          }
                     else if (*wmo_counter < 1000)
                          {
                             buffer[length_type_indicator + header_length] = ((*wmo_counter / 100) % 10) + '0';
                             buffer[length_type_indicator + header_length + 1] = ((*wmo_counter / 10) % 10) + '0';
                             buffer[length_type_indicator + header_length + 2] = (*wmo_counter % 10) + '0';
                          }
                     buffer[length_type_indicator + header_length + 3] = '\015'; /* CR */
                     buffer[length_type_indicator + header_length + 4] = '\015'; /* CR */
                     buffer[length_type_indicator + header_length + 5] = '\012'; /* LF */
                     header_length += 6;
                  }
               } /* if (wmo_counter_fd > 0) */

               for (;;)
               {
                  while ((*ptr != '_') && (*ptr != '-') && (*ptr != ' ') &&
                         (*ptr != '\0') && (*ptr != '.') && (*ptr != ';'))
                  {
                     buffer[length_type_indicator + header_length] = *ptr;
                     header_length++; ptr++;
                  }
                  if ((*ptr == '\0') || (*ptr == '.') || (*ptr == ';'))
                  {
                     break;
                  }
                  else
                  {
                     if (space_count == 2)
                     {
                        if ((isalpha((int)(*(ptr + 1)))) &&
                            (isalpha((int)(*(ptr + 2)))) &&
                            (isalpha((int)(*(ptr + 3)))))
                        {
                           buffer[length_type_indicator + header_length] = ' ';
                           buffer[length_type_indicator + header_length + 1] = *(ptr + 1);
                           buffer[length_type_indicator + header_length + 2] = *(ptr + 2);
                           buffer[length_type_indicator + header_length + 3] = *(ptr + 3);
                           header_length += 4;
                        }
                        break;
                     }
                     else
                     {
                        buffer[length_type_indicator + header_length] = ' ';
                        header_length++; ptr++; space_count++;
                     }
                  }
               } /* for (;;) */
               buffer[length_type_indicator + header_length] = '\015'; /* CR */
               buffer[length_type_indicator + header_length + 1] = '\015'; /* CR */
               buffer[length_type_indicator + header_length + 2] = '\012'; /* LF */
               header_length += 3;
               end_length = 4;
            }

            /* Read (local) and write (remote) file. */
            no_of_bytes = 0;
            loops = (length_type_indicator + header_length + *p_file_size_buffer) / blocksize;
            rest = (length_type_indicator + header_length + *p_file_size_buffer) % blocksize;

            if ((db.special_flag & FILE_NAME_IS_HEADER) && (rest == 0))
            {
               loops--;
               rest = blocksize;
            }

            /* Write length and type indicator. */
            (void)snprintf(buffer, 9, "%08lu",
                           (unsigned long)(*p_file_size_buffer + header_length + end_length));
            if (db.transfer_mode == 'I')
            {
               buffer[length_type_indicator - 2] = 'B';
               buffer[length_type_indicator - 1] = 'I';
            }
            else if (db.transfer_mode == 'A')
                 {
                    buffer[length_type_indicator - 2] = 'A';
                    buffer[length_type_indicator - 1] = 'N';
                 }
                 else
                 {
                    buffer[length_type_indicator - 2] = 'F';
                    buffer[length_type_indicator - 1] = 'X';
                 }

            if (fsa->trl_per_process > 0)
            {
               init_limit_transfer_rate();
            }
            if (fsa->protocol_options & TIMEOUT_TRANSFER)
            {
               start_transfer_time_file = time(NULL);
            }

            for (;;)
            {
               for (j = 0; j < loops; j++)
               {
#ifdef _SIMULATE_SLOW_TRANSFER
                  (void)sleep(_SIMULATE_SLOW_TRANSFER);
#endif
                  if ((status = read(fd,
                                     (buffer + length_type_indicator + header_length),
                                     (blocksize - length_type_indicator - header_length))) != (blocksize - length_type_indicator - header_length))
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Could not read() local file `%s' : %s",
                               fullname, strerror(errno));
                     wmo_quit();
                     exit(READ_LOCAL_ERROR);
                  }
                  if ((status = wmo_write(buffer, blocksize)) != SUCCESS)
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Failed to write block from file `%s' to remote port %d [%d].",
                               p_file_name_buffer, db.port, status);
                     wmo_quit();
                     exit(eval_timeout(WRITE_REMOTE_ERROR));
                  }
                  if (fsa->trl_per_process > 0)
                  {
                     limit_transfer_rate(blocksize, fsa->trl_per_process,
                                         clktck);
                  }

                  no_of_bytes += blocksize;

                  if (gsf_check_fsa(p_db) != NEITHER)
                  {
                     fsa->job_status[(int)db.job_no].file_size_in_use_done = no_of_bytes;
                     fsa->job_status[(int)db.job_no].file_size_done += blocksize;
                     fsa->job_status[(int)db.job_no].bytes_send += blocksize;
                     if (fsa->protocol_options & TIMEOUT_TRANSFER)
                     {
                        end_transfer_time_file = time(NULL);
                        if (end_transfer_time_file < start_transfer_time_file)
                        {
                           start_transfer_time_file = end_transfer_time_file;
                        }
                        else
                        {
                           if ((end_transfer_time_file - start_transfer_time_file) > transfer_timeout)
                           {
                              trans_log(INFO_SIGN, __FILE__, __LINE__, NULL, NULL,
#if SIZEOF_TIME_T == 4
                                        "Transfer timeout reached for `%s' after %ld seconds.",
#else
                                        "Transfer timeout reached for `%s' after %lld seconds.",
#endif
                                        fsa->job_status[(int)db.job_no].file_name_in_use,
                                        (pri_time_t)(end_transfer_time_file - start_transfer_time_file));
                              wmo_quit();
                              exitflag = 0;
                              exit(STILL_FILES_TO_SEND);
                           }
                        }
                     }
                  }
                  if (length_type_indicator > 0)
                  {
                     length_type_indicator = 0;
                     header_length = 0;
                  }
               } /* for (j = 0; j < loops; j++) */

               if (rest > 0)
               {
                  if ((status = read(fd,
                                     (buffer + length_type_indicator + header_length),
                                     (rest - length_type_indicator - header_length))) != (rest - length_type_indicator - header_length))
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Could not read() local file `%s' : %s",
                               fullname, strerror(errno));
                     wmo_quit();
                     exit(READ_LOCAL_ERROR);
                  }
                  if (end_length == 4)
                  {
                     buffer[rest] = '\015';
                     buffer[rest + 1] = '\015';
                     buffer[rest + 2] = '\012';
                     buffer[rest + 3] = 3;  /* ETX */
                  }
                  if ((status = wmo_write(buffer, rest + end_length)) != SUCCESS)
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Failed to write rest of file to remote port %d [%d].",
                               p_file_name_buffer, db.port, status);
                     wmo_quit();
                     exit(eval_timeout(WRITE_REMOTE_ERROR));
                  }
                  if (fsa->trl_per_process > 0)
                  {
                     limit_transfer_rate(rest + end_length,
                                         fsa->trl_per_process, clktck);
                  }

                  no_of_bytes += rest + end_length;

                  if (gsf_check_fsa(p_db) != NEITHER)
                  {
                     fsa->job_status[(int)db.job_no].file_size_in_use_done = no_of_bytes;
                     fsa->job_status[(int)db.job_no].file_size_done += rest;
                     fsa->job_status[(int)db.job_no].bytes_send += rest;
                  }
               }

               /*
                * Since there are always some users sending files to the
                * AFD not in dot notation, lets check here if this is really
                * the EOF.
                * If not lets continue so long until we hopefully have reached
                * the EOF.
                * NOTE: This is NOT a fool proof way. There must be a better
                *       way!
                */
               if (fstat(fd, &stat_buf) == -1)
               {
                  (void)rec(transfer_log_fd, DEBUG_SIGN,
                            "Hmmm. Failed to stat() `%s' : %s (%s %d)\n",
                            fullname, strerror(errno), __FILE__, __LINE__);
                  break;
               }
               else
               {
                  if (stat_buf.st_size > *p_file_size_buffer)
                  {
                     char sign[LOG_SIGN_LENGTH];

                     if (db.special_flag & SILENT_NOT_LOCKED_FILE)
                     {
                        (void)memcpy(sign, DEBUG_SIGN, LOG_SIGN_LENGTH);
                     }
                     else
                     {
                        (void)memcpy(sign, WARN_SIGN, LOG_SIGN_LENGTH);
                     }

                     loops = (stat_buf.st_size - *p_file_size_buffer) / blocksize;
                     rest = (stat_buf.st_size - *p_file_size_buffer) % blocksize;
                     *p_file_size_buffer = stat_buf.st_size;

                     /*
                      * Give a warning in the receive log, so some action
                      * can be taken against the originator.
                      */
                     receive_log(sign, __FILE__, __LINE__, 0L, db.id.job,
                                 "File `%s' for host %s was DEFINITELY send without any locking. #%x",
                                 p_file_name_buffer, fsa->host_dsp_name, db.id.job);
                  }
                  else
                  {
                     break;
                  }
               }
            } /* for (;;) */

            if (db.special_flag & WMO_CHECK_ACKNOWLEDGE)
            {
               int ret;

               if ((ret = wmo_check_reply()) == INCORRECT)
               {
                  trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                            "Failed to receive reply from port %d for file %s.",
                            db.port, p_file_name_buffer);
                  wmo_quit();
                  exit(eval_timeout(CHECK_REPLY_ERROR));
               }
               else if (ret == NEGATIV_ACKNOWLEDGE)
                    {
                       trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                                 "Received negative acknowledge from remote port %d for file %s.",
                                 db.port, p_file_name_buffer);
                    }
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               end_time = times(&tmsdummy);
            }
#endif

            /* Close local file. */
            if (close(fd) == -1)
            {
               (void)rec(transfer_log_fd, WARN_SIGN,
                         "%-*s[%d]: Failed to close() local file %s : %s (%s %d)\n",
                         MAX_HOSTNAME_LENGTH, tr_hostname, (int)db.job_no,
                         p_file_name_buffer, strerror(errno),
                         __FILE__, __LINE__);
               /*
                * Since we usually do not send more then 100 files and
                * sf_wmo() will exit(), there is no point in stopping
                * the transmission.
                */
            }
         }
         else
         {
            trans_log(INFO_SIGN, __FILE__, __LINE__, NULL, NULL,
                      "File `%s' is of zero length, ignoring.",
                      p_file_name_buffer);
         }

         /* Update FSA, one file transmitted. */
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            fsa->job_status[(int)db.job_no].file_name_in_use[0] = '\0';
            fsa->job_status[(int)db.job_no].no_of_files_done++;
            fsa->job_status[(int)db.job_no].file_size_in_use = 0;
            fsa->job_status[(int)db.job_no].file_size_in_use_done = 0;
            local_file_size += *p_file_size_buffer;
            local_file_counter += 1;

            now = time(NULL);
            if (now >= (last_update_time + LOCK_INTERVAL_TIME))
            {
               last_update_time = now;
               update_tfc(local_file_counter, local_file_size,
                          p_file_size_buffer, files_to_send,
                          files_send, now);
               local_file_size = 0;
               local_file_counter = 0;
            }
         }

#ifdef _WITH_TRANS_EXEC
         if (db.special_flag & TRANS_EXEC)
         {
            trans_exec(file_path, fullname, p_file_name_buffer, clktck);
         }
#endif

#ifdef _OUTPUT_LOG
         if (db.output_log == YES)
         {
            if (ol_fd == -2)
            {
# ifdef WITHOUT_FIFO_RW_SUPPORT
               output_log_fd(&ol_fd, &ol_readfd, &db.output_log);
# else
               output_log_fd(&ol_fd, &db.output_log);
# endif
            }
            if ((ol_fd > -1) && (ol_data == NULL))
            {
               output_log_ptrs(&ol_retries,
                               &ol_job_number,
                               &ol_data,              /* Pointer to buffer.      */
                               &ol_file_name,
                               &ol_file_name_length,
                               &ol_archive_name_length,
                               &ol_file_size,
                               &ol_unl,
                               &ol_size,
                               &ol_transfer_time,
                               &ol_output_type,
                               db.host_alias,
                               (current_toggle - 1),
                               WMO,
                               &db.output_log);
            }
         }
#endif

         /* Now archive file if necessary. */
         if ((db.archive_time > 0) &&
             (p_db->archive_dir[0] != FAILED_TO_CREATE_ARCHIVE_DIR))
         {
#ifdef WITH_ARCHIVE_COPY_INFO
            int ret;
#endif

            /*
             * By telling the function archive_file() that this
             * is the first time to archive a file for this job
             * (in struct p_db) it does not always have to check
             * whether the directory has been created or not. And
             * we ensure that we do not create duplicate names
             * when adding db.archive_time to msg_name.
             */
#ifdef WITH_ARCHIVE_COPY_INFO
            if ((ret = archive_file(file_path, p_file_name_buffer, p_db)) < 0)
#else
            if (archive_file(file_path, p_file_name_buffer, p_db) < 0)
#endif
            {
               if (fsa->debug > NORMAL_MODE)
               {
                  trans_db_log(ERROR_SIGN, __FILE__, __LINE__, NULL,
                               "Failed to archive file `%s'",
                               p_file_name_buffer);
               }

               /*
                * NOTE: We _MUST_ delete the file we just send,
                *       else the file directory will run full!
                */
               if (unlink(fullname) == -1)
               {
                  system_log(ERROR_SIGN, __FILE__, __LINE__,
                             "Could not unlink() local file `%s' after sending it successfully : %s",
                             fullname, strerror(errno));
               }

#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
                  (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
                  *ol_file_name_length = (unsigned short)strlen(ol_file_name);
                  ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
                  ol_file_name[*ol_file_name_length + 1] = '\0';
                  (*ol_file_name_length)++;
                  *ol_file_size = *p_file_size_buffer;
                  *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
                  *ol_retries = db.retries;
                  *ol_unl = db.unl;
                  *ol_transfer_time = end_time - start_time;
                  *ol_archive_name_length = 0;
                  *ol_output_type = OT_NORMAL_DELIVERED + '0';
                  ol_real_size = *ol_file_name_length + ol_size;
                  if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "write() error : %s", strerror(errno));
                  }
               }
#endif
            }
            else
            {
               if (fsa->debug > NORMAL_MODE)
               {
                  trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                               "Archived file `%s'", p_file_name_buffer);
               }
#ifdef WITH_ARCHIVE_COPY_INFO
               if (ret == DATA_COPIED) 
               {
                  archived_copied++;
               }
#endif

#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
                  (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
                  *ol_file_name_length = (unsigned short)strlen(ol_file_name);
                  ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
                  ol_file_name[*ol_file_name_length + 1] = '\0';
                  (*ol_file_name_length)++;
                  (void)strcpy(&ol_file_name[*ol_file_name_length + 1],
                               &db.archive_dir[db.archive_offset]);
                  *ol_file_size = *p_file_size_buffer;
                  *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
                  *ol_retries = db.retries;
                  *ol_unl = db.unl;
                  *ol_transfer_time = end_time - start_time;
                  *ol_archive_name_length = (unsigned short)strlen(&ol_file_name[*ol_file_name_length + 1]);
                  *ol_output_type = OT_NORMAL_DELIVERED + '0';
                  ol_real_size = *ol_file_name_length +
                                 *ol_archive_name_length + 1 + ol_size;
                  if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "write() error : %s", strerror(errno));
                  }
               }
#endif
            }
         }
         else
         {
#ifdef WITH_UNLINK_DELAY
            int unlink_loops = 0;

try_again_unlink:
#endif
            /* Delete the file we just have send. */
            if (unlink(fullname) == -1)
            {
#ifdef WITH_UNLINK_DELAY
               if ((errno == EBUSY) && (unlink_loops < 20))
               {
                  (void)my_usleep(100000L);
                  unlink_loops++;
                  goto try_again_unlink;
               }
#endif
               system_log(ERROR_SIGN, __FILE__, __LINE__,
                          "Could not unlink() local file %s after sending it successfully : %s",
                          fullname, strerror(errno));
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
               (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
               *ol_file_name_length = (unsigned short)strlen(ol_file_name);
               ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
               ol_file_name[*ol_file_name_length + 1] = '\0';
               (*ol_file_name_length)++;
               *ol_file_size = *p_file_size_buffer;
               *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
               *ol_retries = db.retries;
               *ol_unl = db.unl;
               *ol_transfer_time = end_time - start_time;
               *ol_archive_name_length = 0;
               *ol_output_type = OT_NORMAL_DELIVERED + '0';
               ol_real_size = *ol_file_name_length + ol_size;
               if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
               {
                  system_log(ERROR_SIGN, __FILE__, __LINE__,
                             "write() error : %s", strerror(errno));
               }
            }
#endif
         }

         /*
          * After each successful transfer set error
          * counter to zero, so that other jobs can be
          * started.
          */
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            if ((*p_file_size_buffer > 0) && (fsa->error_counter > 0))
            {
               int  fd,
#ifdef WITHOUT_FIFO_RW_SUPPORT
                    readfd,
#endif
                    j;
               char fd_wake_up_fifo[MAX_PATH_LENGTH];

#ifdef LOCK_DEBUG
               lock_region_w(fsa_fd, db.lock_offset + LOCK_EC, __FILE__, __LINE__);
#else
               lock_region_w(fsa_fd, db.lock_offset + LOCK_EC);
#endif
               fsa->error_counter = 0;

               /*
                * Wake up FD!
                */
               (void)snprintf(fd_wake_up_fifo, MAX_PATH_LENGTH, "%s%s%s",
                              p_work_dir, FIFO_DIR, FD_WAKE_UP_FIFO);
#ifdef WITHOUT_FIFO_RW_SUPPORT
               if (open_fifo_rw(fd_wake_up_fifo, &readfd, &fd) == -1)
#else
               if ((fd = open(fd_wake_up_fifo, O_RDWR)) == -1)
#endif
               {
                  system_log(WARN_SIGN, __FILE__, __LINE__,
                             "Failed to open() FIFO %s : %s",
                             fd_wake_up_fifo, strerror(errno));
               }
               else
               {
                  if (write(fd, "", 1) != 1)
                  {
                     system_log(WARN_SIGN, __FILE__, __LINE__,
                                "Failed to write() to FIFO %s : %s",
                                fd_wake_up_fifo, strerror(errno));
                  }
#ifdef WITHOUT_FIFO_RW_SUPPORT
                  if (close(readfd) == -1)
                  {
                     system_log(DEBUG_SIGN, __FILE__, __LINE__,
                                "Failed to close() FIFO %s (read) : %s",
                                fd_wake_up_fifo, strerror(errno));
                  }
#endif
                  if (close(fd) == -1)
                  {
                     system_log(DEBUG_SIGN, __FILE__, __LINE__,
                                "Failed to close() FIFO %s : %s",
                                fd_wake_up_fifo, strerror(errno));
                  }
               }

               /*
                * Remove the error condition (NOT_WORKING) from all jobs
                * of this host.
                */
               for (j = 0; j < fsa->allowed_transfers; j++)
               {
                  if ((j != db.job_no) &&
                      (fsa->job_status[j].connect_status == NOT_WORKING))
                  {
                     fsa->job_status[j].connect_status = DISCONNECT;
                  }
               }
               fsa->error_history[0] = 0;
               fsa->error_history[1] = 0;
#ifdef LOCK_DEBUG
               unlock_region(fsa_fd, db.lock_offset + LOCK_EC, __FILE__, __LINE__);
#else
               unlock_region(fsa_fd, db.lock_offset + LOCK_EC);
#endif

#ifdef LOCK_DEBUG
               lock_region_w(fsa_fd, db.lock_offset + LOCK_HS, __FILE__, __LINE__);
#else
               lock_region_w(fsa_fd, db.lock_offset + LOCK_HS);
#endif
               now = time(NULL);
               if (now > fsa->end_event_handle)
               {
                  fsa->host_status &= ~(EVENT_STATUS_FLAGS | AUTO_PAUSE_QUEUE_STAT);
                  if (fsa->end_event_handle > 0L)
                  {
                     fsa->end_event_handle = 0L;
                  }
                  if (fsa->start_event_handle > 0L)
                  {
                     fsa->start_event_handle = 0L;
                  }
               }
               else
               {
                  fsa->host_status &= ~(EVENT_STATUS_STATIC_FLAGS | AUTO_PAUSE_QUEUE_STAT);
               }
#ifdef LOCK_DEBUG
               unlock_region(fsa_fd, db.lock_offset + LOCK_HS, __FILE__, __LINE__);
#else
               unlock_region(fsa_fd, db.lock_offset + LOCK_HS);
#endif

               /*
                * Since we have successfully transmitted a file, no need to
                * have the queue stopped anymore.
                */
               if (fsa->host_status & AUTO_PAUSE_QUEUE_STAT)
               {
                  char sign[LOG_SIGN_LENGTH];

                  error_action(fsa->host_alias, "stop", HOST_ERROR_ACTION);
                  event_log(0L, EC_HOST, ET_EXT, EA_ERROR_END, "%s",
                            fsa->host_alias);
                  if ((fsa->host_status & HOST_ERROR_OFFLINE_STATIC) ||
                      (fsa->host_status & HOST_ERROR_OFFLINE) ||
                      (fsa->host_status & HOST_ERROR_OFFLINE_T))
                  {
                     (void)memcpy(sign, OFFLINE_SIGN, LOG_SIGN_LENGTH);
                  }
                  else
                  {
                     (void)memcpy(sign, INFO_SIGN, LOG_SIGN_LENGTH);
                  }
                  trans_log(sign, __FILE__, __LINE__, NULL, NULL,
                            "Starting input queue that was stopped by init_afd.");
                  event_log(0L, EC_HOST, ET_AUTO, EA_START_QUEUE, "%s",
                            fsa->host_alias);
               }
            } /* if (fsa->error_counter > 0) */
#ifdef WITH_ERROR_QUEUE
            if (fsa->host_status & ERROR_QUEUE_SET)
            {
               remove_from_error_queue(db.id.job, fsa, db.fsa_pos, fsa_fd);
            }
#endif
            if (fsa->host_status & HOST_ACTION_SUCCESS)
            {
               error_action(fsa->host_alias, "start", HOST_SUCCESS_ACTION);
            }
         }

         p_file_name_buffer += MAX_FILENAME_LENGTH;
         p_file_size_buffer++;
      } /* for (files_send = 0; files_send < files_to_send; files_send++) */

#ifdef WITH_ARCHIVE_COPY_INFO
      if (archived_copied > 0)
      {
         trans_log(DEBUG_SIGN, __FILE__, __LINE__, NULL, NULL,
                   "Copied %u files to archive.", archived_copied);
         archived_copied = 0;
      }
#endif

      if (local_file_counter)
      {
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            update_tfc(local_file_counter, local_file_size,
                       p_file_size_buffer, files_to_send, files_send,
                       time(NULL));
            local_file_size = 0;
            local_file_counter = 0;
         }
      }

      /*
       * Remove file directory, but only when all files have
       * been transmitted.
       */
      if ((files_to_send == files_send) || (files_to_send < 1))
      {
         if (rmdir(file_path) < 0)
         {
            system_log(ERROR_SIGN, __FILE__, __LINE__,
                       "Failed to remove directory %s : %s",
                       file_path, strerror(errno));
         }
      }
      else
      {
         system_log(WARN_SIGN, __FILE__, __LINE__,
                    "There are still %d files for %s. Will NOT remove this job!",
                    files_to_send - files_send, file_path);
         exit_status = STILL_FILES_TO_SEND;
      }

#ifdef _WITH_BURST_2
      burst_2_counter++;
      diff_time = time(NULL) - connected;
      if (((fsa->protocol_options & KEEP_CONNECTED_DISCONNECT) &&
           (db.keep_connected > 0) && (diff_time > db.keep_connected)) ||
          ((db.disconnect > 0) && (diff_time > db.disconnect)))
      {
         cb2_ret = NO;
         break;
      }
   } while ((cb2_ret = check_burst_sf(file_path, &files_to_send, 0,
# ifdef _WITH_INTERRUPT_JOB
                                      0,
# endif
# ifdef _OUTPUT_LOG
                                      &ol_fd,
# endif
# ifndef AFDBENCH_CONFIG
                                      NULL,
# endif
                                      NULL)) == YES);
   burst_2_counter--;

   if (cb2_ret == NEITHER)
   {
      exit_status = STILL_FILES_TO_SEND;
   }
#endif /* _WITH_BURST_2 */

   free(buffer);

   /* Disconnect from remote port. */
   wmo_quit();
   if ((fsa != NULL) && (fsa->debug > NORMAL_MODE))
   {
      trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                   "Disconnected from port %d.", db.port);
   }

   if (wmo_counter_fd > 0)
   {
      close_counter_file(wmo_counter_fd, &wmo_counter);
   }

   exitflag = 0;
   exit(exit_status);
}
示例#18
0
文件: rec.c 项目: blueskycoco/hp
int main(int argc, char *argv[])
{

	pid_t fpid;	
	int msgid = -1;

	msgid = msgget((key_t)1234, 0666 | IPC_CREAT);  
	if(msgid == -1)  
	{  
		fprintf(stderr, "msgget failed with error: %d\n", errno);  
		exit(-1);  
	}

	fpid=fork();
	if(fpid<0)
		printf("fork failed\n");
	else if(fpid==0)
	{
		//child process,capture audio when main process send start cmd, finish when receive stop cmd
		//rec((char *)argv[1]);		
		long int msgtype = 8;//MAIN_TO_AUDIO 8
		struct msg_st data_r;
		while(1)
		{
			printf("waiting audio capt cmd...\n");
			msgrcv(msgid, (void*)&data_r, sizeof(struct msg_st)-sizeof(long int), msgtype, 0);
			printf("data_r id %d,text %d\n",data_r.msg_type,data_r.id);
			switch (data_r.id)
			{
				case 0://start rec
				{
					rec("/tmp/rec.avi");
				}
				break;
				case 2://start transfer string and play
				{
					play(data_r.text,"/tmp/3.wav");
					playback("/tmp/3.wav");
				}
				break;
				default:
					break;
			}
		}
	}
	else
	{
		//father process
		long int msgtype = 8;//MAIN_TO_AUDIO 8
		struct msg_st data_r;
		int status;
		while(1)
		{
			ms_sleep(2);
			data_r.msg_type = 8;
			data_r.id=0;
			printf("start record\n");
			if(msgsnd(msgid, (void*)&data_r, sizeof(struct msg_st)-sizeof(long int), IPC_NOWAIT) == -1)  
			{  
				fprintf(stderr, "msgsnd failed %s msgid %d\n",strerror(errno),msgid);  
				exit(1);  
			}  
			ms_sleep(3);
			data_r.msg_type = 8;
			data_r.id=1;  
			printf("stop record\n");
			if(msgsnd(msgid, (void*)&data_r, sizeof(struct msg_st)-sizeof(long int), IPC_NOWAIT) == -1)  
			{  
				fprintf(stderr, "msgsnd failed %s\n",strerror(errno));  
				exit(1);  
			} 
			printf("waiting message 7\n"); 
			msgtype=7;
			msgrcv(msgid, (void*)&data_r, sizeof(struct msg_st)-sizeof(long int), msgtype, 0);

			printf("Get Result %s\n",data_r.text);
			
			data_r.msg_type = 8;    //注意2
			data_r.id=2;  
			printf("start transfer and playback\n");
			if(msgsnd(msgid, (void*)&data_r, sizeof(struct msg_st)-sizeof(long int), IPC_NOWAIT) == -1)  
			{  
				fprintf(stderr, "msgsnd failed %s\n",strerror(errno));  
				exit(1);  
			}
			system("rm /tmp/rec.avi");
			//system("ipcs -q");
		}
		waitpid(fpid, &status, 0);
	}
	return 0;
}
示例#19
0
int rec() {
  printf(1,".");
  rec();
  return 0;
}
示例#20
0
文件: rec1.c 项目: Ingramz/analyzer
main () {
  rec(1);
}
示例#21
0
int getMaxResult(void) {
	memset(a, -1, sizeof(a));
	return rec(0, W);
}