Пример #1
0
void SafePluginMap::loadFromList(const char * pluginsList)
{
    const char *pluginDir = pluginsList;
    for (;*pluginDir;)
    {
        StringBuffer thisPlugin;
        while (*pluginDir && *pluginDir != ENVSEPCHAR)
            thisPlugin.append(*pluginDir++);
        if(*pluginDir)
            pluginDir++;

        if(!thisPlugin.length())
            continue;

        Owned<IFile> file = createIFile(thisPlugin.str());
        if (file->isDirectory() == foundYes)
            loadFromDirectory(thisPlugin);
        else
        {
            StringBuffer tail;
            splitFilename(thisPlugin, NULL, NULL, &tail, &tail);
            addPlugin(thisPlugin, tail.str());
        }
    }
}
Пример #2
0
    virtual bool finalizeOptions(IProperties *globals)
    {
        if (!EclCmdCommon::finalizeOptions(globals))
        {
            usage();
            return false;
        }
        StringBuffer err;
        if (optFileName.isEmpty())
            err.append("\n ... Missing package file name\n\n");
        else if (optTarget.isEmpty())
            err.append("\n ... Specify a cluster name\n\n");

        if (err.length())
        {
            fprintf(stdout, "%s", err.str());
            usage();
            return false;
        }

        if (optProcess.isEmpty())
            optProcess.set("*");

        if (optPackageMapId.isEmpty())
        {
            StringBuffer name;
            splitFilename(optFileName.get(), NULL, NULL, &name, &name);
            optPackageMapId.set(name.str());
        }
        optPackageMapId.toLowerCase();
        return true;
    }
Пример #3
0
	// ----------------------------------------------------------------------------------------------------------------------------------------------
	void StringUtil::splitFullFilename(	const Ogre::String& qualifiedName, 
		Ogre::String& outBasename, Ogre::String& outExtention, Ogre::String& outPath )
	{
		Ogre::String fullName;
		splitFilename( qualifiedName, fullName, outPath );
		splitBaseFilename( fullName, outBasename, outExtention );
	}
Пример #4
0
int main(int argc, char **argv) 
{ 
    InitModuleObjects();

    addAbortHandler(ControlHandler);

    try
    { 
        StringBuffer codeDirectory;
        splitFilename(argv[0], &codeDirectory, &codeDirectory, NULL, NULL);
        if (!codeDirectory.length())
            codeDirectory.append(".");
        
        execSvr.setown(new CEclAgentExecutionServer());
        execSvr->start(codeDirectory);
    } 
    catch (...)
    {
        printf("Unexpected error running agentexec server\r\n");
    }
    if (execSvr)
    {
        execSvr->stop();
    }

    releaseAtoms();
    ExitModuleObjects();

    return 0;
} 
Пример #5
0
void CppCompiler::addLibrary(const char * libName)
{
    if (verbose)
        PrintLog("addLibrary %s", libName);

    const char* lname = libName;
    const char * quote;
    StringBuffer path, tail; // NOTE - because of the (hacky) code below that sets lname to point within tail.str(), this must NOT be moved inside the if block
    if (targetCompiler == GccCppCompiler)
    {
        // It seems gcc compiler doesn't like things like -lmydir/libx.so
        splitFilename(libName, &path, &path, &tail, &tail);
        if(path.length())
        {
            addLibraryPath(path);
            lname = tail.str();
            // HACK - make it work with plugins. This should be handled at caller end!
            if (strncmp(lname, "lib", 3) == 0)
                lname += 3;
        }
        quote = NULL;   //quoting lib names with gcc causes link error (lib not found)
    }
    else
    {
        quote = "\"";
    }
    linkerLibraries.append(" ").append(USE_LIB_FLAG[targetCompiler]).append(quote).append(lname).append(USE_LIB_TAIL[targetCompiler]).append(quote);
}
Пример #6
0
void CodeBlocksProvider::writeFileListToProject(const FileNode &dir, std::ofstream &projectFile, const int indentation,
                                                const StringList &duplicate, const std::string &objPrefix, const std::string &filePrefix) {

	for (FileNode::NodeList::const_iterator i = dir.children.begin(); i != dir.children.end(); ++i) {
		const FileNode *node = *i;

		if (!node->children.empty()) {
			writeFileListToProject(*node, projectFile, indentation + 1, duplicate, objPrefix + node->name + '_', filePrefix + node->name + '/');
		} else {
			std::string name, ext;
			splitFilename(node->name, name, ext);

			if (ext == "rc") {
				projectFile << "\t\t<Unit filename=\"" << convertPathToWin(filePrefix + node->name) << "\">\n"
				               "\t\t\t<Option compilerVar=\"WINDRES\" />\n"
				               "\t\t</Unit>\n";
			} else if (ext == "asm") {
				projectFile << "\t\t<Unit filename=\"" << convertPathToWin(filePrefix + node->name) << "\">\n"
				               "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"$(" << LIBS_DEFINE << ")bin/nasm.exe -f win32 -g $file -o $object\" />"
				               "\t\t</Unit>\n";
			} else {
				projectFile << "\t\t<Unit filename=\"" << convertPathToWin(filePrefix + node->name) << "\" />\n";
			}
		}
	}
}
Пример #7
0
ESDLcompiler::ESDLcompiler(const char * sourceFile, bool generatefile, const char *outDir, bool outputIncludes_, bool isIncludedEsdl, const char* includePath_)
{
    outputIncludes = outputIncludes_;
    modules = NULL;
    enums = NULL;
    apis=NULL;
    servs=NULL;
    msgs=NULL;
    includes=NULL;
    methods=NULL;
    versions = NULL;
    esxdlo = -1;
    StringBuffer ext;
    StringBuffer prot;
    splitFilename(sourceFile, &prot, &srcDir, &name, &ext);

    if (includePath_ && *includePath_)
        includeDirs.appendList(includePath_, ENVSEPSTR);

    filename = strdup(sourceFile);

    yyin = fopen(sourceFile, "rt");
    if (!yyin)
    {
        if (isIncludedEsdl)
        {
            StringBuffer locatedFilePath;
            bool located = locateIncludedFile(locatedFilePath, prot.str(), srcDir.str(), name.str(), ext.str());
            if( located)
                yyin = fopen(locatedFilePath.str(), "rt");
            if (!yyin)
            {
                fprintf(stderr, "Fatal Error: Could not load included ESDL grammar %s\n", filename);
                exit(1);
            }
        }
        else
        {
            fprintf(stderr, "Fatal Error: Could not load ESDL grammar %s\n", sourceFile);
            exit(1);
        }

    }

    packagename = es_gettail(sourceFile);

    if (generatefile)
    {
        if (!outDir || !*outDir)
            outDir = srcDir.str();

        char* targetBase = getTargetBase(outDir, sourceFile);

        esxdlo = es_createFile(targetBase,"xml");

        free(targetBase);
    }
}
Пример #8
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf
            ("frunssh <nodelistfile> \"command\" [options] \n"
            "    options: -i:<identity-file> \n"
            "             -u:<user> \n"
            "             -n:<number_of_threads>\n"
            "             -t:<connect-timeout-secs>\n"
            "             -a:<connect-attempts>\n"
            "             -d:<working_directory>\n"
            "             -s                -- strict, must match known_hosts\n"
            "             -b                -- background\n"
            "             -pw:<password>    -- INSECURE: requires pssh (NB identity file preferred)\n"
            "             -pe:<password>    -- INSECURE: as -pw except encrypted password\n"
            "             -pl               -- use plink (on windows)\n"
            "             -v                -- verbose, lists commands run\n"
            "             -d                -- dry run (for testing, enables verbose)\n"
            );
        return 255;
    }


    InitModuleObjects();

