コード例 #1
0
ファイル: checkHelpers.hpp プロジェクト: jkells/nscp
		void runCheck(typename TContents::TValueType &value, NSCAPI::nagiosReturn &returnCode, std::wstring &message, std::wstring &perf) {
			std::wstring tstr;
			if (crit.check(value, getAlias(), tstr, critical)) {
				//std::wcout << _T("crit") << std::endl;
				nscapi::plugin_helper::escalteReturnCodeToCRIT(returnCode);
			} else if (warn.check(value, getAlias(), tstr, warning)) {
				//std::wcout << _T("warn") << std::endl;
				nscapi::plugin_helper::escalteReturnCodeToWARN(returnCode);
			}else if (show == showLong) {
				//std::wcout << _T("long") << std::endl;
				tstr = getAlias() + _T(": ") + TContents::toStringLong(value);
			}else if (show == showShort) {
				//std::wcout << _T("short") << std::endl;
				tstr = getAlias() + _T(": ") + TContents::toStringShort(value);
			}
			if (perfData) {
				if (!perf.empty())
					perf += _T(" ");
				perf += gatherPerfData(value);
			}
			if (!message.empty() && !tstr.empty())
				message += _T(", ");
			if (!tstr.empty())
				message += tstr;
			//std::wcout << _T("result: ") << tstr << _T("--") << std::endl;
		}
コード例 #2
0
ファイル: checkHelpers.hpp プロジェクト: jkells/nscp
		std::wstring gatherPerfData(typename TContents::TValueType &value) {
			if (crit.hasBounds())
				return crit.gatherPerfData(getAlias(), value, warn, crit);
			else if (warn.hasBounds())
				return warn.gatherPerfData(getAlias(), value, warn, crit);
			else {
				TContents tmp;
				return tmp.gatherPerfData(getAlias(), value);
			}
		}
コード例 #3
0
ファイル: modules.c プロジェクト: m23project/mdk-devel
int main() {
	struct confModules *foo;
	int x;
	
	foo=newConfModules();
	addAlias(foo,"eth0","eepro100",CM_REPLACE);
	addAlias(foo,"eth0","tulip",CM_COMMENT);
	addOptions(foo,"eth0","debug=foo",0);
	addLine(foo,"alias parport_lowlevel parport_pc",CM_COMMENT);
	writeConfModules(foo,"foomod");
	printf("=%s=\n",getAlias(foo,"eth0"));
	printf("=%s=\n",getAlias(foo,"scuzzy_hostadapter"));
	freeConfModules(foo);
}
コード例 #4
0
 void freeze()
 {
     IndexType victimIndex = m_freezeWorklist.takeAny();
     ASSERT_WITH_MESSAGE(getAlias(victimIndex) == victimIndex, "coalesce() should not leave aliased Tmp in the worklist.");
     m_simplifyWorklist.append(victimIndex);
     freezeMoves(victimIndex);
 }
コード例 #5
0
ファイル: itemdef.cpp プロジェクト: EXio4/minetest
	virtual bool isKnown(const std::string &name_) const
	{
		// Convert name according to possible alias
		std::string name = getAlias(name_);
		// Get the definition
		std::map<std::string, ItemDefinition*>::const_iterator i;
		return m_item_definitions.find(name) != m_item_definitions.end();
	}
コード例 #6
0
ファイル: scp.c プロジェクト: chenx/Latex2gDPS
void SCP_writeDpfeBase(FILE * fp, DPFE * d) {
  // if d->module_type != NULL or d->base != NULL.
  MACRO_writeDpfeBase(fp, d);
  // else, default base.
  // don't know how to specify n, is it the size of dimension array?
  PARAMS_STRUCT * p = d->params_struct;
  if (NULL == p) { return; }
  fprintf(fp, "  %s(g, x) = 0 if x = %d\n", 
          getAlias(d->gf->f_name), p->size - 1);
}
コード例 #7
0
    void assignColors()
    {
        ASSERT(m_simplifyWorklist.isEmpty());
        ASSERT(m_worklistMoves.isEmpty());
        ASSERT(m_freezeWorklist.isEmpty());
        ASSERT(m_spillWorklist.isEmpty());

        // Reclaim as much memory as possible.
        m_interferenceEdges.clear();
        m_degrees.clear();
        m_moveList.clear();
        m_worklistMoves.clear();
        m_simplifyWorklist.clear();
        m_spillWorklist.clear();
        m_freezeWorklist.clear();

        // Try to color the Tmp on the stack.
        m_coloredTmp.resize(m_adjacencyList.size());

        while (!m_selectStack.isEmpty()) {
            unsigned tmpIndex = m_selectStack.takeLast();
            ASSERT(!isPrecolored(tmpIndex));
            ASSERT(!m_coloredTmp[tmpIndex]);

            RegisterSet coloredRegisters;
            for (IndexType adjacentTmpIndex : m_adjacencyList[tmpIndex]) {
                IndexType aliasTmpIndex = getAlias(adjacentTmpIndex);
                Reg reg = m_coloredTmp[aliasTmpIndex];

                ASSERT(!isPrecolored(aliasTmpIndex) || (isPrecolored(aliasTmpIndex) && reg));

                if (reg)
                    coloredRegisters.set(reg);
            }

            bool colorAssigned = false;
            for (Reg reg : m_regsInPriorityOrder) {
                if (!coloredRegisters.get(reg)) {
                    m_coloredTmp[tmpIndex] = reg;
                    colorAssigned = true;
                    break;
                }
            }

            if (!colorAssigned)
                m_spilledTmps.append(tmpIndex);
        }
        m_selectStack.clear();

        if (m_spilledTmps.isEmpty())
            m_coalescedTmpsAtSpill.clear();
        else
            m_coloredTmp.clear();
    }
