Ejemplo n.º 1
0
Archivo: main.c Proyecto: samboy/Oblige
static void ProcessResponseFile(const char *filename)
{
  int word_len = 0;
  int in_quote = 0;
 
  FILE *fp = fopen(filename, "rb");

  if (! fp)
    TextFatalError("Error: Cannot find RESPONSE file: %s\n", filename);

  // the word buffer is always kept NUL-terminated
  word_buffer[0] = 0;

  for (;;)
  {
    int ch = fgetc(fp);

    if (ch == EOF)
      break;

    if (isspace(ch) && !in_quote)
    {
      if (word_len > 0)
        AddArg(word_buffer);

      word_len = 0;
      in_quote = 0;

      continue;
    }

    if (isspace(ch) && !in_quote)
      continue;

    if ((ch == '\n' || ch == '\r') && in_quote)
      break;  // causes the unclosed-quotes error

    if (ch == '"')
    {
      in_quote = ! in_quote;
      continue;
    }

    if (word_len >= MAX_WORD_LEN)
      TextFatalError("Error: option in RESPONSE file too long (limit %d chars)\n",
          MAX_WORD_LEN);

    word_buffer[word_len++] = ch;
    word_buffer[word_len] = 0;
  }

  if (in_quote)
    TextFatalError("Error: unclosed quotes in RESPONSE file\n");

  if (word_len > 0)
    AddArg(word_buffer);

  fclose(fp);
}
Ejemplo n.º 2
0
BOOL CCmd_MaxChange::Run( )
{
	ClearArgs();
	AddArg(_T("changes"));
	AddArg(_T("-s"));
	AddArg(_T("submitted"));
	AddArg(_T("-m"));
	AddArg(_T("1"));
	
	m_MaxChange=0;
	return CP4Command::Run();
}
Ejemplo n.º 3
0
BOOL CCmd_Delete::Run(int descType, LPCTSTR reference)
{
	ClearArgs();
	switch (descType)
	{
	case P4BRANCH_DEL:
		AddArg(_T("branch"));	break;
	case P4CHANGE_DEL:
		AddArg(_T("change"));	break;
	case P4CLIENT_DEL:
		AddArg(_T("client"));	break;
	case P4JOB_DEL:
		AddArg(_T("job"));		break;
	case P4LABEL_DEL:
		AddArg(_T("label"));	break;
	case P4USER_DEL:
		AddArg(_T("user"));		break;
	default:
		ASSERT(0);
		return FALSE;
	}
	
	AddArg(_T("-d"));
//how come no -f for force?

	// remove any surrounding quotes (jobs can have multi word names)
	CString	ref = reference;
	ref.TrimLeft(_T('\"'));
	ref.TrimRight(_T('\"'));
	AddArg(ref);

	m_CompletionData=_T("");
	m_CompletionMsg =_T("");
	return CP4Command::Run();
}
Ejemplo n.º 4
0
static int StashResults(int argc, char **argv, void *callback) {
    ListBlock *list = (ListBlock *) callback;
    ArgBlock *argb;
    char *arg;
    int i;

    /* printf("DEBUG: StashResults argc = %d\n", argc);
     * for (i = 0; i < argc; i++)
     * printf("DEBUG: StashResults argv[%d] = %s\n", i, argv[i]);
     */

    while (list->alloccount <= (list->count + 1)) {
	ArgBlock **args = (ArgBlock **) malloc(list->alloccount * 2 * sizeof(char *));
	list->alloccount = list->alloccount * 2;
	for(i = 0; i < list->count; i++) {
	    args[i] = list->Args[i];
	}
	free(list->Args);
	list->Args = args;
    }

    argb = NewArgBlock();

    for (i = 0; i < argc; i++) {
	arg = (char *) malloc(strlen(argv[i]) + 1);
	strcpy(arg, argv[i]);
	AddArg(argb, arg);
    }
    list->Args[list->count++] = argb;
    return (0);
}
Ejemplo n.º 5
0
BOOL CCmd_Depots::Run( )											
{
	ClearArgs( );
	AddArg( _T("depots") );

	return CP4Command::Run( );
}
Ejemplo n.º 6
0
BOOL CCmd_Password::Run(LPCTSTR oldPwd, LPCTSTR newPwd)
{
	m_OldPwd = oldPwd;
	m_NewPwd = newPwd;
	ClearArgs();
	AddArg(_T("passwd"));
	return CP4Command::Run();
}
Ejemplo n.º 7
0
// Pre-made responses.
std::unique_ptr<Response> Response::Res(const std::string &type,
                                        const std::string &path,
                                        const std::string &value)
{
	auto res = std::unique_ptr<Response>(
		new Response(Response::Code::RES)
	);
	res->AddArg(path).AddArg(type).AddArg(value);
	return res;
}
Ejemplo n.º 8
0
static void
AddArgFmt(const char *fmt, ...)
{
    char buf[1024];
    va_list ap;
    va_start(ap, fmt);
    vsnprintf(buf, sizeof(buf), fmt, ap);
    va_end(ap);
    AddArg(strdup(buf));
}
Ejemplo n.º 9
0
Archivo: main.c Proyecto: samboy/Oblige
static void BuildArgumentList(int argc, char **argv)
{
  for (; argc > 0; argv++, argc--)
  {
    if (argv[0][0] == '@')
    {
      ProcessResponseFile(argv[0] + 1);
      continue;
    }

    AddArg(*argv);
  }

  resp_argv[resp_argc] = NULL;
}
Ejemplo n.º 10
0
BOOL CCmd_Labels::Run(CStringList *viewSpec)
{
	ClearArgs();
	m_BaseArgs= AddArg(_T("labels"));

	m_UsedTagged = GET_SERVERLEVEL() >= 8 ? TRUE : FALSE;

	m_pList= new CObList;

	if (GET_SERVERLEVEL() >= 11)
	{
		// We may or may not have a view spec to limit the fetching of 
		// labels, so sometimes we have an input list and sometimes not
		ASSERT(viewSpec==NULL || viewSpec->IsKindOf(RUNTIME_CLASS(CStringList)));
		if(viewSpec != NULL && viewSpec->GetCount())
		{
			m_pStrListIn= viewSpec;
			m_posStrListIn= m_pStrListIn->GetHeadPosition();
			NextListArgs();
		}
	}
	return CP4Command::Run();
}
int JniRecvCallback(uint32_t function_id, yeguang::ParamArgs& args, void* context)
{
	JNIEnv *env;
	bool res = GetJniEnv((void **)&env);

	const yeguang::TParamInfo *info = yeguang::ParamExecutor::Instance()->GetParamInfo(function_id);

	if(info != NULL)
	{
		jobject execobj = (jobject)context;

		jclass clazz_args = env->FindClass("com/yeguang/paramprotocol/ParamArgs");
		jmethodID mid_args = env->GetMethodID(clazz_args, "<init>", "()V");
		jobject argsobj = env->NewObject(clazz_args, mid_args);

		int cnt = args.GetArgCount();

		for (int i = 0; i < cnt; i++)
		{
			AddArg(env, argsobj, args[i]);
		}

		jmethodID mid = GetMethod(env, "com/yeguang/paramprotocol/ParamSocket",
			"Execute", "(ILcom/yeguang/paramprotocol/ParamArgs;)V");   

		dprint("env:%p execobj:%p mid:%p function_id:%X argsobj:%p", env, execobj, mid, function_id, argsobj);

		env->CallVoidMethod(execobj, mid, function_id, argsobj);
	}

	if (res)
	{
		ReleaseJniEnv();
	}
	return 0;
}
Ejemplo n.º 12
0
//----------------------------------------------------------------------------
//
// Name       : DoInstruction
//
// Description: Executes slic intructions that were previously
//              "compiled" by slicif_add_op.
//
// Parameters : SOP op
//
// Globals    : This function is so big no idea.
//
// Returns    : -
//
// Remark(s)  : The behaviour depends on the given SOP type
//              if you define new operatiors you have of course modify
//              or implement the according behaviour of that function.
//
//              This function is called at slic run time.
//
//----------------------------------------------------------------------------
BOOL SlicFrame::DoInstruction(SOP op)
{
	unsigned char* codePtr = &m_segment->m_code[m_offset];
	unsigned char* origCodePtr = &m_segment->m_code[m_offset];
#if defined(SLIC_DOUBLES)
	double dval;
#endif
	
	sint32 ival, ival2; 

	
	SlicStackValue sval1, sval2, sval3;

	SS_TYPE type1, type2, type3;
	SlicSymbolData *symval;
	BOOL stopped = FALSE;
	sint32 sp;
	sint32 res;
	BOOL calcOffset = TRUE;

	//Added by Martin Gühmann for database access
	SlicDBInterface *conduit;
	char* name;

	switch(op) {
		case SOP_PUSHI:
			sval1.m_int = *(reinterpret_cast<sint32 *>(codePtr));
			codePtr += sizeof(sint32);
			m_stack->Push(SS_TYPE_INT, sval1);
			break;

		case SOP_PUSHD:
#if defined(SLIC_DOUBLES)
			dval = *((double*)codePtr);
            // Probably some handling missing here. Now, we just skip some bytes.
#endif
			codePtr += sizeof(sint32);
			break;

		case SOP_PUSHV:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(int);
			sval1.m_sym = g_slicEngine->GetSymbol(ival);
			if (sval1.m_sym) 
            {
                m_stack->Push(SS_TYPE_SYM, sval1);
            }
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL symbol %d\n", ival));
				stopped = TRUE;
			}
			break;

		case SOP_PUSHM:
		{
			ival = *((sint32*)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL struct symbol %d\n", ival));
				stopped = TRUE;
				break;
			}

			if(symval->GetType() != SLIC_SYM_STRUCT) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, %s is not a struct\n", symval->GetName()));
				stopped = TRUE;
				break;
			}

			SlicStructInstance *theStruct = symval->GetStruct();
			Assert(theStruct);

			ival2 = *((sint32*)codePtr);
			codePtr += sizeof(sint32);
			
			sval1.m_sym = theStruct->GetMemberSymbol(ival2);
			m_stack->Push(SS_TYPE_SYM, sval1);
			break;
		}

		case SOP_PUSHAM:
		{
			
			ival = *((sint32*)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL struct symbol %d\n", ival));
				stopped = TRUE;
				break;
			}

			if(symval->GetType() != SLIC_SYM_ARRAY) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, %s is not an array\n", symval->GetName()));
				stopped = TRUE;
				break;
			}

			
			sp = m_stack->Pop(type3, sval3);
			Assert(sp >= 1);
			
			
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);

			
			if(!symval->ArrayLookup(Eval(type3, sval3), type1, sval1)) {
				DPRINTF(k_DBG_SLIC, ("Couldn't perform array lookup in SOP_PUSHAM\n"));
				stopped = TRUE;
				break;
			}
			
			
			SlicSymbolData * structSym = SlicStack::GetSymbol(type1, sval1);
			if (!structSym) 
            {
				DPRINTF(k_DBG_SLIC, ("Couldn't find struct symbol in SOP_PUSHAM\n"));
				stopped = TRUE;
				break;
			}
			
			if(structSym->GetType() != SLIC_SYM_STRUCT) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, array symbol id not a struct in SOP_PUSHAM\n"));
				stopped = TRUE;
				break;
			}

			SlicStructInstance *theStruct = structSym->GetStruct();
			Assert(theStruct);
			
			
			ival2 = *((sint32*)codePtr);
			codePtr += sizeof(sint32);
			
			sval1.m_sym = theStruct->GetMemberSymbol(ival2);
			m_stack->Push(SS_TYPE_SYM, sval1);
			break;
		}

		case SOP_PUSHA:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(int);
			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL symbol %d\n", ival));
				stopped = TRUE;
				break;
			}

			sval1.m_sym = symval;
			m_stack->Push(SS_TYPE_SYM, sval1);
			break;

		case SOP_AINDX:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 1);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			res = ArrayLookup(type2, sval2, type1, sval1,
							  type3, sval3);
			if(res)
				
				m_stack->Push(type3, sval3);
			else {
				sval3.m_int = 0;
				
				m_stack->Push(SS_TYPE_INT, sval3);
			}
			break;
		case SOP_ADD:  
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) + Eval(type1, sval1);
			
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_SUB:  
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) - Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_MULT: 
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) * Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_EXP: 
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = static_cast<int>
				(pow(static_cast<double>(Eval(type2, sval2)), Eval(type1, sval1)));
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		// Bitwise operators:
		case SOP_BAND: 
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) & Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		case SOP_BOR:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) | Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		case SOP_BXOR:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) ^ Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		case SOP_BNOT:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sval3.m_int = ~Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		case SOP_DIV:  
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			if(Eval(type1, sval1) == 0) {

				//Added by Martin Gühmann
				//It is a problem of slic code and not of the ctp2.exe,
				//the slicer has to solve the problem.
				if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
					c3errors_ErrorDialog("Slic", "In object %s: Division by 0.", m_segment->GetName());
				}
				sval3.m_int = 0;
				m_stack->Push(SS_TYPE_INT, sval3);
				break;
			}
			sval3.m_int = Eval(type2, sval2) / Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_MOD:  
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
            {
                sint32 const    divisor = Eval(type1, sval1);
                if (0 == divisor)
                {
                    // Handle error as for SOP_DIV.
                    if (g_theProfileDB && g_theProfileDB->IsDebugSlic())
                    {
                        c3errors_ErrorDialog("Slic", "In object %s: modulo 0.",
                                             m_segment->GetName()
                                            );
                    }
                    sval3.m_int = 0;
                }
                else
                {
                    sval3.m_int = Eval(type2, sval2) % divisor;
                }
            }
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_EQ:   
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = IsEqual(type2, sval2, type1, sval1);
			
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_GT:   
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) > Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_LT:   
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) < Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_GTE:  

			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) >= Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_LTE:  

			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) <= Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_NEQ:
			
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = !IsEqual(type2, sval2, type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_AND:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) && Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_OR:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);
			sval3.m_int = Eval(type2, sval2) || Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);

			break;
		case SOP_NOT:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sval3.m_int = !Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		case SOP_POP:  
			
			
			Assert(FALSE);
			break;
		case SOP_TRIG: 
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sval3.m_int = Eval(type1, sval1);
			if(!sval3.m_int)
				stopped = TRUE;
			break;
		case SOP_ARGE: 
			sp = m_stack->Pop(type1, sval1);			
			AddArg(type1, sval1);
			break;
		case SOP_ARGID:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, NULL symbol %d\n", ival));
				return FALSE;
			}
			if(symval->GetType() != SLIC_SYM_ID) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, symbol %s is not of type ID\n",
						symval->GetName()));
				return FALSE;
			}
			m_argList->AddArg(symval->GetSegment(), symval);
			break;
		case SOP_ARGS: 
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(symval->GetType() != SLIC_SYM_SVAR) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, string arg doesn't have string type\n"));
				return FALSE;
			}
			m_argList->AddArg(SA_TYPE_STRING, sint32(symval->GetStringId()));
			break;
		case SOP_ARGST:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(symval->GetType() != SLIC_SYM_STRING) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, hard string doesn't have hard string type\n"));
				return FALSE;
			}
			m_argList->AddArg(SA_TYPE_HARD_STRING, symval);
			break;
		case SOP_CALL:
		case SOP_CALLR:
		{
			
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, NULL symbol %d\n", ival));
				return FALSE;
			}
			if(symval->GetType() != SLIC_SYM_FUNC && symval->GetType() != SLIC_SYM_UFUNC) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, symbol %s is not a function\n",
						symval->GetName()));
				return FALSE;
			}
			SlicFunc *funcObj = symval->GetFunction();
			SFN_ERROR err;

			if(!funcObj) {
				
				SlicSegment *segment = g_slicEngine->GetSegment(symval->GetName());
				if(!segment || segment->GetType() != SLIC_OBJECT_FUNCTION) {
					DPRINTF(k_DBG_SLIC, ("Undefined function %s\n", symval->GetName()));
					if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
						c3errors_ErrorDialog("Slic", "%s is not a known function", symval->GetName());
					}
					return FALSE;
				}
				
				
				SlicObject * obj = NULL;
				err = segment->Call(m_argList, obj);
				if (obj)
                {
                    if (op == SOP_CALLR) 
                    {
					    if (g_slicEngine->AtBreak()) 
                        {
                            Assert(!m_resultObject); // need stack when failing?
                            if (m_resultObject)
                            {
                                m_resultObject->Release();
                            }
						    m_resultObject  = obj;
					    } 
                        else 
                        {
						    sval1.m_int = obj->GetResult();
						    m_stack->Push(SS_TYPE_INT, sval1);
						    obj->Release();
					    }
                    }
                    else 
                    {
                        // SOP_CALL: result not used
                        obj->Release();
                    }
				}
			} else {
				err = funcObj->Call(m_argList);
				if(op == SOP_CALLR) {
					switch(funcObj->GetReturnType()) {
						case SFR_INT:
							sval1.m_int = funcObj->GetResult().m_int;
							m_stack->Push(SS_TYPE_INT, sval1);
							break;
						default:
							sval1.m_int = 0;
							m_stack->Push(SS_TYPE_INT, sval1);
							Assert(FALSE);
					}
				}
			}
			if(err != SFN_ERROR_OK) {
				ReportSFError(err, symval);
				stopped = TRUE;
			}

			
			m_argStackPtr--;
			Assert(m_argStackPtr >= -1);
			if(m_argStackPtr >= 0) {
				m_argList = &m_argListArray[m_argStackPtr];
			} else if(m_argStackPtr == -1) {
				m_argList = NULL;
			}

			if(g_slicEngine->AtBreak())
				stopped = TRUE;

			break;
		}
		case SOP_EVENT:
		{
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			if(g_gevManager->IsProcessing()) {
				EVENTLOG(("    "));
			}

			EVENTLOG(("Event:%s(", g_gevManager->GetEventName((GAME_EVENT)ival)));

			GameEventArgList *args = m_argList->CreateGameEventArgs((GAME_EVENT)ival);
			EVENTLOG((") : Serial %d\n", g_gevManager->GetNextSerial()));

			g_gevManager->ArglistAddEvent(GEV_INSERT_Tail,
										  (GAME_EVENT)ival,
										  args);
			
			
			m_argStackPtr--;
			Assert(m_argStackPtr >= -1);
			if(m_argStackPtr >= 0) {
				m_argList = &m_argListArray[m_argStackPtr];
			} else if(m_argStackPtr == -1) {
				m_argList = NULL;
			}

			if(g_slicEngine->AtBreak())
				stopped = TRUE;

			break;
		}
		case SOP_SBLK:
			DPRINTF(k_DBG_SLIC, ("dangling SBLK\n"));
			return FALSE;
		case SOP_END:
			stopped = TRUE;
			codePtr += sizeof(sint32); 
			break;
		case SOP_JMP:
			m_offset    = *(reinterpret_cast<sint32 *>(codePtr));
			calcOffset  = FALSE;
			break;
		case SOP_BNT:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			sp = m_stack->Pop(type2, sval2);
			if(!Eval(type2, sval2)) {
				m_offset = ival;
				calcOffset = FALSE;
			}
			break;
		case SOP_BNEV:
			
			
			
			codePtr += sizeof(sint32);
			
			break;
		case SOP_BUTN:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			ival2 = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);

			symval = g_slicEngine->GetSymbol(ival2);
			if(symval->GetType() != SLIC_SYM_SVAR) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, button string arg doesn't have string type\n"));
				return FALSE;
			}
			g_slicEngine->GetContext()->AddButton(new SlicButton(
				(StringId)symval->GetStringId(), m_segment,
				ival, g_slicEngine->GetContext()));
			break;
		case SOP_OCLS:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);

			g_slicEngine->GetContext()->AddButton(new SlicButton(
					 		 -1, m_segment, ival,
							 g_slicEngine->GetContext()));
			break;
		case SOP_STOP:
			stopped = TRUE;
			break;
		case SOP_NEG:
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			sval3.m_int = 0 - Eval(type1, sval1);
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		case SOP_ASSN:
			ival = *((sint32*)codePtr);
			codePtr += sizeof(sint32);

			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL symbol %d\n", ival));
				stopped = TRUE;
				break;
			}

			sp = m_stack->Pop(type1, sval1);
			
			
			SetValue(symval, type1, sval1);
			break;
		case SOP_ASSNA:
			
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL symbol %d in array assignment", ival));
				stopped = TRUE;
				break;
			}

			if(symval->GetType() != SLIC_SYM_ARRAY) {
				if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
					c3errors_ErrorDialog("Slic", "Symbol '%s' used in array assignment is not an array", symval->GetName());
				}
				stopped = TRUE;
				break;
			}

			
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 1);

			
			sp = m_stack->Pop(type3, sval3);
			Assert(sp >= 0);
			
			SetArrayValue(symval, type2, sval2, type3, sval3);
			break;
		case SOP_ASSNM:
		{
			ival = *((sint32*)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			if(!symval) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL struct symbol %d\n", ival));
				stopped = TRUE;
				break;
			}

			if(symval->GetType() != SLIC_SYM_STRUCT) {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, %s is not a struct\n", symval->GetName()));
				stopped = TRUE;
				break;
			}

			SlicStructInstance *theStruct = symval->GetStruct();
			Assert(theStruct);

			ival2 = *((sint32*)codePtr);
			codePtr += sizeof(sint32);
			
			symval = theStruct->GetMemberSymbol(ival2);
			
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			SetValue(symval, type1, sval1);
			break;
		}
		case SOP_ASSNAM:
		{
			

			
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			SlicSymbolData *arraySym = g_slicEngine->GetSymbol(ival);

			
			ival2 = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			
			if(!arraySym) {
				DPRINTF(k_DBG_SLIC, ("Bad Mojo, symbol %d does not exist", ival));
				stopped = TRUE;
				break;
			}

			if(arraySym->GetType() != SLIC_SYM_ARRAY) {
				DPRINTF(k_DBG_SLIC, ("%s is not an array", arraySym->GetName()));
				stopped = TRUE;
				break;
			}

			
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 1);

			
			sp = m_stack->Pop(type2, sval2);
			Assert(sp >= 0);

			if(!arraySym->ArrayLookup(Eval(type2, sval2), type3, sval3)) {
				DPRINTF(k_DBG_SLIC, ("Array lookup, %s[%d], failed\n", 
									 arraySym->GetName(), Eval(type2, sval2)));
				stopped = TRUE;
				break;
			}

			SlicSymbolData *structSym = SlicStack::GetSymbol(type3, sval3);
			if (!structSym) 
			{
				DPRINTF(k_DBG_SLIC, ("Couldn't find symbol for %s[%d]\n",
									 arraySym->GetName(), Eval(type2, sval2)));
				stopped = TRUE;
				break;
			}

			if(structSym->GetType() != SLIC_SYM_STRUCT) {
				DPRINTF(k_DBG_SLIC, ("%s[%d] is not a struct\n",
									 arraySym->GetName(), Eval(type2, sval2)));
				stopped = TRUE;
				break;
			}

			SlicStructInstance *theStruct = structSym->GetStruct();
			Assert(theStruct);

			if(!theStruct) {
				stopped = TRUE;
				break;
			}
			SlicSymbolData *assnSym = theStruct->GetMemberSymbol(ival2);
			assnSym->SetValueFromStackValue(type1, sval1);
			break;
		}			
		case SOP_SARGS:
			
			m_argStackPtr++;
			Assert(m_argStackPtr < k_ARGLIST_STACK_SIZE);
			if(m_argStackPtr < k_ARGLIST_STACK_SIZE) {
				m_argList = &m_argListArray[m_argStackPtr];
				m_argList->Clear();
			}
			break;
		case SOP_RET:
			
			sp = m_stack->Pop(type1, sval1);
			Assert(sp >= 0);
			g_slicEngine->GetContext()->SetResult(Eval(type1, sval1));
			stopped = TRUE;
			break;
		case SOP_LINE:
		case SOP_LBRK:
		{
			
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			m_currentLine = ival;

			ival2 = *((sint32 *)codePtr);
			if(m_segment->GetFilename()) {
				if(ival2 < 0) {
					
					
					*((sint32 *)codePtr) = FindFileOffset(m_segment->GetFilename(), ival);
					ival2 = *((sint32 *)codePtr);
				}
			}

			codePtr += sizeof(sint32);

			SlicConditional *cond = *((SlicConditional **)codePtr);
			codePtr += sizeof(SlicConditional *);

			if(op == SOP_LBRK || g_slicEngine->BreakRequested()) {
				if(!cond || (cond->Eval() != 0)) {
					
					
					g_slicEngine->Break(m_segment, codePtr - m_segment->m_code, 
										g_slicEngine->GetContext(), m_stack,
										m_messageData);
					stopped = TRUE;
				}
			}

			break;
		}
		case SOP_ASIZE:
			ival = *((sint32 *)codePtr);
			codePtr += sizeof(sint32);
			symval = g_slicEngine->GetSymbol(ival);
			Assert(symval);
			if(symval) {
				sval1.m_int = symval->GetArray()->GetSize();
			}
			else{
				sval1.m_int = 0;
			}
			m_stack->Push(SS_TYPE_INT, sval1);
			break;

		//Added by Martin Gühmann for database support
		case SOP_DBNAME:
		{
			conduit     = GetDatabase(codePtr);
			ival        = *((sint32 *)codePtr);
			codePtr    += sizeof(sint32);
			symval      = g_slicEngine->GetSymbol(ival);

			if (conduit && symval) 
            {
			    sval1.m_sym = symval;
			    sval3.m_int = Eval(SS_TYPE_SYM, sval1);		
			
			    if ((sval3.m_int >= 0) && sval3.m_int < conduit->GetNumRecords())
                {	
                    // No action: value is OK
			    }
			    else
                {
				    sval3.m_int = -1;
                }
                
                m_stack->Push(SS_TYPE_INT, sval3);
			}
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL symbol %d\n", ival));
				stopped = TRUE;
			}
			break;
		}
		case SOP_DBNAMEREF:
		{
			conduit     = GetDatabase(codePtr);
			ival        = *((sint32 *)codePtr);
			codePtr    += sizeof(sint32);
			symval      = g_slicEngine->GetSymbol(ival);

			if (conduit && symval) 
            {
                //Get the member:
                name = reinterpret_cast<char *>(codePtr);
                Assert(name);
                for ( ; *codePtr++; )
                {
	                // No action: just skip
                }

                sval1.m_sym = symval;
                sval3.m_int = Eval(SS_TYPE_SYM, sval1);		

                if(sval3.m_int > -1 && sval3.m_int < conduit->GetNumRecords()){		
	                sval3.m_int = conduit->GetValue(sval3.m_int, name);
	                m_stack->Push(SS_TYPE_INT, sval3);
                }
                else{
	                if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
		                c3errors_ErrorDialog("Slic", "In object %s no entry found with index %i in %s.", m_segment->GetName(), sval3.m_int, conduit->GetName());
	                }
	                sval3.m_int = 0;
	                m_stack->Push(SS_TYPE_INT, sval3);
                }
            }
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL symbol %d\n", ival));
				stopped = TRUE;
            }
			break;
		}
		case SOP_DBNAMEARRAY:
		{
			conduit     = GetDatabase(codePtr);
			ival        = *((int*)codePtr);
			codePtr    += sizeof(int);
			symval      = g_slicEngine->GetSymbol(ival);

			if (conduit && symval) 
            {
			    //Get the member:
			    name    = reinterpret_cast<char *>(codePtr);
			    Assert(name);
			    for ( ; *codePtr++ ; )
                {
				    // No action: just skip
			    }

			    sval1.m_sym = symval;
			    sval3.m_int = Eval(SS_TYPE_SYM, sval1);		

			    sp = m_stack->Pop(type2, sval2);
			    Assert(sp >= 0);

			    sval2.m_int = Eval(type2, sval2);

			    if(sval3.m_int > -1 && sval3.m_int < conduit->GetNumRecords()){		
				    sval3.m_int = conduit->GetValue(sval3.m_int, name, sval2.m_int);
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
			    else{
				    if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
					    c3errors_ErrorDialog("Slic", "In object %s no entry found with index %i in %s.", m_segment->GetName(), sval3.m_int, conduit->GetName());
				    }
				    sval3.m_int = 0;
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
            }
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, NULL symbol %d\n", ival));
				stopped = TRUE;
			}

			break;
		}
		case SOP_DBNAMECONSTARRAY:
		{
			conduit     = GetDatabase(codePtr);

            if (conduit)
            {
			    sval3.m_int = *((sint32 *)codePtr);
			    codePtr    += sizeof(sint32);
			    //Get the member:
			    name = reinterpret_cast<char *>(codePtr);
			    Assert(name);
			    for ( ; *codePtr++; )
                {
				    // No action: just skip
			    }

			    sp = m_stack->Pop(type2, sval2);
			    Assert(sp >= 0);

			    sval2.m_int = Eval(type2, sval2);


			    if(sval3.m_int > -1 && sval3.m_int < conduit->GetNumRecords()){		
				    sval3.m_int = conduit->GetValue(sval3.m_int, name, sval2.m_int);
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
			    else{
				    if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
					    c3errors_ErrorDialog("Slic", "In object %s no entry found with index %i in %s.", m_segment->GetName(), sval3.m_int, conduit->GetName());
				    }
				    sval3.m_int = 0;
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
            }
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, incorrect database symbol\n"));
				stopped = TRUE;
            }

			break;
		}
		case SOP_DB:
		{
			conduit = GetDatabase(codePtr);

			if (conduit)
            {
			    sp = m_stack->Pop(type1, sval1);
			    Assert(sp >= 0);

			    sval3.m_int = Eval(type1, sval1);

			    if(sval3.m_int > -1 && sval3.m_int < conduit->GetNumRecords()){		
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
			    else{
				    sval3.m_int = -1;
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
            }
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, incorrect database symbol\n"));
				stopped = TRUE;
            }

			break;
		}
		case SOP_DBREF:
		{
			conduit = GetDatabase(codePtr);

			if (conduit)
            {
			    //Get the member:
			    name = reinterpret_cast<char *>(codePtr);
			    Assert(name);
			    for ( ; *codePtr++ ; )
                {
				    // No action: just skip
			    }

			    sp = m_stack->Pop(type1, sval1);
			    Assert(sp >= 0);

			    sval2.m_int = Eval(type1, sval1);

			    if(sval2.m_int > -1 && sval2.m_int < conduit->GetNumRecords()){		
				    sval3.m_int = conduit->GetValue(sval2.m_int, name);
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
			    else{
				    if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
					    c3errors_ErrorDialog("Slic", "In object %s no entry found with index %i in %s.", m_segment->GetName(), sval2.m_int, conduit->GetName());
				    }
				    sval2.m_int = 0;
				    m_stack->Push(SS_TYPE_INT, sval2);
			    }
            }
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, incorrect database symbol\n"));
				stopped = TRUE;
            }

			break;
		}
		case SOP_DBARRAY:
		{
			conduit = GetDatabase(codePtr);

			if (conduit)
            {
			    //Get the member:
			    name = reinterpret_cast<char *>(codePtr);
			    Assert(name);
			    for ( ; *codePtr++; )
                {
				    // Just skip
			    }

			    sp = m_stack->Pop(type1, sval1);
			    Assert(sp >= 0);

			    sval1.m_int = Eval(type1, sval1);

			    sp = m_stack->Pop(type2, sval2);
			    Assert(sp >= 0);

			    sval2.m_int = Eval(type2, sval2);

			    if(sval2.m_int > -1 && sval2.m_int < conduit->GetNumRecords()){		
				    sval3.m_int = conduit->GetValue(sval2.m_int, name, sval1.m_int);
				    m_stack->Push(SS_TYPE_INT, sval3);
			    }
			    else{
				    if(g_theProfileDB && g_theProfileDB->IsDebugSlic()) {
					    c3errors_ErrorDialog("Slic", "In object %s no entry found with index %i in %s.", m_segment->GetName(), sval2.m_int, conduit->GetName());
				    }
				    sval2.m_int = 0;
				    m_stack->Push(SS_TYPE_INT, sval2);
			    }
            }
            else
            {
				DPRINTF(k_DBG_SLIC, ("Bad mojo, incorrect database symbol\n"));
				stopped = TRUE;
            }
            
			break;
		}
		case SOP_DBSIZE:
		{
			//Added by Martin Gühmann to figure out via 
			//slic how many records the database contains
			//Get the database:
			conduit = GetDatabase(codePtr);
			Assert(conduit);
			if (conduit)
            {
				sval3.m_int = conduit->GetNumRecords();
			}
			else
            {
				sval3.m_int = 0;
			}
			m_stack->Push(SS_TYPE_INT, sval3);
			break;
		}

		default:
			DPRINTF(k_DBG_SLIC, ("???\n"));
			break;
	}
	if(calcOffset)
		m_offset += codePtr - origCodePtr;
	return !stopped;
}
Ejemplo n.º 13
0
void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
{
    for (const std::string& name : names) {
        AddArg(name, "", false, OptionsCategory::HIDDEN);
    }
}
Ejemplo n.º 14
0
BOOL CCmd_Describe::Run(int descType, LPCTSTR reference, 
						LPCTSTR templateName/*=NULL*/, 
						BOOL force/*=FALSE*/,
						int flag  /*= 0*/, 
						BOOL uFlag/*=FALSE*/)
{
	ClearArgs();
	m_SpecType=descType;
	switch (m_SpecType)
	{
	case P4DESCRIBELONG:
		m_bLong = TRUE;
		m_SpecType=P4DESCRIBE;
		AddArg(_T("describe"));
		switch (m_Flag = flag)
		{
		case ID_SHOWDIFFS_SUMMARY:
			AddArg(_T("-ds"));
			break;
		case ID_SHOWDIFFS_UNIFIED:
			AddArg(_T("-du"));
			break;
		case ID_SHOWDIFFS_CONTEXT:
			AddArg(_T("-dc"));
			break;
		case ID_SHOWDIFFS_RCS:
			AddArg(_T("-dn"));
			break;
		case ID_SHOWDIFFS_NONE:
			m_Flag = 0;
			AddArg(_T("-s"));
			break;
		}
		break;
	case P4DESCRIBE:
		AddArg(_T("describe"));
		AddArg(_T("-s"));
		break;
	case P4BRANCH_SPEC:
		AddArg(_T("branch"));	
		AddArg(_T("-o"));
		break;
	case P4CHANGE_SPEC:
		AddArg(_T("change"));	
		AddArg(_T("-o"));
		if( uFlag && GET_SERVERLEVEL() >= 23 )	// 2007.2 or later?
			AddArg(_T("-u"));
		else if( force || uFlag )
			AddArg(_T("-f"));
		break;
	case P4CLIENT_SPEC:
        AddArg(_T("client"));	
		AddArg(_T("-o"));
        if( templateName!=NULL )
        {
            AddArg(_T("-t"));
            AddArg(templateName);
        }
        break;
	case P4JOB_SPEC:
		AddArg(_T("job"));		
		AddArg(_T("-o"));
		break;
	case P4LABEL_SPEC:
		AddArg(_T("label"));	
		AddArg(_T("-o"));
		if( templateName!=NULL )
        {
            AddArg(_T("-t"));
            AddArg(templateName);
        }
		break;
	case P4USER_SPEC:
		AddArg(_T("user"));		
		AddArg(_T("-o"));
		break;
	case P4GROUP_SPEC:
		AddArg(_T("group"));		
		AddArg(_T("-o"));
		break;
	default:
		ASSERT(0);
		return FALSE;
	}
	
	if(reference != NULL && _tcslen(reference) > 0)
	{
		m_Reference = reference;
		m_Reference.TrimLeft(_T('\"'));
		m_Reference.TrimRight(_T('\"'));
		AddArg(m_Reference);
	}
	else m_Reference = _T("");
	m_Description=_T("");

	return CP4Command::Run();
}
Ejemplo n.º 15
0
BOOL CCmd_Fstat::Run(BOOL suppress, CStringList *specList, BOOL bShowEntireDepot, 
					 long minChange/*=0*/, BOOL bWorking/*=FALSE*/, 
					 long wkChgNbr/*=-1*/, long maxOutput/*=0*/)
{
    ASSERT_KINDOF( CStringList, specList );
	ASSERT( specList->GetCount() );
	
	ClearArgs();
	m_BaseArgs= AddArg(_T("fstat"));

	if(GET_SERVERLEVEL() >= 19)			// 2005.1 or later?
	{
		m_BaseArgs= AddArg(_T("-Ol"));
		m_BaseArgs= AddArg(_T("-Oh"));
		if (bWorking)
		{
			m_bWorking = TRUE;
			m_BaseArgs= AddArg(_T("-Ro"));
			if (wkChgNbr != -1)
			{
				AddArg( g_sChangeList_e );
				if (!wkChgNbr)
					m_BaseArgs= AddArg(_T("default"));
				else
					m_BaseArgs= AddArg(wkChgNbr);
			}
		}
	}
	else if (bWorking)
	{
		ASSERT(0);
		return FALSE;
	}

	if(suppress)
		m_BaseArgs= AddArg(_T("-s"));
	if(minChange > 0)
	{
		AddArg( g_sChangeList );
		m_BaseArgs= AddArg(minChange);
	}

	if ( ! bShowEntireDepot && GET_SERVERLEVEL() > 3 )
		m_BaseArgs= AddArg ( g_sClientViewOnly );

	if ( maxOutput && GET_SERVERLEVEL() > 20 )
	{
		if (maxOutput == -1)
			m_IgnorePermissionErrs = TRUE;
		else
		{
			m_BaseArgs= AddArg ( g_sMaxOutput );
			m_BaseArgs= AddArg ( maxOutput );
			if (maxOutput == 1)
				m_IgnorePermissionErrs = TRUE;
		}
	}

	m_pBatch= new CObList;

    m_posStrListIn= specList->GetHeadPosition();
	m_pStrListIn= specList;  
	
	// Put the first few files into the arg list
	NextListArgs();

	return CP4Command::Run();
}
Ejemplo n.º 16
0
static void
Start(int nextArg, int argc, char *argv[])
{
    int i;
    time_t lastExit = 0;
    pid_t otherInstance;

    CheckJavaBinaryExists();

    syslog(LOG_INFO, "checking if another instance of manager is already running");
    otherInstance = GetPidOfRunningManagerInstance();
    if (otherInstance != -1) {
	syslog(LOG_ERR, "another instance of manager is already running (pid=%d)", otherInstance);
	exit(1);
    }

    /* first argument must be name of binary */
    AddArg(JAVA_BINARY);
    
    for (i = nextArg; i < argc; i++) {
	if (IsAllowedJVMArg(argv[i])) {
	    AddArg(argv[i]);
	} else {
	    syslog(LOG_ERR, "JVM option: %s: not allowed\n", argv[i]);
	    exit(1);
	}
    }
    
    /* REMIND: Do we need this?  Seems applicable only when -jar option
     * is present?
     * AddArg("-jre-no-restrict-search");
     */
   
    AddArgFmt("-Djava.io.tmpdir=%s/work", MAILBOXD_HOME); 
    AddArgFmt("-Djava.library.path=%s", ZIMBRA_LIB);
    AddArgFmt("-Djava.endorsed.dirs=%s/common/endorsed", MAILBOXD_HOME);
    AddArgFmt("-Dzimbra.config=%s", ZIMBRA_CONFIG);

    /* We don't want these things being passed in from command line */
    AddArgFmt("-Djetty.home=%s", MAILBOXD_HOME);
    AddArgFmt("-DSTART=%s/etc/start.config", MAILBOXD_HOME);
    AddArg("-jar");
    AddArgFmt("%s/start.jar", MAILBOXD_HOME);
    AddArg("OPTIONS=Server,jsp,jmx,resources,websocket,ext,jta,plus,rewrite,setuid");
    AddArgFmt("%s/etc/jetty.properties", MAILBOXD_HOME);
    AddArgFmt("%s/etc/jetty-setuid.xml", MAILBOXD_HOME);
    AddArgFmt("%s/etc/jetty.xml", MAILBOXD_HOME);

    if (Verbose) {
	ShowNewEnv();
	ShowNewArgs();
    }
    
    /* Now daemonize the manager process. */
    if (fork() != 0) {
	exit(0);
    }

    /* We are in manager child process. */

    setsid();

    chdir(MAILBOXD_CWD);
  
    /* Note that the PID that is written is the PID of the launcher
     * process, not that of the JVM. */
    RecordPid("manager", MAILBOXD_MANAGER_PIDFILE, getpid());
    
    /* On SIGTERM, we set ShutdownRequested to true. */
    signal(SIGTERM, StopHandler);
    
    /* On SIGHUP, we go ahead and shutdown mailboxd, but do not set
       ShutdownRequested to true. */
    signal(SIGHUP, StopHandler);
    
    /* On SIGQUIT, we forward the SIGQUIT on to the mailboxd/JVM
       process. */
    signal(SIGQUIT, ThreadDumpHandler);

    while (1) {
	StartMailboxd();
	
	syslog(LOG_INFO, "manager started mailboxd/JVM with pid %d", MailboxdPid);
	wait(NULL);
	syslog(LOG_INFO, "manager woke up from wait on mailboxd/JVM with pid %d", MailboxdPid);
	if (ShutdownRequested) {
	    unlink(MAILBOXD_MANAGER_PIDFILE);
	    unlink(MAILBOXD_JAVA_PIDFILE);
	    unlink(MAILBOXD_MANAGER_DEPRECATED_PIDFILE);
	    break;
	}
	
	if (BounceRequested) {
	    BounceRequested = 0;
	    lastExit = 0;
	    /* Pretend as though the process has never crashed before,
	       by not setting lastExit. */
	    continue;
	}
	
	if (lastExit > 0) {
	    time_t now = time(NULL);
	    if ((now - lastExit) < DoubleExitInterval) {
		syslog(LOG_ERR, "mailboxd/JVM exited twice in %d seconds (tolerance=%d)",
		       (int)(now - lastExit), DoubleExitInterval);
		exit(1);
	    }
	    /* Any subsequent time child crashed ... */
	    lastExit = now;
	} else {
	    /* First time child crashed... */
	    lastExit = time(NULL);
	}
    }
}
Ejemplo n.º 17
0
BOOL CCmd_SendSpec::Run( int specType, LPCTSTR specText, BOOL submit, 
						 BOOL force /*=FALSE*/, BOOL reopen /*=FALSE*/, 
						 int unchangedFlag /*=0*/, BOOL uFlag/*=FALSE*/ )
{
	ASSERT( specType==P4CHANGE_SPEC || !submit );

	m_Submit= submit;
	m_ForceEdit= force;
	m_Reopen= reopen;
	m_UnchangedFlag= unchangedFlag;
	m_SpecText= specText;
    m_SpecTextSent = false;
	m_SpecType= specType;

	ClearArgs();
	
	switch (m_SpecType)
	{
	case P4BRANCH_SPEC:
		AddArg(_T("branch"));  break;
	case P4CHANGE_SPEC:
		if(submit)
			AddArg(_T("submit"));
		else
			AddArg(_T("change"));  
		break;
	case P4CLIENT_SPEC:
        AddArg(_T("client"));  break;
	case P4JOB_SPEC:
		AddArg(_T("job"));     break;
	case P4LABEL_SPEC:
		AddArg(_T("label"));   break;
	case P4USER_SPEC:
		AddArg(_T("user"));	   break;
	default:
		ASSERT(0);
		return FALSE;
	}

	if( uFlag && GET_SERVERLEVEL() >= 23 )	// 2007.2 or later?
		AddArg(_T("-u"));
	else if( force || uFlag )
		AddArg(_T("-f"));

	if (submit)
	{
		if (GET_SERVERLEVEL() >= 22)	// 2006.2 or later?
		{
			if( !force )			// has the -f already been added?
				AddArg(_T("-f"));	// if not, add it

			switch(unchangedFlag)
			{
			case 0:
				AddArg(reopen ? _T("submitunchanged+reopen") : _T("submitunchanged"));
				break;

			case 1:
				AddArg(reopen ? _T("revertunchanged+reopen") : _T("revertunchanged"));
				break;

			default:
			case 2:
				AddArg(reopen ? _T("leaveunchanged+reopen") : _T("leaveunchanged"));
				break;
			}
		}
		else
		{
			if( reopen && GET_SERVERLEVEL() >= 13)
				AddArg(_T("-r"));
			
			if( unchangedFlag==1 && GET_SERVERLEVEL() >= 21)	// 2006.1 (only)
				AddArg(_T("-R"));
		}
	}

	AddArg( _T("-i") );

	return CP4Command::Run();
}