#ifndef __64BIT__
    // Restrict stack sizes on 32-bit systems
    Thread::setDefaultStackSize(0x10000);   // NB under windows requires linker setting (/stack:)
#endif

    try  {
        StringBuffer logname;
        splitFilename(argv[0], NULL, NULL, &logname, NULL);

        Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator("frunssh");
        lf->setCreateAliasFile(false);
        lf->setMsgFields(MSGFIELD_prefix);
        lf->beginLogging();

        Owned<IFRunSSH> runssh = createFRunSSH();
        runssh->init(argc,argv);
        runssh->exec();
    }
    catch(IException *e)
    {
        EXCLOG(e,"frunssh");
        e->Release();
        res=255;
    }
    releaseAtoms();
    return res;
}
Пример #9
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf
            ("frunssh <nodelistfile> \"command\" [options] \n"
            "    options: -i:<identity-file> \n"
            "             -u:<user> \n"
            "             -n:<number_of_threads>\n"
            "             -t:<connect-timeout-secs>\n"
            "             -a:<connect-attempts>\n"
            "             -d:<working_directory>\n"
            "             -s                -- strict, must match known_hosts\n"
            "             -b                -- background\n"
            "             -pw:<password>    -- INSECURE: requires pssh (NB identity file preferred)\n"
            "             -pe:<password>    -- INSECURE: as -pw except encrypted password\n"
            "             -pl               -- use plink (on windows)\n"
            "             -v                -- verbose, lists commands run\n"
            "             -d                -- dry run (for testing, enables verbose)\n"
            );
        return 255;
    }


    InitModuleObjects();
    try  {
        StringBuffer logname;
        splitFilename(argv[0], NULL, NULL, &logname, NULL);
        StringBuffer logdir;
        if (getConfigurationDirectory(NULL,"log","frunssh",logname.str(),logdir)) {
            recursiveCreateDirectory(logdir.str());
            StringBuffer tmp(logname);
            addPathSepChar(logname.clear().append(logdir)).append(tmp);
        }
        addFileTimestamp(logname, true);
        logname.append(".log");
        appendLogFile(logname.str(),0,false);
        queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix);

        Owned<IFRunSSH> runssh = createFRunSSH();
        runssh->init(argc,argv);
        runssh->exec();
    }
    catch(IException *e)
    {
        EXCLOG(e,"frunssh");
        e->Release();
        res=255;
    }
    releaseAtoms();
    return res;
}
void localStorageInit( const std::string& fullpath)
{
	if (fullpath.empty())
        return;

	if( ! _initialized )
    {
        std::string strDBFilename = fullpath;
        splitFilename(strDBFilename);
        if (JniHelper::callStaticBooleanMethod(className, "init", strDBFilename, "data")) {
            _initialized = 1;
        }
	}
}
Пример #11
0
void SafePluginMap::loadFromDirectory(const char * pluginDirectory)
{
    const char * mask = "*" SharedObjectExtension;
    
    Owned<IFile> pluginDir = createIFile(pluginDirectory);
    Owned<IDirectoryIterator> pluginFiles = pluginDir->directoryFiles(mask,false,false);
    ForEach(*pluginFiles)
    {
        const char *thisPlugin = pluginFiles->query().queryFilename();
        StringBuffer tail;
        splitFilename(thisPlugin, NULL, NULL, &tail, &tail);
        addPlugin(thisPlugin, tail.str());
    }
}
Пример #12
0
void CMakeProvider::writeFileListToProject(const FileNode &dir, std::ofstream &projectFile, const int indentation,
                                                const StringList &duplicate, const std::string &objPrefix, const std::string &filePrefix) {

	for (FileNode::NodeList::const_iterator i = dir.children.begin(); i != dir.children.end(); ++i) {
		const FileNode *node = *i;

		if (!node->children.empty()) {
			writeFileListToProject(*node, projectFile, indentation + 1, duplicate, objPrefix + node->name + '_', filePrefix + node->name + '/');
		} else {
			std::string name, ext;
			splitFilename(node->name, name, ext);
			projectFile << "\t" << filePrefix + node->name << "\n";
		}
	}
}
Пример #13
0
bool processArgvFilename(IFileArray & filenames, const char * filename)
{
    if (filename[0] == '@')
        return processArgvFilenamesFromFile(filenames, filename+1);

    if (containsFileWildcard(filename))
    {
        StringBuffer dirPath, dirWildcard;
        splitFilename(filename, &dirPath, &dirPath, &dirWildcard, &dirWildcard);
        Owned<IDirectoryIterator> iter = createDirectoryIterator(dirPath.str(), dirWildcard.str());
        ForEach(*iter)
        {
            IFile & cur = iter->query();
            if (cur.isFile() == foundYes)
                filenames.append(OLINK(cur));
        }
    }
    else
    {
Пример #14
0
int EclCMDShell::callExternal(ArgvIterator &iter)
{
    const char *argv[100];
    StringBuffer cmdstr("ecl-");
    cmdstr.append(cmd.str());
    int i=0;
    argv[i++]=cmdstr.str();
    if (optHelp)
        argv[i++]="help";
    for (; !iter.done(); iter.next())
        argv[i++]=iter.query();
    argv[i]=NULL;
//TODO - add common routine or use existing in jlib
    // First try in same dir as the ecl executable
    StringBuffer local;
    splitFilename(queryCurrentProcessPath(), &local, &local, NULL, NULL);
    local.append(cmdstr);
    errno = 0;
#ifdef _WIN32
    if (_spawnvp(_P_WAIT, local.str(), const_cast<char **>(argv))==-1)
        return 0;
    // If not found, try the path
    if (errno!=ENOENT || _spawnvp(_P_WAIT, cmdstr.str(), const_cast<char **>(argv))==-1)
#else
    if (execvp(local.str(), const_cast<char **>(argv))!=-1)
        return 0;
    // If not found, try the path
    if (errno!=ENOENT || execvp(cmdstr.str(), const_cast<char **>(argv))==-1)
#endif
    {
        switch(errno)
        {
        case ENOENT:
            fprintf(stderr, "ecl '%s' command not found\n", cmd.str());
            return 1;
        default:
            fprintf(stderr, "ecl '%s' command error %d\n", cmd.str(), errno);
            return 1;
        }
    }
    return 0;
}
void localStorageInit( const char *fullpath)
{
    if (fullpath == NULL || strlen(fullpath) == 0) return;

    if( ! _initialized ) {
        JniMethodInfo t;

        if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "init", "(Ljava/lang/String;Ljava/lang/String;)Z")) {
            std::string strDBFilename = fullpath;
            splitFilename(strDBFilename);
            jstring jdbName = t.env->NewStringUTF(strDBFilename.c_str());
            jstring jtableName = t.env->NewStringUTF("data");
            jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, jdbName, jtableName);
            t.env->DeleteLocalRef(jdbName);
            t.env->DeleteLocalRef(jtableName);
            t.env->DeleteLocalRef(t.classID);
            if (ret) {
                _initialized = 1;
            }
        }

    }
}
Пример #16
0
void MSBuildProvider::computeFileList(const FileNode &dir, const StringList &duplicate, const std::string &objPrefix, const std::string &filePrefix) {
	for (FileNode::NodeList::const_iterator i = dir.children.begin(); i != dir.children.end(); ++i) {
		const FileNode *node = *i;

		if (!node->children.empty()) {
			// Update filter
			std::string _currentFilter = _filters.back();
			_filters.back().append((_filters.back() == "" ? "" : "\\") + node->name);

			computeFileList(*node, duplicate, objPrefix + node->name + '_', filePrefix + node->name + '/');

			// Reset filter
			_filters.push_back(_currentFilter);
		} else {
			// Filter files by extension
			std::string name, ext;
			splitFilename(node->name, name, ext);

			FileEntry entry;
			entry.name = name;
			entry.path = convertPathToWin(filePrefix + node->name);
			entry.filter = _filters.back();
			entry.prefix = objPrefix;

			if (ext == "cpp" || ext == "c")
				_compileFiles.push_back(entry);
			else if (ext == "h")
				_includeFiles.push_back(entry);
			else if (ext == "rc")
				_resourceFiles.push_back(entry);
			else if (ext == "asm")
				_asmFiles.push_back(entry);
			else
				_otherFiles.push_back(entry);
		}
	}
}
Пример #17
0
int main(int argc, const char *argv[])
{
    InitModuleObjects();

    int ret = 0;
    bool dryRun = false;
    bool offline = false;
    StringAttr daliServer, envPath;

    enum CmdType { cmd_none, cmd_swap, cmd_auto, cmd_history, cmd_email, cmd_swapped, cmd_reset, cmd_resetspares, cmd_addspares, cmd_removespares, cmd_resethistory };
    CmdType cmd = cmd_none;

    ArgvIterator iter(argc, argv);

    try
    {
        bool stop=false;
        StringArray params;
        for (; !ret&&!iter.done(); iter.next())
        {
            const char *arg = iter.query();
            if ('-' == *arg)
            {
                bool value;
                if (iter.matchFlag(value, "-dryrun"))
                    dryRun = value;
                else if (iter.matchFlag(value, "-offline"))
                    offline = value;
                else
                {
                    PROGLOG("Unknown option");
                    ret = 2;
                    usage();
                    break;
                }
            }
            else
            {
                switch (cmd)
                {
                    case cmd_none:
                        if (strieq("swap", arg))
                            cmd = cmd_swap;
                        else if (strieq("auto", arg))
                            cmd = cmd_auto;
                        else if (strieq("history", arg))
                            cmd = cmd_history;
                        else if (strieq("email", arg))
                            cmd = cmd_email;
                        else if (strieq("swapped", arg))
                            cmd = cmd_swapped;
                        else if (strieq("reset", arg))
                            cmd = cmd_reset;
                        else if (strieq("resetspares", arg))
                            cmd = cmd_resetspares;
                        else if (strieq("addspares", arg))
                            cmd = cmd_addspares;
                        else if (strieq("removespares", arg))
                            cmd = cmd_removespares;
                        else if (strieq("resethistory", arg))
                            cmd = cmd_resethistory;
                        else
                        {
                            PROGLOG("Unknown command");
                            usage();
                            ret = 2;
                        }
                        break;
                    default:
                        params.append(iter.query());
                        break;
                }
            }
        }
        unsigned requiredParams=UINT_MAX;
        switch (cmd)
        {
            case cmd_swap:
                requiredParams = 4;
                break;
            case cmd_addspares:
            case cmd_removespares:
                requiredParams = 3;
                break;
            case cmd_auto:
            case cmd_history:
            case cmd_email:
            case cmd_swapped:
            case cmd_reset:
            case cmd_resetspares:
            case cmd_resethistory:
                requiredParams = 2;
                break;
        }
        if (params.ordinality() < requiredParams)
        {
            usage();
            ret = 2;
        }
        else
        {
            StringAttr daliServer = params.item(0);
            StringAttr clusterName = params.item(1);

            DaliClient dclient(daliServer);
            StringBuffer logname;
            splitFilename(argv[0], NULL, NULL, &logname, NULL);
            addFileTimestamp(logname, true);
            logname.append(".log");
            StringBuffer lf;
            openLogFile(lf, logname.str(),0,false,true);
            queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix);

            Owned<IRemoteConnection> conn = querySDS().connect("/Environment", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT);
            IPropertyTree *environment = conn->queryRoot();
            StringBuffer xpath("Software/ThorCluster[@name=\"");
            xpath.append(clusterName).append("\"]");
            IPropertyTree *cluster = environment->queryPropTree(xpath.str());
            if (!cluster)
            {
                PROGLOG("Unknown cluster: %s", clusterName.get());
                ret = 3;
            }
            if (!ret)
            {
                Owned<IPropertyTree> options = createPTreeFromIPT(cluster);
                conn.clear();
                if (options&&options->getPropBool("@enableSysLog",true))
                    UseSysLogForOperatorMessages();

                switch (cmd)
                {
                    case cmd_auto:
                    {
                        if (!autoSwapNode(clusterName, dryRun))
                            ret = 3;
                        break;
                    }
                    case cmd_swap:
                    {
                        const char *oldip=params.item(2);
                        const char *newip=params.item(3);
                        if (!swapNode(clusterName, oldip, newip))
                            ret = 3;
                        break;
                    }
                    case cmd_history:
                    case cmd_swapped:
                    case cmd_email:
                    {
                        unsigned days = params.isItem(2) ? atoi(params.item(2)) : 0; // for history or swapped
                        switch (cmd)
                        {
                            case cmd_history:
                                swapNodeHistory(clusterName, days, NULL);
                                break;
                            case cmd_swapped:
                                swappedList(clusterName, days, NULL);
                                break;
                            case cmd_email:
                            {
                                bool sendSwapped = false;
                                bool sendHistory = false;
                                if (params.isItem(2))
                                {
                                    if (strieq("swapped", params.item(2)))
                                        sendSwapped = true;
                                    else if (strieq("history", params.item(2)))
                                        sendHistory = true;
                                }
                                emailSwap(clusterName, NULL, true, sendSwapped, sendHistory);
                                break;
                            }
                        }
                        break;
                    }
                    case cmd_reset:
                    case cmd_resetspares:
                    {
                        StringBuffer response;
                        if (!resetClusterGroup(clusterName, "ThorCluster", cmd==cmd_resetspares, response))
                        {
                            WARNLOG("%s", response.str());
                            ret = 3;
                        }
                        break;
                    }
                    case cmd_addspares:
                    case cmd_removespares:
                    {
                        SocketEndpointArray allEps;
                        unsigned p=2;
                        do
                        {
                            const char *ipOrRange = params.item(p);
                            SocketEndpointArray epa;
                            epa.fromText(ipOrRange, 0);
                            ForEachItemIn(e, epa)
                                allEps.append(epa.item(e));
                            p++;
                        }
                        while (p<params.ordinality());
                        StringBuffer response;
                        bool res;
                        if (cmd == cmd_addspares)
                            res = addClusterSpares(clusterName, "ThorCluster", allEps, response);
                        else
                            res = removeClusterSpares(clusterName, "ThorCluster", allEps, response);
                        if (!res)
                        {
                            WARNLOG("%s", response.str());
                            ret = 3;
                        }
                        break;
                    }
                    case cmd_resethistory:
                    {
                        Owned<IRemoteConnection> conn = querySDS().connect("/SwapNode", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT);
                        if (conn)
                        {
                            StringBuffer groupName;
                            getClusterGroupName(*options, groupName);
                            VStringBuffer xpath("Thor[@group=\"%s\"]", groupName.str());
                            if (conn->queryRoot()->removeProp(xpath.str()))
                                PROGLOG("SwapNode info for cluster %s removed", clusterName.get());
                            else
                                PROGLOG("SwapNode info for cluster %s not found", clusterName.get());
                        }
                        break;
                    }
                }
            }
        }
        UseSysLogForOperatorMessages(false);
    }
    catch (IException *e) {
        EXCLOG(e,"SWAPNODE");
        e->Release();
        ret = -1;
    }

    ExitModuleObjects();
    return ret;
}
Пример #18
0
bool QueryHelper::doit(FILE * fp)
{
    Owned<IClientWUCreateRequest> creq = wuclient->createWUCreateRequest();
    Owned<IClientWUCreateResponse> cresp = wuclient->WUCreate(creq);
    const IMultiException* excep = &cresp->getExceptions();
    if(excep != NULL && excep->ordinality() > 0)
    {
        StringBuffer msg;
        excep->errorMessage(msg);
        printf("%s\n", msg.str());
        return false;
    }

    IConstECLWorkunit* wu = &cresp->getWorkunit();
    if(!wu)
    {
        printf("can't create workunit\n");
        return false;
    }

    Owned<IClientWUUpdateRequest> ureq = wuclient->createWUUpdateRequest();
    ureq->setWuid(wu->getWuid());

    // Make a workUnit
    StringBuffer jobname;
    if(globals->hasProp("jobname"))
        jobname.append(globals->queryProp("jobname"));

    StringBuffer ecl;
    if (globals->getProp("ecl", ecl))
    {
        if (ecl.length() && ecl.charAt(0)=='@')
        {
            StringBuffer filename(ecl.str()+1);
            ecl.clear().loadFile(filename);
            if (jobname.length() == 0)
                splitFilename(filename, NULL, NULL, &jobname, NULL);
        }
        ureq->setQueryText(ecl.str());
    }
    else if (globals->hasProp("main"))
        ureq->setQueryMainDefinition(globals->queryProp("main"));
    else if (globals->hasProp("attr"))
        ureq->setQueryText(globals->queryProp("attr"));

    if (globals->getPropInt("compileOnly", 0)!=0)
        ureq->setAction(WUActionCompile);
    if (jobname.length())
        ureq->setJobname(jobname);

    IArrayOf<IEspDebugValue> dvals;
    IArrayOf<IEspApplicationValue> avals;
    StringBuffer xmlParams;

    Owned<IPropertyIterator> it = globals->getIterator();
    bool xmlSeen = false;
    ForEach(*it)
    {
        const char * key = it->getPropKey();
        if (key && strlen(key)>1)
        {
            if(key[0] == '-')
            {
                if (key[1] == 'f')
                {
                    Owned<IEspDebugValue> dval = createDebugValue();
                    dval->setName(&key[2]);
                    dval->setValue(globals->queryProp(key));
                    dvals.append(*dval.getLink());
                }
                //All other options are ignored.
            }
            else if(key[0] == '_')
            {
                Owned<IEspApplicationValue> aval = createApplicationValue();
                aval->setApplication("eclplus");
                aval->setName(&key[1]);
                aval->setValue(globals->queryProp(key));
                avals.append(*aval.getLink());
            }
            else if(key[0] == '/')
            {
                if (xmlSeen)
                    throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once");
                // The / form is expected to be used for scalars, so xmlEncode is appropriate.
                // To pass sets or datasets, use the xml= version
                xmlParams.appendf("<%s>", &key[1]);
                encodeXML(globals->queryProp(key), xmlParams);
                xmlParams.appendf("</%s>", &key[1]);
            }
            else if(stricmp(key, "stored")==0)
            {
                if (xmlSeen)
                    throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once");
                const char *xml = globals->queryProp(key);
                try
                {
                    Owned<IPropertyTree> checkValid = createPTreeFromXMLString(xml);
                }
                catch (IException *E)
                {
                    StringBuffer msg;
                    E->errorMessage(msg);
                    E->Release();
                    throw MakeStringException(0, "Invalid xml: %s", msg.str());
                }
                xmlParams.append(xml);
            }
            else if(stricmp(key, "query")==0)
            {
                if (xmlSeen || xmlParams.length())
                    throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once");
                xmlSeen = true;
                StringBuffer xml;
                if (!globals->getProp(key, xml))
                    throw MakeStringException(0, "Invalid value for query= parameter");
                if (xml.length() && xml.charAt(0)=='@')
                {
                    StringBuffer filename(xml.str()+1);
                    xml.clear().loadFile(filename);
                }
                try
                {
                    Owned<IPropertyTree> checkValid = createPTreeFromXMLString(xml);
                }
                catch (IException *E)
                {
                    StringBuffer msg;
                    E->errorMessage(msg);
                    E->Release();
                    throw MakeStringException(0, "Invalid xml: %s", msg.str());
                }
                xmlParams.append(xml);
            }
        }
    }
    if(dvals.length() > 0)
        ureq->setDebugValues(dvals);
    if(avals.length() > 0)
        ureq->setApplicationValues(avals);
    if (xmlParams.length())
    {
        if (!xmlSeen)
        {
            xmlParams.insert(0, "<Query>");
            xmlParams.append("</Query>");
        }
        ureq->setXmlParams(xmlParams);
    }

    Owned<IClientWUUpdateResponse> uresp = wuclient->WUUpdate(ureq);
    const IMultiException* uexcep = &uresp->getExceptions();
    if(uexcep != NULL && uexcep->ordinality() > 0)
    {
        StringBuffer msg;
        uexcep->errorMessage(msg);
        printf("%s\n", msg.str());
        return false;
    }

    // Execute it
    return doSubmitWorkUnit(fp, wu->getWuid(), globals->queryProp("cluster"));
}
Пример #19
0
 EclCMDShell(int argc, const char *argv[], EclCommandFactory _factory, const char *_version, bool _runExternals=false)
     : args(argc, argv), factory(_factory), version(_version), optHelp(false), runExternals(_runExternals)
 {
     splitFilename(argv[0], NULL, NULL, &name, NULL);
 }