コード例 #8
0
ファイル: modules.c プロジェクト: m23project/mdk-devel
int isAliased(struct confModules *cf, char *alias, char *module)
{
	char tmp[128];
	char *modalias;
	int x=0,retval=-1;
	
	if ( (modalias=getAlias(cf,alias)) && (!strcmp(module,modalias)))
	  retval = 0;
	else
	  while (1) {
		snprintf(tmp,128,"%s%d",alias,x);
		if ( (modalias=getAlias(cf,tmp)) && (!strcmp(module,modalias))) {
			retval=x;
			break;
		}
		if (!modalias && x!=0) break;
		x++;
	  }
	return retval;
}
コード例 #9
0
void GraphObject::registerAttributes()
{
    addAttribute("alias",
        [&](const Values& args) {
            auto alias = args[0].as<string>();
            setAlias(alias);
            return true;
        },
        [&]() -> Values { return {getAlias()}; },
        {'s'});
    setAttributeDescription("alias", "Alias name");

    addAttribute("setSavable",
        [&](const Values& args) {
            auto savable = args[0].as<bool>();
            setSavable(savable);
            return true;
        },
        {'n'});

    addAttribute("priorityShift",
        [&](const Values& args) {
            _priorityShift = args[0].as<int>();
            return true;
        },
        [&]() -> Values { return {_priorityShift}; },
        {'n'});
    setAttributeDescription("priorityShift",
        "Shift to the default rendering priority value, for those cases where two objects should be rendered in a specific order. Higher value means lower priority");

    addAttribute("switchLock",
        [&](const Values& args) {
            auto attribIterator = _attribFunctions.find(args[0].as<string>());
            if (attribIterator == _attribFunctions.end())
                return false;

            string status;
            auto& attribFunctor = attribIterator->second;
            if (attribFunctor.isLocked())
            {
                status = "Unlocked";
                attribFunctor.unlock();
            }
            else
            {
                status = "Locked";
                attribFunctor.lock();
            }

            Log::get() << Log::MESSAGE << _name << "~~" << args[0].as<string>() << " - " << status << Log::endl;
            return true;
        },
        {'s'});
}
コード例 #10
0
ファイル: itemdef.cpp プロジェクト: EXio4/minetest
	virtual const ItemDefinition& get(const std::string &name_) const
	{
		// Convert name according to possible alias
		std::string name = getAlias(name_);
		// Get the definition
		std::map<std::string, ItemDefinition*>::const_iterator i;
		i = m_item_definitions.find(name);
		if(i == m_item_definitions.end())
			i = m_item_definitions.find("unknown");
		assert(i != m_item_definitions.end());
		return *(i->second);
	}
コード例 #11
0
    void coalesce()
    {
        unsigned moveIndex = m_worklistMoves.takeLastMove();
        const MoveOperands& moveOperands = m_coalescingCandidates[moveIndex];
        IndexType u = getAlias(moveOperands.srcIndex);
        IndexType v = getAlias(moveOperands.dstIndex);

        if (isPrecolored(v))
            std::swap(u, v);

        if (traceDebug)
            dataLog("Coalescing move at index", moveIndex, " u = ", u, " v = ", v, "\n");

        if (u == v) {
            addWorkList(u);

            if (traceDebug)
                dataLog("    Coalesced\n");
        } else if (isPrecolored(v) || m_interferenceEdges.contains(InterferenceEdge(u, v))) {
            addWorkList(u);
            addWorkList(v);

            if (traceDebug)
                dataLog("    Constrained\n");
        } else if (canBeSafelyCoalesced(u, v)) {
            combine(u, v);
            addWorkList(u);
            m_hasCoalescedNonTrivialMove = true;

            if (traceDebug)
                dataLog("    Safe Coalescing\n");
        } else {
            m_activeMoves.quickSet(moveIndex);

            if (traceDebug)
                dataLog("    Failed coalescing, added to active moves.\n");
        }
    }
コード例 #12
0
ファイル: buddy.cpp プロジェクト: meyerd/libtransport
Swift::Presence::ref Buddy::generatePresenceStanza(int features, bool only_new) {
	std::string alias = getAlias();
	std::string name = getSafeName();

	Swift::StatusShow s;
	std::string statusMessage;
	if (!getStatus(s, statusMessage))
		return Swift::Presence::ref();

	if (m_jid.getNode().empty()) {
		generateJID();
	}

	Swift::Presence::ref presence = Swift::Presence::create();
 	presence->setFrom(m_jid);
	presence->setTo(m_rosterManager->getUser()->getJID().toBare());
	presence->setType(Swift::Presence::Available);

	if (!statusMessage.empty())
		presence->setStatus(statusMessage);

	if (s.getType() == Swift::StatusShow::None)
		presence->setType(Swift::Presence::Unavailable);
	presence->setShow(s.getType());

	if (presence->getType() != Swift::Presence::Unavailable) {
		// caps
		
		presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::CapsInfo(m_rosterManager->getUser()->getComponent()->getBuddyCapsInfo())));

// 		if (features & 0/*TRANSPORT_FEATURE_AVATARS*/) {
			presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::VCardUpdate (getIconHash())));
// 		}
		if (isBlocked()) {
			presence->addPayload(boost::shared_ptr<Swift::Payload>(new Transport::BlockPayload ()));
		}
	}

// 	if (only_new) {
// 		if (m_lastPresence)
// 			m_lastPresence->setTo(Swift::JID(""));
// 		if (m_lastPresence == presence) {
// 			return Swift::Presence::ref();
// 		}
// 		m_lastPresence = presence;
// 	}

	return presence;
}
コード例 #13
0
ファイル: spc.c プロジェクト: chenx/Latex2gDPS
void SPC_writeGeneralFunctions(FILE * fp, DPFE * d) {
  PARAMS_STRUCT * p = d->params_struct;
  if (NULL == p) { return; }
  fprintf(fp, "GENERAL_FUNCTIONS_BEGIN\n");
  fprintf(fp, "  private static NodeSet possibleNextNodes(int node) { \n");
  fprintf(fp, "    NodeSet result = new NodeSet(); \n");
  fprintf(fp, "    for (int i=0; i<distance[node].length; i++) { \n");
  fprintf(fp, "      if (%s[node][i]!=infty) {i \n", getAlias(p->name));
  fprintf(fp, "        result.add(new Integer(i)); \n");
  fprintf(fp, "      } \n");
  fprintf(fp, "    } \n");
  fprintf(fp, "    return result; \n");
  fprintf(fp, "  } \n");
  fprintf(fp, "GENERAL_FUNCTIONS_END\n\n");
}
コード例 #14
0
    void freezeMoves(IndexType tmpIndex)
    {
        forEachNodeMoves(tmpIndex, [this, tmpIndex] (IndexType moveIndex) {
            if (!m_activeMoves.quickClear(moveIndex))
                m_worklistMoves.takeMove(moveIndex);

            const MoveOperands& moveOperands = m_coalescingCandidates[moveIndex];
            IndexType srcTmpIndex = moveOperands.srcIndex;
            IndexType dstTmpIndex = moveOperands.dstIndex;

            IndexType originalOtherTmp = srcTmpIndex != tmpIndex ? srcTmpIndex : dstTmpIndex;
            IndexType otherTmpIndex = getAlias(originalOtherTmp);
            if (m_degrees[otherTmpIndex] < m_regsInPriorityOrder.size() && !isMoveRelated(otherTmpIndex)) {
                if (m_freezeWorklist.remove(otherTmpIndex))
                    m_simplifyWorklist.append(otherTmpIndex);
            }
        });
    }
コード例 #15
0
ファイル: mainwindow.cpp プロジェクト: jeffrimko/QuickWin
void MainWindow::onTextEnter()
{
    bool stay = false;
    cmds_t cmds;
    QString text = ui->cmdText->text();
    format_cmds(cmds, text.toStdString());

    if(cmds.find("help") != cmds.end()) {
        QString help = "Commands: ";
        for(std::string cmd : list_cmd_types()) {
            help += QString::fromStdString(cmd);
            help += " ";
        }
        ui->noteText->append(help);
        stay = true;
    }
    if(cmds.find("delete") != cmds.end()) {
        delAlias();
        stay = true;
    }
    if("" != cmds["set"]) {
        uint num = getSelWinNum();
        setAlias(QString::fromStdString(cmds["set"]), num);
        stay = true;
    }
    if(cmds.find("aliases") != cmds.end()) {
        listAlias();
        stay = true;
    }

    if(!stay) {
        if("" != cmds["get"]) {
            getAlias(QString::fromStdString(cmds["get"]));
        } else {
            onWitemActivate(ui->winView->currentIndex());
        }
    }
    ui->cmdText->clear();
}
コード例 #16
0
ファイル: door.cpp プロジェクト: evanelias/tournament-trivia
void main(int argc, char *argv[])
#endif
{
   char szText[160];
   bool bSuccess;
   short nTries = 0;

   // Set results of what happens when a call to new fails
   set_new_handler(badNew);

   // Call the startup function
   #ifdef OD32
   startup(lpszCmdLine);
   #else
   startup(argc, argv);
   #endif

   Sleep(500);

   do
      {
      // Attempt to start up the door server process.  (No need to check if the door server process is already
      // running; it does that on its own and shuts down extra copies as needed)
      bSuccess = CreateProcess(DOOR_SERVER_EXE, NULL, NULL, NULL, false, DETACHED_PROCESS, NULL, NULL, new STARTUPINFO, new PROCESS_INFORMATION);
      Sleep(1000);
      nTries++;
      }  
   while ( bSuccess == false && nTries < 5 );

   // Get a handle on the door server's input mailslot
   hInputSlot = openSlot(-1);

   // Create this node's output mailslot.
   hOutputSlot = createSlot( getNode() );
 
   // If unable to open input slot, re-try up to 5 times (intial failure seems to happen on WinXP randomly)
   // If still failure, this indicates the door server is not running and could not be started, so shut down.
   nTries = 0;
   while (hInputSlot == INVALID_HANDLE_VALUE ) 
      {
      Sleep(500);
      hInputSlot = openSlot(-1);      
      if ( ++nTries > 5 )
         {
         local("Unable to start door: IPC error");
         exitDoor(1);
         }
      }

   // If the output slot for this node is already open, it means the node is already running the door.
   if ( hOutputSlot == INVALID_HANDLE_VALUE )
      {
      local("Unable to start door:  This node is already in use!");
      pausePrompt();
      exitDoor(1);
      }

   // Now that the mailslot handles were successful, call setupExitFunction() to register beforeExit() as the
   // function called upon exit.
   setupExitFunction();
      
   // Send an input message to the server, to tell it a user is trying to enter the game.  The user's info is
   // passed as a string in the format below.
   sprintf(szText, "%d&%c&%d&%s&%s", isSysop(), getGender(), getPlatform(), getAlias(), getRealName());
   sendInput(szText, IP_ENTER_GAME);

   // Handle I/O for the user
   while (1)
      {
      performIO();
      }   
}
コード例 #17
0
ファイル: PrngTest.cpp プロジェクト: kphannan/OpenLCB
 void dump() {
     printf(" %X %X -> %X \n", lfsr1, lfsr2, getAlias());
 }