Пример #20
0
void VisualStudioProvider::writeFileListToProject(const FileNode &dir, std::ofstream &projectFile, const int indentation,
                                                  const StringList &duplicate, const std::string &objPrefix, const std::string &filePrefix) {
	const std::string indentString = getIndent(indentation + 2);

	if (indentation)
		projectFile << getIndent(indentation + 1) << "<Filter\tName=\"" << dir.name << "\">\n";

	for (FileNode::NodeList::const_iterator i = dir.children.begin(); i != dir.children.end(); ++i) {
		const FileNode *node = *i;

		if (!node->children.empty()) {
			writeFileListToProject(*node, projectFile, indentation + 1, duplicate, objPrefix + node->name + '_', filePrefix + node->name + '/');
		} else {
			if (producesObjectFile(node->name)) {
				std::string name, ext;
				splitFilename(node->name, name, ext);
				name += ".o";
				std::transform(name.begin(), name.end(), name.begin(), tolower);
				const bool isDuplicate = (std::find(duplicate.begin(), duplicate.end(), name) != duplicate.end());

				if (ext == "asm") {
					std::string objFileName = "$(IntDir)\\";
					if (isDuplicate)
						objFileName += objPrefix;
					objFileName += "$(InputName).obj";

					const std::string toolLine = indentString + "\t\t<Tool Name=\"VCCustomBuildTool\" CommandLine=\"nasm.exe -f win32 -g -o &quot;" + objFileName + "&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;\" Outputs=\"" + objFileName + "\" />\n";

					// NASM is not supported for x64, thus we do not need to add additional entries here :-).
					projectFile << indentString << "<File RelativePath=\"" << convertPathToWin(filePrefix + node->name) << "\">\n"
					            << indentString << "\t<FileConfiguration Name=\"Debug|Win32\">\n"
					            << toolLine
					            << indentString << "\t</FileConfiguration>\n"
					            << indentString << "\t<FileConfiguration Name=\"Analysis|Win32\">\n"
					            << toolLine
					            << indentString << "\t</FileConfiguration>\n"
					            << indentString << "\t<FileConfiguration Name=\"Release|Win32\">\n"
					            << toolLine
					            << indentString << "\t</FileConfiguration>\n"
					            << indentString << "</File>\n";
				} else {
					if (isDuplicate) {
						const std::string toolLine = indentString + "\t\t<Tool Name=\"VCCLCompilerTool\" ObjectFile=\"$(IntDir)\\" + objPrefix + "$(InputName).obj\" XMLDocumentationFileName=\"$(IntDir)\\" + objPrefix + "$(InputName).xdc\" />\n";

						projectFile << indentString << "<File RelativePath=\"" << convertPathToWin(filePrefix + node->name) << "\">\n"
						            << indentString << "\t<FileConfiguration Name=\"Debug|Win32\">\n"
						            << toolLine
						            << indentString << "\t</FileConfiguration>\n"
						            << indentString << "\t<FileConfiguration Name=\"Analysis|Win32\">\n"
						            << toolLine
						            << indentString << "\t</FileConfiguration>\n"
						            << indentString << "\t<FileConfiguration Name=\"Release|Win32\">\n"
						            << toolLine
						            << indentString << "\t</FileConfiguration>\n"
						            << indentString << "\t<FileConfiguration Name=\"Debug|x64\">\n"
						            << toolLine
						            << indentString << "\t</FileConfiguration>\n"
						            << indentString << "\t<FileConfiguration Name=\"Analysis|x64\">\n"
						            << toolLine
						            << indentString << "\t</FileConfiguration>\n"
						            << indentString << "\t<FileConfiguration Name=\"Release|x64\">\n"
						            << toolLine
						            << indentString << "\t</FileConfiguration>\n"
						            << indentString << "</File>\n";
					} else {
						projectFile << indentString << "<File RelativePath=\"" << convertPathToWin(filePrefix + node->name) << "\" />\n";
					}
				}
			} else {
				projectFile << indentString << "<File RelativePath=\"" << convertPathToWin(filePrefix + node->name) << "\" />\n";
			}
		}
	}

	if (indentation)
		projectFile << getIndent(indentation + 1) << "</Filter>\n";
}
Пример #21
0
std::vector<ImportDescriptor*> FitsImporter::getImportDescriptors(const std::string& fname)
{
   std::string filename = fname;
   std::vector<std::vector<std::string> >& errors = mErrors[fname];
   std::vector<std::vector<std::string> >& warnings = mWarnings[fname];
   errors.clear();
   warnings.clear();
   int status=0;
   std::vector<ImportDescriptor*> descriptors;

   FitsFileResource pFile(filename);
   if (!pFile.isValid())
   {
      errors.resize(1);
      errors[0].push_back(pFile.getStatus());
      RETURN_DESCRIPTORS;
   }

   int hduCnt = 0;
   int specificHdu = 0;
   int hdu = 1;
   if (!splitFilename(filename, hduCnt, specificHdu, hdu, pFile, errors, warnings))
   {
      RETURN_DESCRIPTORS;
   }
   errors.resize(hduCnt+1);
   warnings.resize(hduCnt+1);

   for(; hdu <= hduCnt; ++hdu)
   {
      std::string datasetName = filename + "[" + StringUtilities::toDisplayString(hdu) + "]";
      int hduType;
      CHECK_FITS(fits_movabs_hdu(pFile, hdu, &hduType, &status), hdu, false, continue);
      ImportDescriptorResource pImportDescriptor(static_cast<ImportDescriptor*>(NULL));
      FactoryResource<DynamicObject> pMetadata;
      VERIFYRV(pMetadata.get() != NULL, descriptors);
      { // scope
         std::vector<std::string> comments;
         char pCard[81];
         char pValue[81];
         char pComment[81];
         int nkeys = 0;
         CHECK_FITS(fits_get_hdrspace(pFile, &nkeys, NULL, &status), hdu, true, ;);
         for(int keyidx = 1; keyidx <= nkeys; ++keyidx)
         {
            CHECK_FITS(fits_read_keyn(pFile, keyidx, pCard, pValue, pComment, &status), hdu, true, continue);
            std::string name = StringUtilities::stripWhitespace(std::string(pCard));
            std::string val = StringUtilities::stripWhitespace(std::string(pValue));
            std::string comment = StringUtilities::stripWhitespace(std::string(pComment));
            if (!val.empty())
            {
               pMetadata->setAttributeByPath("FITS/" + name, val);
            }
            else if (!comment.empty())
            {
               comments.push_back(comment);
            }
         }
         if (!comments.empty())
         {
            // ideally, this would add a multi-line string but Opticks doesn't display this properly
            // pMetadata->setAttributeByPath("FITS/COMMENT", StringUtilities::join(comments, "\n"));
            for(unsigned int idx = 0; idx < comments.size(); ++idx)
            {
               pMetadata->setAttributeByPath("FITS/COMMENT/" + StringUtilities::toDisplayString(idx), comments[idx]);
            }
         }
      }
      switch(hduType)
      {
      case IMAGE_HDU:
      {
         pImportDescriptor = ImportDescriptorResource(datasetName, TypeConverter::toString<RasterElement>());
         VERIFYRV(pImportDescriptor.get() != NULL, descriptors);

         EncodingType fileEncoding;
         InterleaveFormatType interleave(BSQ);
         unsigned int rows=0;
         unsigned int cols=0;
         unsigned int bands=1;

         int bitpix;
         int naxis;
         long axes[3];
         CHECK_FITS(fits_get_img_param(pFile, 3, &bitpix, &naxis, axes, &status), hdu, false, continue);
         switch(bitpix)
         {
         case BYTE_IMG:
            fileEncoding = INT1UBYTE;
            break;
         case SHORT_IMG:
            fileEncoding = INT2SBYTES;
            break;
         case LONG_IMG:
            fileEncoding = INT4SBYTES;
            break;
         case FLOAT_IMG:
            fileEncoding = FLT4BYTES;
            break;
         case DOUBLE_IMG:
            fileEncoding = FLT8BYTES;
            break;
         default:
            warnings[hdu].push_back("Unsupported BITPIX value " + StringUtilities::toDisplayString(bitpix) + ".");
            continue;
         }
         EncodingType dataEncoding = checkForOverflow(fileEncoding, pMetadata.get(), hdu, errors, warnings);
         if (naxis == 1)
         {
            // 1-D data is a signature
            pImportDescriptor = ImportDescriptorResource(datasetName, TypeConverter::toString<Signature>());
            pMetadata->setAttributeByPath(METADATA_SIG_ENCODING, dataEncoding);
            pMetadata->setAttributeByPath(METADATA_SIG_LENGTH, axes[0]);

            RasterUtilities::generateAndSetFileDescriptor(pImportDescriptor->getDataDescriptor(), filename,
               StringUtilities::toDisplayString(hdu), BIG_ENDIAN_ORDER);

            // add units
            SignatureDataDescriptor* pSigDd =
               dynamic_cast<SignatureDataDescriptor*>(pImportDescriptor->getDataDescriptor());
            if (pSigDd != NULL)
            {
               FactoryResource<Units> pUnits;
               pUnits->setUnitName("Custom");
               pUnits->setUnitType(CUSTOM_UNIT);
               pSigDd->setUnits("Reflectance", pUnits.get());
            }

            break; // leave switch()
         }
         else if (naxis == 2)
         {
            cols = axes[0];
            rows = axes[1];
         }
         else if (naxis == 3)
         {
            cols = axes[0];
            rows = axes[1];
            bands = axes[2];
         }
         else
         {
            errors[hdu].push_back(StringUtilities::toDisplayString(naxis) + " axis data not supported.");
         }

         RasterDataDescriptor* pDataDesc = RasterUtilities::generateRasterDataDescriptor(
            datasetName, NULL, rows, cols, bands, interleave, dataEncoding, IN_MEMORY);
         pImportDescriptor->setDataDescriptor(pDataDesc);
         if (specificHdu == 0 && hdu == 1 && naxis == 2 && (axes[0] <= 5 || axes[1] <= 5))
         {
            // use 5 as this is a good top end for the number of astronomical band pass filters
            // in general usage. this is not in a spec anywhere and is derived from various sample
            // FITS files for different astronomical instruments.
            //
            // There's a good chance this is really a spectrum. (0th HDU)
            // We'll create an import descriptor for the spectrum version of this
            // And disable the raster descriptor by default
            pImportDescriptor->setImported(false);
            ImportDescriptorResource pSigDesc(datasetName, TypeConverter::toString<SignatureLibrary>());
            DynamicObject* pSigMetadata = pSigDesc->getDataDescriptor()->getMetadata();
            pSigMetadata->merge(pMetadata.get());
            std::vector<double> centerWavelengths;
            unsigned int cnt = (axes[0] <= 5) ? axes[1] : axes[0];
            double startVal = StringUtilities::fromDisplayString<double>(
               dv_cast<std::string>(pMetadata->getAttributeByPath("FITS/MINWAVE"), "0.0"));
            double endVal = StringUtilities::fromDisplayString<double>(
               dv_cast<std::string>(pMetadata->getAttributeByPath("FITS/MAXWAVE"), "0.0"));
            double incr = (endVal == 0.0) ? 1.0 : ((endVal - startVal) / static_cast<double>(cnt));
            centerWavelengths.reserve(cnt);
            for (unsigned int idx = 0; idx < cnt; idx++)
            {
               centerWavelengths.push_back(startVal + (idx * incr));
            }
            pSigMetadata->setAttributeByPath(CENTER_WAVELENGTHS_METADATA_PATH, centerWavelengths);

            // Units
            std::string unitsName = dv_cast<std::string>(pMetadata->getAttributeByPath("FITS/BUNIT"), std::string());
            if (!unitsName.empty())
            {
               FactoryResource<Units> units;
               units->setUnitName(unitsName);
               units->setUnitType(RADIANCE);
               SignatureDataDescriptor* pSigDd =
                  dynamic_cast<SignatureDataDescriptor*>(pSigDesc->getDataDescriptor());
               if (pSigDd != NULL)
               {
                  pSigDd->setUnits("Reflectance", units.get());
               }
            }

            RasterUtilities::generateAndSetFileDescriptor(pSigDesc->getDataDescriptor(),
               filename, StringUtilities::toDisplayString(hdu), BIG_ENDIAN_ORDER);

            // If units are not available, set custom units into the data descriptor so that the user can
            // modify them - this must occur after the call to RasterUtilities::generateAndSetFileDescriptor()
            // so that the file descriptor will still display no defined units
            if (unitsName.empty())
            {
               FactoryResource<Units> units;
               units->setUnitName("Custom");
               units->setUnitType(CUSTOM_UNIT);
               SignatureDataDescriptor* pSigDd = dynamic_cast<SignatureDataDescriptor*>(pSigDesc->getDataDescriptor());
               if (pSigDd != NULL)
               {
                  pSigDd->setUnits("Reflectance", units.get());
               }
            }

            descriptors.push_back(pSigDesc.release());
         }

         RasterFileDescriptor* pFileDescriptor = dynamic_cast<RasterFileDescriptor*>(
            RasterUtilities::generateAndSetFileDescriptor(pDataDesc, filename,
            StringUtilities::toDisplayString(hdu), BIG_ENDIAN_ORDER));
         if (pFileDescriptor != NULL)
         {
            unsigned int bitsPerElement = RasterUtilities::bytesInEncoding(fileEncoding) * 8;
            pFileDescriptor->setBitsPerElement(bitsPerElement);
         }

         break; // leave switch()
      }
      case ASCII_TBL:
      case BINARY_TBL:
         warnings[hdu].push_back("Tables not supported. [HDU " + StringUtilities::toDisplayString(hdu) + "]");
         continue;
      default:
         warnings[hdu].push_back("HDU " + StringUtilities::toDisplayString(hdu) + " is an unknown type.");
         continue;
      }

      pImportDescriptor->getDataDescriptor()->setMetadata(pMetadata.release());
      pImportDescriptor->setImported(errors[hdu].empty());
      descriptors.push_back(pImportDescriptor.release());
   }