コード例 #18
0
ファイル: main.c プロジェクト: rajdye/modelica-projects
///////////////////////////////////////////////////////////////////////////////
/// Simulate the given FMU using the forward euler method.
/// Time events are processed by reducing step size to exactly hit tNext.
/// State events are checked and fired only at the end of an Euler step. 
/// The simulator may therefore miss state events and fires state events typically too late.
///
///\param fmu FMU.
///\param tEnd Ending time of simulation.
///\param h Tiem step size.
///\param loggingOn Controller for logging.
///\param separator Separator character.
///\return 0 if there is no error occurred.
///////////////////////////////////////////////////////////////////////////////
static int simulate(FMU* fmu, double tEnd, double h, fmiBoolean loggingOn, char separator) {
		
  int i, n;
  fmiBoolean timeEvent, stateEvent, stepEvent;
  double time;  
  ModelDescription* md;            // handle to the parsed XML file        
  const char* guid;                // global unique id of the fmu
  fmiCallbackFunctions callbacks;  // called by the model during simulation
  fmiComponent c;                  // instance of the fmu 
  fmiStatus fmiFlag;               // return code of the fmu functions
  fmiReal t0 = 0;                  // start time
	fmiBoolean toleranceControlled = fmiFalse;
  int nSteps = 0;
  FILE* file;

	fmiValueReference vr;			// add it to get value reference for variables

  //Note: User defined references
  //Begin------------------------------------------------------------------
  fmiValueReference vru[1], vry[1]; // value references for two input and two output variables 
  //End--------------------------------------------------------------------

	ScalarVariable** vars = fmu->modelDescription->modelVariables;		// add it to get variables
	int k;							// add a counter for variables
	fmiReal ru1, ru2, ry, ry1, ry2;	// add real variables for input and output
	fmiInteger ix, iy;				// add integer variables for input and output
	fmiBoolean bx, by;				// add boolean variables for input and output
	fmiString sx, sy;				// Zuo: add string variables for input and output
	fmiStatus status;				// Zuo: add stauus for fmi

	printDebug("Instantiate the fmu.\n");		
  // instantiate the fmu
  md = fmu->modelDescription;
  guid = getString(md, att_guid);
	printfDebug("Got GUID = %s!\n", guid);	
  callbacks.logger = fmuLogger;
  callbacks.allocateMemory = calloc;
  callbacks.freeMemory = free;
	printDebug("Got callbacks!\n");
	printfDebug("Model Identifer is %s\n", getModelIdentifier(md));
 	c = fmu->instantiateSlave(getModelIdentifier(md), guid, "Model1", "", 10, fmiFalse, fmiFalse, callbacks, loggingOn);
  if (!c) {
    printError("could not instantiate slaves.\n");
    return 1;
  }
  printDebug("Instantiated slaves!\n");	

  // Open result file
  if (!(file=fopen(RESULT_FILE, "w"))) {
    printfError("could not write %s because:\n", RESULT_FILE);
    printfError("    %s\n", strerror(errno));
    return 1;
  }
  printDebug("Open results file!\n");    

  // Set the start time and initialize
  time = t0;

	printDebug("start to initialize fmu!\n");	   
	fmiFlag =  fmu->initializeSlave(c, t0, fmiTrue, tEnd);	
	printDebug("Initialized fmu!\n");
  if (fmiFlag > fmiWarning) {
    printError("could not initialize model");
    return 1;
  }
 
  // Output solution for time t0 
  printDebug("start to outputRow");
  //outputRow(fmu, c, t0, file, separator, TRUE);  // output column names
  //outputRow(fmu, c, t0, file, separator, FALSE); // output initla value of fmu 
  outputdata(t0, file, separator, 0, 0, TRUE);
  
  printDebug("start to getValueReference");
  ///////////////////////////////////////////////////////////////////////////// 
  // Get value references for input and output varibles
  // Note: User needs to specify the name of variables for their own fmus
  //Begin------------------------------------------------------------------
  vru[0] = getValueReference(getVariableByName(md, "Toa"));
  //vru[1] = getValueReference(getVariableByName(md, "u2"));
  vry[0] = getValueReference(getVariableByName(md, "TrmSou"));
  //vry[1] = getValueReference(getVariableByName(md, "y2"));
  //End--------------------------------------------------------------------
  
  printDebug("Enter in simulation loop.\n");	

  // enter the simulation loop
  while (time < tEnd) {
    if (loggingOn) printf("Step %d to t=%.4f\n", nSteps, time);		  

    ///////////////////////////////////////////////////////////////////////////
    // Step 1: get values of output variables	from slaves
    for (k=0; vars[k]; k++) {
	    ScalarVariable* sv = vars[k];
	    if (getAlias(sv)!=enu_noAlias) continue;	
	    if (getCausality(sv) != enu_output) continue; // only get output variable
      vr = getValueReference(sv);

      switch (sv->typeSpec->type){
        case elm_Real:
          fmu->getReal(c, &vr, 1, &ry); 
          break;
        case elm_Integer:
          fmu->getInteger(c, &vr, 1, &iy);  
          break;
        case elm_Boolean:
          fmu->getBoolean(c, &vr, 1, &by);
          break;
        case elm_String:
          fmu->getString(c, &vr, 1, &sy);
          break;
      }


      // Allocate values to cooresponding varibles on master program
      // Note: User needs to specify the output variables for their own fmu 
      //Begin------------------------------------------------------------------
      if (vr == vry[0]) ry1 = ry;
      //else if(vr == vry[1]) ry2 = ry;
      //End--------------------------------------------------------------------
    } 
    
    ///////////////////////////////////////////////////////////////////////////
    // Step 2: compute on master side 
    // Note: User can adjust the computing schemes of mater program
    //Begin------------------------------------------------------------------
     printf("Dymola output = %f\n", ry1);
	 //= ry2 + 3.0; 
    ru1 = 293;
    //End--------------------------------------------------------------------

    //////////////////////////////////////////////////////////////////////////
    // Step 3: set input variables back to slaves
    for (k=0; vars[k]; k++) {
      ScalarVariable* sv = vars[k];
      if (getAlias(sv)!=enu_noAlias) continue;
	    if (getCausality(sv) != enu_input) continue; // only set input variable
        vr = getValueReference(sv);
        // Note: User can adjust the settings for input variables
        //Begin------------------------------------------------------------------
        switch (sv->typeSpec->type){
          case elm_Real:

            if(vr == vru[0]) {
              fmu->setReal(c, &vr, 1, &ru1); 				
              printDebug("Set u1.\n");
            }
            //else if (vr == vru[1]) {
            //  fmu->setReal(c, &vr, 1, &ru2);
            //  printDebug("Set u2.\n");
            //}
            else
              printf("Warning: no data given for input variable.\n");
            break;
          case elm_Integer:
            fmu->setInteger(c, &vr, 1, &ix);  
            break;
          case elm_Boolean:
            fmu->setBoolean(c, &vr, 1, &bx);
            break;
          case elm_String:
		    printDebug("Get string in simulatio()");
            fmu->setString(c, &vr, 1, &sx);
            break;        
        }
        //End--------------------------------------------------------------------        
    } 
    
    // Advance to next time step
    status = fmu->doStep(c, time, h, fmiTrue);  
    // Terminate this row
    // fprintf(file, "\n");  (comment out this line to get rid of the blank line between the results in the csv file.)    
   
    time = min(time+h, tEnd);
    //outputRow(fmu, c, time, file, separator, FALSE); // output values for this step
	outputdata(time, file, separator, ru1, ry1, FALSE);
    nSteps++;
   
  } // end of while  

  // Cleanup
  fclose(file);

  // Print simulation summary 
  if (loggingOn) printf("Step %d to t=%.4f\n", nSteps, time);		
  printf("Simulation from %g to %g terminated successful\n", t0, tEnd);
  printf("  steps ............ %d\n", nSteps);
  printf("  fixed step size .. %g\n", h);

  return 0; // success
}
コード例 #19
0
ファイル: main.c プロジェクト: rajdye/modelica-projects
///////////////////////////////////////////////////////////////////////////////
/// Output time and all non-alias variables in CSV format.
/// If separator is ',', columns are separated by ',' and '.' is used for floating-point numbers.
/// Otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used for 
/// floating-point numbers.
///
///\param fmu FMU.
///\param c FMI component.
///\param time Time when data is outputed.
///\param separator Separator in file.
///\param header Indicator of row head.
///////////////////////////////////////////////////////////////////////////////
static void outputRow(FMU *fmu, fmiComponent c, double time, FILE* file, char separator, boolean header, double x, double y) {
  int k;
  fmiReal r;
  fmiInteger i;
  fmiBoolean b;
  fmiString s;
  fmiValueReference vr;				
  ScalarVariable** vars = fmu->modelDescription->modelVariables;
  char buffer[32];
  
  // Print first column
  if (header) 
    fprintf(file, "time"); 
  else {
    if (separator==',') 
      fprintf(file, "%.4f", time);				
    else {
      // Separator is e.g. ';' or '\t'
      doubleToCommaString(buffer, time);
      fprintf(file, "%s", buffer);       
    }
  }
    
  // Print all other columns
  for (k=0; vars[k]; k++) {
    ScalarVariable* sv = vars[k];
    if (getAlias(sv)!=enu_noAlias) continue;
    if (header) {
      // Output names only
      fprintf(file, "%c%s", separator, getName(sv));
    }
    else {
      // Output values
      vr = getValueReference(sv);
      switch (sv->typeSpec->type){
        case elm_Real:
          fmu->getReal(c, &vr, 1, &r);
          if (separator==',') 
            fprintf(file, ",%.4f", r);				
        else {
          // Separator is e.g. ';' or '\t'
          doubleToCommaString(buffer, r);
          fprintf(file, "%c%s", separator, buffer);       
          }
          break;
        case elm_Integer:
          fmu->getInteger(c, &vr, 1, &i);
          fprintf(file, "%c%d", separator, i);
          break;
        case elm_Boolean:
          fmu->getBoolean(c, &vr, 1, &b);
          fprintf(file, "%c%d", separator, b);
          break;
        case elm_String:
		  printDebug("get string in outputrow");
          //fmu->getString(c, &vr, 1, &s);
          //fprintf(file, "%c%s", separator, s);
          break;
      }
    }
  } // for
    
  // Terminate this row
  fprintf(file, "\n"); 
}
コード例 #20
0
ファイル: condor_sinful.cpp プロジェクト: AlainRoy/htcondor
void
Sinful::regenerateV1String() {
	if(! m_valid) {
		// The empty list.
		m_v1String = "{}";
		return;
	}

	std::vector< SourceRoute > v;
	std::vector< SourceRoute > publics;

	//
	// We need to preserve the primary address to permit round-trips from
	// original serialization to v1 serialization and back again.  If we're
	// clever, we can also use the special primary-address entry to handle
	// some troublesome backwards-compability concerns: original Sinful
	// did no input validation, and an empty original Sinful is considered
	// valid.  We should also be able to maintain the invariant that all
	// addresses are protocol literals (and therefore require no lookup).
	//
	SourceRoute sr( CP_PRIMARY, m_host, getPortNum(), PUBLIC_NETWORK_NAME );
	v.push_back( sr );

	//
	// Presently,
	// each element of the list must be of one of the following forms:
	//
	// a = primary, port = port, p = IPv4, n = "internet"
	// a = primary, port = port, p = IPv6, n = "internet"
	// a = addrs[], port = port, p = IPv4, n = "internet"
	// a = addrs[], port = port, p = IPv6, n = "internet"
	//
	// a = primary, port = port, p = IPv4, n = "private"
	// a = primary, port = port, p = IPv6, n = "private"
	// a = private, port = privport, p = IPv4, n = "private"
	// a = private, port = privport, p = IPv6, n = "private"
	//
	// a = CCB[], port = ccbport, p = IPv4, n = "internet"
	// a = CCB[], port = ccbport, p = IPv6, n = "internet"
	// a = CCB[], port = ccbport, p = IPv4, n = "internet", ccbsharedport
	// a = CCB[], port = ccbport, p = IPv6, n = "internet", ccbsharedport
	//
	// Additionally, each of the above may also include sp; if any
	// address includes sp, all must include (the same) sp.
	//

	// Start by generating our list of public addresses.
	if( numParams() == 0 ) {
		condor_sockaddr sa;
		if( sa.from_ip_string( m_host ) ) {
			SourceRoute * sr = simpleRouteFromSinful( * this );
			if( sr != NULL ) {
				publics.push_back( * sr );
				delete sr;
			}
		}
	} else if( hasAddrs() ) {
		for( unsigned i = 0; i < addrs.size(); ++i ) {
			condor_sockaddr sa = addrs[i];
			SourceRoute sr( sa, PUBLIC_NETWORK_NAME );
			publics.push_back( sr );
		}
	}

	// If we have a private network, either:
	//		* add its private network address, if it exists
	//	or
	//		* add each of its public addresses.
	// In both cases, the network name for the routes being added is the
	// private network name.
	if( getPrivateNetworkName() != NULL ) {
		if( getPrivateAddr() == NULL ) {
			for( unsigned i = 0; i < publics.size(); ++i ) {
				SourceRoute sr( publics[i], getPrivateNetworkName() );
				v.push_back( sr );
			}
		} else {
			// The private address is defined to be a simple original Sinful,
			// just and ip-and-port string surrounded by brackets.  This is
			// overkill, but it's less ugly than stripping the brackets.
			Sinful s( getPrivateAddr() );
			if(! s.valid()) {
				m_valid = false;
				return;
			}

			SourceRoute * sr = simpleRouteFromSinful( s, getPrivateNetworkName() );
			if( sr == NULL ) {
				m_valid = false;
				return;
			}
			v.push_back( * sr );
			free( sr );
		}
	}

	// If we have a CCB address, add all CCB addresses.  Otherwise, add all
	// of our public addresses.
	if( getCCBContact() != NULL ) {
		unsigned brokerIndex = 0;
		StringList brokers( getCCBContact(), " " );

		brokers.rewind();
		char * contact = NULL;
		while( (contact = brokers.next()) != NULL ) {
			MyString ccbAddr, ccbID;
			MyString peer( "er, constructing v1 Sinful string" );
			bool contactOK = CCBClient::SplitCCBContact( contact, ccbAddr, ccbID, peer, NULL );
			if(! contactOK ) {
				m_valid = false;
				return;
			}

			//
			// A ccbAddr is an original Sinful without the <brackets>.  It
			// may have "PrivNet", "sock", "noUDP", and "alias" set.  What
			// we want to do is add copy ccbAddr's source routes to this
			// Sinful, adding the ccbID and setting the brokerIndex, so
			// that we know how to merge them back together when regenerating
			// this Sinful's original Sinful string.
			//
			std::string ccbSinfulString;
			formatstr( ccbSinfulString, "<%s>", ccbAddr.c_str() );
			Sinful s( ccbSinfulString.c_str() );
			if(! s.valid()) { m_valid = false; return; }
			std::vector< SourceRoute > w;
			if(! s.getSourceRoutes( w )) { m_valid = false; return; }

			for( unsigned j = 0; j < w.size(); ++j ) {
				SourceRoute sr = w[j];
				sr.setBrokerIndex( brokerIndex );
				sr.setCCBID( ccbID.c_str() );

				sr.setSharedPortID( "" );
				if( s.getSharedPortID() != NULL ) {
					sr.setCCBSharedPortID( s.getSharedPortID() );
				}

				v.push_back( sr );
			}
			++brokerIndex;
		}
	}

	// We'll never use these addresses -- the CCB address will supersede
	// them -- but we need to record them to properly recreate addrs.
	for( unsigned i = 0; i < publics.size(); ++i ) {
		v.push_back( publics[i] );
	}

	// Set the host alias, if present, on all addresses.
	if( getAlias() != NULL ) {
		std::string alias( getAlias() );
		for( unsigned i = 0; i < v.size(); ++i ) {
			v[i].setAlias( alias );
		}
	}

	// Set the shared port ID, if present, on all addresses.
	if( getSharedPortID() != NULL ) {
		std::string spid( getSharedPortID() );
		for( unsigned i = 0; i < v.size(); ++i ) {
			v[i].setSharedPortID( spid );
		}
	}

	// Set noUDP, if true, on all addresses.  (We don't have to set
	// noUDP on public non-CCB addresses, or on the private address,
	// unless WANT_UDP_COMMAND_SOCKET is false.  However, we can't
	// distinguish that case from the former two unless both CCB and
	// SP are disabled.)
	if( noUDP() ) {
		for( unsigned i = 0; i < v.size(); ++i ) {
			v[i].setNoUDP( true );
		}
	}

	//
	// Now that we've generated a list of source routes, convert it into
	// a nested ClassAd list.  The correct way to do this is to faff
	// about with ClassAds, but they make it uneccessarily hard; for now,
	// I'll just generated the appropriate string directly.
	//
	m_v1String.erase();

	m_v1String += "{";
	m_v1String += v[0].serialize();
	for( unsigned i = 1; i < v.size(); ++i ) {
		m_v1String += ", ";
		m_v1String += v[i].serialize();
	}
	m_v1String += "}";
}
コード例 #21
0
ファイル: Endpoint.cpp プロジェクト: princetoad/acdx
//##ModelId=424BB64601BE
CString Endpoint::toString() 
{
        return getAlias() + "(" + getEpid() + ")";
}
コード例 #22
0
ファイル: ks01.c プロジェクト: chenx/Latex2gDPS
void KS01_writeGoal(FILE * fp, DPFE * d) {
  PARAMS_STRUCT * p = dpfe->params_struct;
  if (NULL == p) { return; }
  fprintf(fp, "  %s(1, %d)\n", getAlias(d->gf->f_name),
          p->size - 1);
}
コード例 #23
0
ファイル: sipaccount.cpp プロジェクト: max3903/SFLphone
std::map<std::string, std::string> SIPAccount::getAccountDetails() const
{
    std::map<std::string, std::string> a;

    a[ACCOUNT_ID] = _accountID;
    // The IP profile does not allow to set an alias
    a[CONFIG_ACCOUNT_ALIAS] = (_accountID == IP2IP_PROFILE) ? IP2IP_PROFILE : getAlias();

    a[CONFIG_ACCOUNT_ENABLE] = isEnabled() ? "true" : "false";
    a[CONFIG_ACCOUNT_TYPE] = getType();
    a[HOSTNAME] = getHostname();
    a[USERNAME] = getUsername();

    a[CONFIG_RINGTONE_PATH] = getRingtonePath();
    a[CONFIG_RINGTONE_ENABLED] = getRingtoneEnabled() ? "true" : "false";
    a[CONFIG_ACCOUNT_MAILBOX] = getMailBox();

    RegistrationState state = Unregistered;
    std::string registrationStateCode;
    std::string registrationStateDescription;

    if (_accountID == IP2IP_PROFILE) {
        registrationStateCode = ""; // emtpy field
        registrationStateDescription = "Direct IP call";
    } else {
        state = getRegistrationState();
        int code = getRegistrationStateDetailed().first;
        std::stringstream out;
        out << code;
        registrationStateCode = out.str();
        registrationStateDescription = getRegistrationStateDetailed().second;
    }

    a[REGISTRATION_STATUS] = (_accountID == IP2IP_PROFILE) ? "READY": Manager::instance().mapStateNumberToString (state);
    a[REGISTRATION_STATE_CODE] = registrationStateCode;
    a[REGISTRATION_STATE_DESCRIPTION] = registrationStateDescription;

    // Add sip specific details
    a[ROUTESET] = getServiceRoute();
    a[CONFIG_ACCOUNT_RESOLVE_ONCE] = isResolveOnce() ? "true" : "false";
    a[USERAGENT] = getUseragent();

    a[CONFIG_ACCOUNT_REGISTRATION_EXPIRE] = getRegistrationExpire();
    a[LOCAL_INTERFACE] = getLocalInterface();
    a[PUBLISHED_SAMEAS_LOCAL] = getPublishedSameasLocal() ? "true" : "false";
    a[PUBLISHED_ADDRESS] = getPublishedAddress();

    std::stringstream localport;
    localport << getLocalPort();
    a[LOCAL_PORT] = localport.str();
    std::stringstream publishedport;
    publishedport << getPublishedPort();
    a[PUBLISHED_PORT] = publishedport.str();
    a[STUN_ENABLE] = isStunEnabled() ? "true" : "false";
    a[STUN_SERVER] = getStunServer();
    a[ACCOUNT_DTMF_TYPE] = (getDtmfType() == OVERRTP) ? "overrtp" : "sipinfo";

    a[SRTP_KEY_EXCHANGE] = getSrtpKeyExchange();
    a[SRTP_ENABLE] = getSrtpEnable() ? "true" : "false";
    a[SRTP_RTP_FALLBACK] = getSrtpFallback() ? "true" : "false";

    a[ZRTP_DISPLAY_SAS] = getZrtpDisplaySas() ? "true" : "false";
    a[ZRTP_DISPLAY_SAS_ONCE] = getZrtpDiaplaySasOnce() ? "true" : "false";
    a[ZRTP_HELLO_HASH] = getZrtpHelloHash() ? "true" : "false";
    a[ZRTP_NOT_SUPP_WARNING] = getZrtpNotSuppWarning() ? "true" : "false";

    // TLS listener is unique and parameters are modified through IP2IP_PROFILE
    std::stringstream tlslistenerport;
    tlslistenerport << getTlsListenerPort();
    a[TLS_LISTENER_PORT] = tlslistenerport.str();
    a[TLS_ENABLE] = getTlsEnable();
    a[TLS_CA_LIST_FILE] = getTlsCaListFile();
    a[TLS_CERTIFICATE_FILE] = getTlsCertificateFile();
    a[TLS_PRIVATE_KEY_FILE] = getTlsPrivateKeyFile();
    a[TLS_PASSWORD] = getTlsPassword();
    a[TLS_METHOD] = getTlsMethod();
    a[TLS_CIPHERS] = getTlsCiphers();
    a[TLS_SERVER_NAME] = getTlsServerName();
    a[TLS_VERIFY_SERVER] = getTlsVerifyServer() ? "true" : "false";
    a[TLS_VERIFY_CLIENT] = getTlsVerifyClient() ? "true" : "false";
    a[TLS_REQUIRE_CLIENT_CERTIFICATE] = getTlsRequireClientCertificate() ? "true" : "false";
    a[TLS_NEGOTIATION_TIMEOUT_SEC] = getTlsNegotiationTimeoutSec();
    a[TLS_NEGOTIATION_TIMEOUT_MSEC] = getTlsNegotiationTimeoutMsec();

    return a;
}
コード例 #24
0
/*
 * getCommand
 *
 * arguments:
 *   char *cmdLine: pointer to the command line string
 *
 * returns: commandT*: pointer to the commandT struct generated by
 *                     parsing the cmdLine string
 *
 * This parses the command line string, and returns a commandT struct,
 * as defined in runtime.h.  You must free the memory used by commandT
 * using the freeCommand function after you are finished.
 *
 * This function tokenizes the input, preserving quoted strings. It
 * supports escaping quotes and the escape character, '\'.
 */
commandT*
getCommand(char* cmdLine)
{
  //printf("here");
  char* restOfLine = (char*)malloc(sizeof(char)*BUFSIZE);
  //char* restCmdLine = (char*)malloc(sizeof(char)*BUFSIZE);

  commandT* cmd = malloc(sizeof(commandT) + sizeof(char*) * MAXARGS);
  cmd->argv[0] = 0;
  cmd->name = 0;
  cmd->argc = 0;
  cmd->piped = FALSE;
  cmd->next=NULL;
 
  int i, inArg = 0;
  char quote = 0;
  char escape = 0;

  // Set up the initial empty argument
  char* tmp = malloc(sizeof(char*) * BUFSIZE);
  int tmpLen = 0;
  tmp[0] = 0;

  //For aliasing:
  //aliasL* alias;
  char* keptString = 0; 
  //printf("parsing:%s\n", cmdLine);

  for (i = 0; cmdLine[i] != 0; i++)
    {
      //printf("\tindex %d, char %c\n", i, cmdLine[i]);

      // Check for whitespace
      if (cmdLine[i] == ' ')
        {
          if (inArg == 0)
            continue;
          if (quote == 0)
            {
              // End of an argument
              cmd->argv[cmd->argc] = malloc(sizeof(char) * (tmpLen + 1));
              strcpy(cmd->argv[cmd->argc], tmp);
              
	      //Get rest of command to add on to expanded command of alias
              if(cmd->argc==0){
                 if(isAlias(cmd->argv[0])){
                     alias=getAlias(cmd->argv[0]);
                     if(alias->found == FALSE){
                     keptString = splitCmd(cmdLine, i, restOfLine);
                     //printf("The rest of the string is: %s\n", keptString);
                     } 
                 }
              }
              

              inArg = 0;
              tmp[0] = 0;
              tmpLen = 0;
              cmd->argc++;
              cmd->argv[cmd->argc] = 0;
              continue;
            }
        }

      // If we get here, we're in text or a quoted string
      inArg = 1;

      // Start or end quoting.
      if (cmdLine[i] == '\'' || cmdLine[i] == '"')
        {
          if (escape != 0 && quote != 0 && cmdLine[i] == quote)
            {
              // Escaped quote. Add it to the argument.
              tmp[tmpLen++] = cmdLine[i];
              tmp[tmpLen] = 0;
              escape = 0;
              continue;
            }

          if (quote == 0)
            {
              //printf("\t\tstarting quote around %c\n", cmdLine[i]);
              quote = cmdLine[i];
              continue;
            }
          else
            {
              if (cmdLine[i] == quote)
                {
                  //printf("\t\tfound end quote %c\n", quote);
                  quote = 0;
                  continue;
                }
            }
        }

      // Handle escape character repeat
      if (cmdLine[i] == '\\' && escape == '\\')
        {
          escape = 0;
          tmp[tmpLen++] = '\\';
          tmp[tmpLen] = 0;
          continue;
        }

      // Handle single escape character followed by a non-backslash or quote character
      if (escape == '\\')
        {
          if (quote != 0)
            {
              tmp[tmpLen++] = '\\';
              tmp[tmpLen] = 0;
            }
          escape = 0;
        }

      // Set the escape flag if we have a new escape character sequence.
      if (cmdLine[i] == '\\')
        {
          escape = '\\';
          continue;
        }
      
      if(cmdLine[i] =='|'){
          cmd->piped =TRUE;
          i+=2;
          char* nextCmd = splitCmd(cmdLine, i, restOfLine);
          pipeSeq(nextCmd, cmd);
          //printf("%s\n",nextCmd);
          //cmd->piped =TRUE;
          //printf("Piped is %b\n", cmd->piped);
          break;
      }
      
      tmp[tmpLen++] = cmdLine[i];
      tmp[tmpLen] = 0;
    }

  
  // End the final argument, if any.
  if (tmpLen > 0)
    {
      //printf("\t\tend of argument %d, got:%s\n", cmd.argc, tmp);
      cmd->argv[cmd->argc] = malloc(sizeof(char) * (tmpLen + 1));
      strcpy(cmd->argv[cmd->argc], tmp);
      //cmd->next=0;
      inArg = 0;
      tmp[0] = 0;
      tmpLen = 0;
      cmd->argc++;
      cmd->argv[cmd->argc] = 0;
      //If input is an alias call expanded command
      if(isAlias(cmd->argv[0])){
         alias=getAlias(cmd->argv[0]);
         if(alias->found == FALSE){
        
	  char* concat = concatCmd(alias->origName, keptString); 
	  alias->found=TRUE;      
	  cmd = getCommand(concat);
	  alias->found=FALSE;
	  //free(concat);
         }
            
        // alias->found=FALSE;
      }
      
    }

  free(tmp);
  //TODO Maybe we Need the cmd Line?
  free(restOfLine);
  //free(restCmdLine);
  cmd->name = cmd->argv[0];

  return cmd;
} /* getCommand */