Exemplo n.º 1
0
int
main(int argc, char **argv)
{
	int	res;
	char	*p;

	if ((p = strrchr(argv[0], '/')) == NULL)
		p = argv[0];
	else
		p++;
	if (strcmp(p, "[") == 0) {
		if (strcmp(argv[--argc], "]") != 0)
			error("missing ]");
		argv[argc] = NULL;
	}

	/* no expression => false */
	if (--argc <= 0)
		return 1;

#ifndef SHELL
	(void)setlocale(LC_CTYPE, "");
#endif
	nargc = argc;
	t_wp = &argv[1];
	parenlevel = 0;
	if (nargc == 4 && strcmp(*t_wp, "!") == 0) {
		/* Things like ! "" -o x do not fit in the normal grammar. */
		--nargc;
		++t_wp;
		res = oexpr(t_lex(*t_wp));
	} else
		res = !oexpr(t_lex(*t_wp));

	if (--nargc > 0)
		syntax(*t_wp, "unexpected operator");

	return res;
}
Exemplo n.º 2
0
int
testcmd(int argc, char **argv)
{
	int res;

	if (strcmp(argv[0], "[") == 0) {
		if (strcmp(argv[--argc], "]"))
			error("missing ]");
		argv[argc] = NULL;
	}

	if (argc < 2)
		return 1;

	t_wp = &argv[1];
	res = !oexpr(t_lex(*t_wp));

	if (*t_wp != NULL && *++t_wp != NULL)
		syntax(*t_wp, "unexpected operator");

	return res;
}
Exemplo n.º 3
0
EPNODE *
getE2(void)			/* E2 -> E2 MULOP E3 */
				/*	 E3 */
{
    EPNODE  *ep1, *ep2;

    ep1 = getE3();
    while (nextc == '*' || nextc == '/') {
	ep2 = newnode();
	ep2->type = nextc;
	scan();
	addekid(ep2, ep1);
	addekid(ep2, getE3());
	if (esupport&E_RCONST) {
		EPNODE	*ep3 = ep1->sibling;
		if (ep1->type == NUM && ep3->type == NUM) {
			ep2 = rconst(ep2);
		} else if (ep3->type == NUM) {
			if (ep2->type == '/') {
				if (ep3->v.num == 0)
					syntax("divide by zero constant");
				ep2->type = '*';	/* for speed */
				ep3->v.num = 1./ep3->v.num;
			} else if (ep3->v.num == 0) {
				ep1->sibling = NULL;	/* (E2 * 0) */
				epfree(ep2);
				ep2 = ep3;
			}
		} else if (ep1->type == NUM && ep1->v.num == 0) {
			epfree(ep3);		/* (0 * E3) or (0 / E3) */
			ep1->sibling = NULL;
			efree((char *)ep2);
			ep2 = ep1;
		}
	}
	ep1 = ep2;
    }
    return(ep1);
}
Exemplo n.º 4
0
MStatus tm_polyExtract::doIt( const MArgList& args )
{
	MStatus stat = MS::kSuccess;
	clearResult();

	MArgDatabase argData( syntax(), args);

//	if(argData.isFlagSet( extractFaces_Flag))
	{
		MSelectionList selectionList;
		argData.getObjects( selectionList);
		MStringArray node_names;
		bool result = extractFaces_Func( selectionList, node_names);
		if(!result)
		{
			MGlobal::displayError("tm_polyExtract: extractFaces function call failed.");
			return MStatus::kFailure;
		}
		setResult( node_names);
		return stat;
	}
}
Exemplo n.º 5
0
MStatus userMessage::doIt( const MArgList& args )
{
	MStatus status = MS::kSuccess;

	MArgDatabase argData(syntax(), args);

	if (argData.isFlagSet(deregisterFlag))
	{
		MString event;
		argData.getFlagArgument(deregisterFlag, 0, event);
		status = MUserEventMessage::deregisterUserEvent(event);
	}
	else if (argData.isFlagSet(registerFlag))
	{
		// Register the new event and add two fixed callbacks to it.
		MString event;
		argData.getFlagArgument(registerFlag, 0, event);
		if (!MUserEventMessage::isUserEvent(event)) {
			status = MUserEventMessage::registerUserEvent(event);
			if (status == MS::kSuccess)
			{
				MUserEventMessage::addUserEventCallback(event,userCallback1,(void*) &stringClientData,&status);
				MUserEventMessage::addUserEventCallback(event,userCallback2,(void*) &stringClientData,&status);
			}
		}
	}
	else if (argData.isFlagSet(postFlag))
	{
		MString event;
	 	argData.getFlagArgument(postFlag, 0, event);
		status = MUserEventMessage::postUserEvent(event);
	}
	else if (argData.isFlagSet(testFlag))
	{
		runTests();
	}

	return status;
}
CFX_ByteString CPDF_DefaultAppearance::GetColorString(
    PaintOperation nOperation) {
  CFX_ByteString csColor;
  if (m_csDA.IsEmpty())
    return csColor;

  CPDF_SimpleParser syntax(m_csDA.AsStringC());
  if (syntax.FindTagParamFromStart(
          (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) {
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
    return csColor;
  }
  if (syntax.FindTagParamFromStart(
          (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) {
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
    return csColor;
  }
  if (syntax.FindTagParamFromStart(
          (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) {
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
    csColor += " ";
    csColor += syntax.GetWord();
  }
  return csColor;
}
void CPDF_DefaultAppearance::GetColor(FX_ARGB& color,
                                      int& iColorType,
                                      PaintOperation nOperation) {
  color = 0;
  iColorType = COLORTYPE_TRANSPARENT;
  if (m_csDA.IsEmpty())
    return;

  CPDF_SimpleParser syntax(m_csDA.AsStringC());
  if (syntax.FindTagParamFromStart(
          (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) {
    iColorType = COLORTYPE_GRAY;
    FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f;
    color = ArgbEncode(255, (int)g, (int)g, (int)g);
    return;
  }
  if (syntax.FindTagParamFromStart(
          (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) {
    iColorType = COLORTYPE_RGB;
    FX_FLOAT r = FX_atof(syntax.GetWord()) * 255 + 0.5f;
    FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f;
    FX_FLOAT b = FX_atof(syntax.GetWord()) * 255 + 0.5f;
    color = ArgbEncode(255, (int)r, (int)g, (int)b);
    return;
  }
  if (syntax.FindTagParamFromStart(
          (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) {
    iColorType = COLORTYPE_CMYK;
    FX_FLOAT c = FX_atof(syntax.GetWord());
    FX_FLOAT m = FX_atof(syntax.GetWord());
    FX_FLOAT y = FX_atof(syntax.GetWord());
    FX_FLOAT k = FX_atof(syntax.GetWord());
    FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
    FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
    FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
    color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f),
                       (int)(b * 255 + 0.5f));
  }
}
Exemplo n.º 8
0
FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData, FX_DWORD dwSize, FX_DWORD max_cost)
{
    if (m_Level > _FPDF_MAX_FORM_LEVEL_) {
        return dwSize;
    }
    FX_DWORD InitObjCount = m_pObjectList->CountObjects();
    CPDF_StreamParser syntax(pData, dwSize);
    CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax);
    m_CompatCount = 0;
    while (1) {
        FX_DWORD cost = m_pObjectList->CountObjects() - InitObjCount;
        if (max_cost && cost >= max_cost) {
            break;
        }
        switch (syntax.ParseNextElement()) {
            case CPDF_StreamParser::EndOfData:
                return m_pSyntax->GetPos();
            case CPDF_StreamParser::Keyword:
                if(!OnOperator((char*)syntax.GetWordBuf()) && _PDF_HasInvalidOpChar((char*)syntax.GetWordBuf())) {
                    m_bAbort = TRUE;
                }
                if (m_bAbort) {
                    return m_pSyntax->GetPos();
                }
                ClearAllParams();
                break;
            case CPDF_StreamParser::Number:
                AddNumberParam((char*)syntax.GetWordBuf(), syntax.GetWordSize());
                break;
            case CPDF_StreamParser::Name:
                AddNameParam((const FX_CHAR*)syntax.GetWordBuf() + 1, syntax.GetWordSize() - 1);
                break;
            default:
                AddObjectParam(syntax.GetObject());
        }
    }
    return m_pSyntax->GetPos();
}
Exemplo n.º 9
0
CFX_ByteString CPDF_DefaultAppearance::GetColorString(
    FX_BOOL bStrokingOperation) {
  CFX_ByteString csColor;
  if (m_csDA.IsEmpty()) {
    return csColor;
  }
  CPDF_SimpleParser syntax(m_csDA);
  if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) {
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
    return csColor;
  }
  syntax.SetPos(0);
  if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) {
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
    return csColor;
  }
  syntax.SetPos(0);
  if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) {
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
    csColor += " ";
    csColor += (CFX_ByteString)syntax.GetWord();
  }
  return csColor;
}
Exemplo n.º 10
0
void func_reply_mail(USER_DATA *usr, char *argument) {
	MAIL_DATA *pMail;
	char buf[STRING];
	BUFFER *buffer;
	int vnum = 1;
	int anum = 0;

	if (argument[0] == '\0' || !is_number(argument)) {
		syntax("[#Wr#x]eply <mail number>", usr);
		return;
	}

	anum = atoi(argument);
	buffer = new_buf();

	for (pMail = usr->pMailFirst; pMail; pMail = pMail->next) {
		if (pMail && (vnum++ == anum))
			break;
	}

	mail_attach(usr);
	if (usr->pCurrentMail->to)
		free_string(usr->pCurrentMail->to);
	usr->pCurrentMail->to = str_dup(pMail->from);
	if (usr->pCurrentMail->subject)
		free_string(usr->pCurrentMail->subject);
	if (pMail->subject[0] == 'R' && pMail->subject[1] == 'e'
			&& pMail->subject[2] == ':' && pMail->subject[3] == ' ')
		usr->pCurrentMail->subject = str_dup(pMail->subject);
	else {
		sprintf(buf, "Re: %s", pMail->subject);
		usr->pCurrentMail->subject = str_dup(buf);
	}
	print_to_user(usr, "To: %s\n\rSubject: %s\n\r", usr->pCurrentMail->to,
			usr->pCurrentMail->subject);
	EDIT_MODE(usr) = EDITOR_MAIL_WRITE;
	string_edit(usr, &usr->pCurrentMail->message);
}
Exemplo n.º 11
0
MStatus nodeCreatedCB::doIt( const MArgList& args )
//
//	Description:
//		implements the MEL nodeCreatedCB command.
//
{
	MStatus stat = MS::kSuccess;

	MArgDatabase argData( syntax(), args );

	// Parse command flags.
	//
	if ( argData.isFlagSet( kRegisterFlag ) ) {
		// Register a new procedure.
		//
		MString proc;
		argData.getFlagArgument( kRegisterFlag, 0, proc );
		stat = registerMelProc( proc, argData.isFlagSet( kFullDagPathFlag ) );
	} else if ( argData.isFlagSet( kUnregisterFlag ) ) {
		// Unregister a procedure.
		//
		MString proc;
		argData.getFlagArgument( kUnregisterFlag, 0, proc );
		stat = unregisterMelProc( proc );
	} else if ( argData.isFlagSet( kFilterFlag ) ) {
		// Change the filter being applied.
		//
		MString filter;
		argData.getFlagArgument( kFilterFlag, 0, filter );
		stat = changeFilter( filter );
	}
	
	if ( stat.error() ) {
		MGlobal::displayError( stat.errorString() );
	}

	return stat;
}
Exemplo n.º 12
0
void CPDF_DefaultAppearance::GetColor(FX_ARGB& color,
                                      int& iColorType,
                                      FX_BOOL bStrokingOperation) {
  color = 0;
  iColorType = COLORTYPE_TRANSPARENT;
  if (m_csDA.IsEmpty()) {
    return;
  }
  CPDF_SimpleParser syntax(m_csDA);
  if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) {
    iColorType = COLORTYPE_GRAY;
    FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f;
    color = ArgbEncode(255, (int)g, (int)g, (int)g);
    return;
  }
  syntax.SetPos(0);
  if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) {
    iColorType = COLORTYPE_RGB;
    FX_FLOAT r = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f;
    FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f;
    FX_FLOAT b = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f;
    color = ArgbEncode(255, (int)r, (int)g, (int)b);
    return;
  }
  syntax.SetPos(0);
  if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) {
    iColorType = COLORTYPE_CMYK;
    FX_FLOAT c = FX_atof((CFX_ByteString)syntax.GetWord());
    FX_FLOAT m = FX_atof((CFX_ByteString)syntax.GetWord());
    FX_FLOAT y = FX_atof((CFX_ByteString)syntax.GetWord());
    FX_FLOAT k = FX_atof((CFX_ByteString)syntax.GetWord());
    FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
    FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
    FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
    color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f),
                       (int)(b * 255 + 0.5f));
  }
}
Exemplo n.º 13
0
co_rc_t co_winnt_main(LPSTR szCmdLine) 
{
	co_rc_t rc;
	co_command_line_params_t cmdline;
	int argc = 0;
	char **args = NULL;

	rc = co_os_parse_args(szCmdLine, &argc, &args);
	if (!CO_OK(rc)) {
		co_terminal_print("daemon: error parsing arguments\n");
		syntax();
		return CO_RC(ERROR);
	}

	rc = co_cmdline_params_alloc(args, argc, &cmdline);
	if (!CO_OK(rc)) {
		co_terminal_print("daemon: error parsing arguments\n");
		co_os_free_parsed_args(args);
		return CO_RC(ERROR);
	}

	return CO_RC(OK);
}
MStatus AlembicPolyMeshToSubdivCommand::doIt(const MArgList& args)
{
	MStatus status;
	MArgParser argData(syntax(), args, &status);

	if (argData.isFlagSet("help"))
	{
		MGlobal::displayInfo("[ExocortexAlembic]: ExocortexAlembic_meshToSubdiv command:");
		MGlobal::displayInfo("                    -m : mesh to assign the initialShadingGroup on");
		return MS::kSuccess;
	}

	const MString mesh = argData.isFlagSet("mesh") ? ("\"" + argData.flagArgumentString("mesh", 0) + "\"") : "";

	MString result;
	MGlobal::executePythonCommand(("ExoAlembic._functions.alembicPolyMeshToSubdiv(" + mesh) + ")", result);
	if (result.length())
	{
		MPxCommand::setResult(result);
		return MS::kFailure;
	}
	return MS::kSuccess;
}
MStatus geometrySurfaceConstraintCommand::parseArgs(const MArgList &argList)
{
	MStatus			ReturnStatus;
	MArgDatabase	argData(syntax(), argList, &ReturnStatus);

	if ( ReturnStatus.error() )
		return MS::kFailure;

	// Settings only work at creation time. Would need an
	// attribute on the node in order to push this state
	// into the node at any time.
	ConstraintType typ;
	if (argData.isFlagSet(kConstrainToLargestWeightFlag))
		typ = geometrySurfaceConstraintCommand::kLargestWeight;
	else if (argData.isFlagSet(kConstrainToSmallestWeightFlag))
		typ = geometrySurfaceConstraintCommand::kSmallestWeight;
	else
		typ = geometrySurfaceConstraintCommand::kLargestWeight;
	weightType = typ;

	// Need parent to process
	return MS::kUnknownParameter;
}
Exemplo n.º 16
0
int
testcmd(shinstance *psh, int argc, char **argv)
{
	int res;

	if (strcmp(argv[0], "[") == 0) {
		if (strcmp(argv[--argc], "]"))
			error(psh, "missing ]");
		argv[argc] = NULL;
	}

	if (argc < 2)
		return 1;

	psh->t_wp_op = NULL;
	psh->t_wp = &argv[1];
	res = !oexpr(psh, t_lex(psh, *psh->t_wp));

	if (*psh->t_wp != NULL && *++psh->t_wp != NULL)
		syntax(psh, *psh->t_wp, "unexpected operator");

	return res;
}
MStatus AlembicAssignInitialSGCommand::doIt(const MArgList& args)
{
  MStatus status;
  MArgParser argData(syntax(), args, &status);

  if (argData.isFlagSet("help"))
  {
    MGlobal::displayInfo("[ExocortexAlembic]: ExocortexAlembic_assignFaceset command:");
    MGlobal::displayInfo("                    -m : mesh to assign the initialShadingGroup on");
    return MS::kSuccess;
  }

  if (!argData.isFlagSet("mesh"))
  {
    MGlobal::displayError("No mesh/subdiv specified!");
    return MS::kFailure;
  }

  MObject initShader;
  MDagPath dagPath;

  if (getObjectByName("initialShadingGroup", initShader) == MS::kSuccess && getDagPathByName(argData.flagArgumentString("mesh", 0), dagPath) == MS::kSuccess)
  {
    ESS_PROFILE_SCOPE("AlembicAssignInitialSGCommand::doIt::MFnSet");
    MFnSet set(initShader);
    set.addMember(dagPath);
  }
  else
  {
    MString theError("Error getting adding ");
    theError += argData.flagArgumentString("mesh", 0);
    theError += MString(" to initalShadingGroup.");
    MGlobal::displayError(theError);
    return MS::kFailure;
  }
  return MS::kSuccess;
}
MStatus RadiosityRenderer::prepareRenderView() {
	
	if (!MRenderView::doesRenderEditorExist())
	{
		setResult( "Cannot renderViewRender in batch render mode. "
				  "Please run in interactive mode, "
				  "so that the render editor exists." );
		return MS::kFailure;
	}
	else
	{
		printf("Past doesRenderEditorExist()");
	}
	
	// get optional flags
	MArgDatabase	argData( syntax(), args );
	parseSyntax( argData );
	
	M3dView curView = M3dView::active3dView();
	MDagPath camDagPath;
	curView.getCamera( camDagPath );
	printf("Rendering camera: %s", camDagPath.fullPathName().asChar());
	
	if( MRenderView::setCurrentCamera( camDagPath ) != MS::kSuccess )
	{
		setResult( "renderViewRender: error occurred in setCurrentCamera." );
		return MS::kFailure;
	}
	
	if (MRenderView::startRender( windowWidth, windowHeight, doNotClearBackground) != MS::kSuccess)
	{
		setResult( "renderViewRender: error occured in startRender." );
		return MS::kFailure;
	}
	
	return MS::kSuccess;
}
Exemplo n.º 19
0
/*
 * Read, parse, and execute a command line.
 */
static void
rpx_line(void)
{
	struct tnode *t;
	sigset_t nmask, omask;
	char *wp;

	linep = line;
	wordp = word;
	error_message = NULL;
	nul_count = 0;
	tree_count = 0;
	do {
		wp = linep;
		get_word();
	} while (*wp != EOL);
	*wordp = NULL;

	if (error_message != NULL) {
		err(SH_ERR, FMT1S, error_message);
		return;
	}

	if (wordp - word > 1) {
		(void)sigfillset(&nmask);
		(void)sigprocmask(SIG_SETMASK, &nmask, &omask);
		t = NULL;
		t = syntax(word, wordp);
		(void)sigprocmask(SIG_SETMASK, &omask, NULL);
		if (error_message != NULL)
			err(SH_ERR, FMT1S, error_message);
		else
			execute(t, NULL, NULL);
		tfree(t);
		t = NULL;
	}
}
Exemplo n.º 20
0
void func_read_mail(USER_DATA *usr, char *argument) {
	MAIL_DATA *pMail;
	char buf[STRING];
	BUFFER *buffer;
	int vnum = 1;
	int anum = 0;

	if (argument[0] == '\0' || !is_number(argument)) {
		syntax("[#Wre#x]ad <mail number>", usr);
		return;
	}

	anum = atoi(argument);
	buffer = new_buf();

	for (pMail = usr->pMailFirst; pMail; pMail = pMail->next) {
		if (pMail && (vnum++ == anum)) {
			time_t *last_read = &pMail->read_time;
			*last_read = UMAX(*last_read, pMail->stamp_time);

			sprintf(buf, "Reading message %d.\n\rDate: %s\n\rFrom: %s\n\r"
				"Subject: %s\n\r\n\r", vnum - 1, time_str(pMail->stamp_time),
					pMail->from, pMail->subject);
			add_buf(buffer, buf);
			add_buf(buffer, pMail->message);
			add_buf(buffer, "#x\n\r");
			page_to_user(buf_string(buffer), usr);
			free_buf(buffer);
			save_mail(usr);
			return;
		}
	}

	send_to_user("There aren't that many mail.\n\r", usr);
	return;
}
Exemplo n.º 21
0
static char *yes_no(char *arg, struct switch_s *s)
{
  int value = s->min;

  switch(arg[0]) {
  case '+':
    arg++;
    value = ON;
    break;
  case '-':
    arg++;
    value = OFF;
    break;
  case 'o':
  case 'O':
    switch(toupper(arg[1])) {
    case 'N':
      arg += 2;       /* ON */
      value = ON;
      break;
    case 'F':
      if (toupper(arg[2]) == 'F') {
        arg += 3;     /* OFF */
        value = OFF;
        break;
      }
    default:
      syntax("ON, OFF or nothing expected after /%s", s->sw);
    }
  }
  if (s->loc)
    *(int *)s->loc = value;
  defined_format |= s->ID;
  forced_format |= s->ID;
  return arg;
}
Exemplo n.º 22
0
int main (int argc, char *argv [])
{
    int
	argn,
	argmax,
	max,
	used,
	i,
	j,
	k,
	n;
    char
	*p;
    GROUP_
	*gr;

    no_mem_buffer = (char *) malloc (1024);

    get_programname (argv [0]);

    while (argc > 1 && argv [1][0] == '-') {
	if (! strcmp (argv [1], "-o")) {
	    argc--;
	    argv++;
	    outfile = argv [1];
	} else if (! strcmp (argv [1], "-l")) {
	    argc--;
	    argv++;
	    listfile = argv [1];
	}
	argc--;
	argv++;
    }

    if (argc < 2 && ! listfile)
	syntax ();

    if (listfile) {
	argc = 1;
	argmax = 256;
	p = argv [0];
	argv = (char **) s_malloc (argmax * sizeof (char *));
	argv [0] = p;
	fileopen (listfile);
	while (mygetline (FALSE)) {
	    if (argc == argmax) {
		argmax += 256;
		argv = (char **) s_realloc (argv, argmax * sizeof (char *));
	    }
	    argv [argc++] = s_strdup (buffer);
	}
    }
    
    fileopen (argv [1]);
    while (mygetline (FALSE)) {
	if (buffer [0] == 'l' || buffer [0] == 'L') {
	    if (n_lbls == max_lbls) {
		max_lbls += 256;
		lbls = (char **) s_realloc (lbls, max_lbls * sizeof (char *));
	    }
	    i = 1;
	    while (buffer [i] && isspace ((unsigned char) buffer [i]))
		i++;
	    lbls [n_lbls++] = s_strdup (buffer + i);
	}
    }
    fclose (fp);

    qsort (lbls, n_lbls, sizeof (char *), scmp);

    if (outfile) {
	fpout = fopen (outfile, "w");
	if (! fpout)
	    errit ("Creating file \"%s\": %s", outfile, strerror (errno));
    } else
	fpout = stdout;

    fprintf (fpout, "# Number of cluster files:\n%i\n# Number of labels:\n%i\n# Labels:\n", argc - 1, n_lbls);
    for (i = 0; i < n_lbls; i++)
	fprintf (fpout, "%s\n", lbls [i]);
    fprintf (fpout, "# Cluster count, cluster members, average cophenetic distance:\n");

    max = n_lbls - 1;
    cl = (CLUSTER_ *) s_malloc (max * sizeof (CLUSTER_));

    members = (char *) s_malloc ((n_lbls + 1) * sizeof (char));
    members [n_lbls] = '\0';

    for (argn = 1; argn < argc; argn++) {
	fileopen (argv [argn]);
	for (used = 0; used < max; used++) {
	    mygetline (TRUE);
	    if (sscanf (buffer, "%i %f%n", &(cl [used].index), &(cl [used].value), &i) < 2)
		errit ("Syntax error in \"%s\", line %i: \"%s\"", filename, inputline, buffer);
	    for (n = 0; n < 2; n++) {
		mygetline (TRUE);
		switch (buffer [0]) {
                    case 'l':
                    case 'L':
			cl [used].node [n] = LBL;
			i = 1;
			while (buffer [i] && isspace ((unsigned char) buffer [i]))
			    i++;
			p = bsearch (buffer + i, lbls, n_lbls, sizeof (char *), lscmp);
			if (! p)
			    errit ("Unknown label in \"%s\", line %i: \"%s\"", filename, inputline, buffer + i);
			cl [used].n [n].label = ((char **)p) - lbls;
			break;
                    case 'c':
                    case 'C':
			cl [used].node [n] = CLS;
			if (sscanf (buffer + 1, "%i", &(cl [used].n [n].cluster)) != 1)
			    errit ("Missing cluster number at line %i", inputline);
			break;
                    default:
			errit ("Syntax error at line %i: \"%s\"", inputline, buffer);
		}
	    }
	}

	/* replace indexes */
	for (i = 0; i < max; i++)
	    for (j = 0; j < 2; j++)
		if (cl [i].node [j] == CLS)
		    for (k = 0; k < max; k++)
			if (cl [i].n [j].cluster == cl [k].index) {
			    cl [i].n [j].cluster = k;
			    break;
			}

	for (i = 0; i < max; i++) {
	    for (j = 0; j < n_lbls; j++)
		members [j] = '-';
	    walk (i);

	    gr = findgroup ();
	    gr->n++;
	    gr->value += cl [i].value;

	}
	fclose (fp);
    }

    walkgroups (root);

    if (outfile)
	fclose (fpout);

    return 0;
}
Exemplo n.º 23
0
 /**
  * @brief Member function <b>parse</b> parses the expression.  If successful, the
  * parse status is set to true.
  *
  * @param expr		a <b>std::string</b> const reference to the
  *				expression to parse.
  *
  */
 inline void syntaxCheck(const std::string &expr) {
   setExpression(expr);
   syntax();
 }
Exemplo n.º 24
0
//-*****************************************************************************
MStatus AbcExport::doIt( const MArgList & args )
{
    MStatus status;

    MTime oldCurTime = MAnimControl::currentTime();

    MArgParser argData( syntax(), args, &status );
    if ( status != MS::kSuccess )
    {
        return status;
    }

    unsigned int numberOfArguments = args.length();

    MString msg;
    msg += "AlembicSimpleAbcExport  [options] OutputFileName.abc\n\n";
    msg += "Options:\n";
    
    msg += "-h  / help  Print this message.\n";
    msg += "\n";
    
    msg += "-fs / frameStart int (default: 0)\n";
    msg += "The export start frame\n";
    msg += "\n";
    
    msg += "-fe / frameEnd int (default: 0)\n";
    msg += "The export end frame\n";
    msg += "\n";
    
    msg += "-v  / verbose  Verbose output\n";
    msg += "\n";
    
    if ( argData.isFlagSet( "help" ) )
    {
        MGlobal::displayInfo( msg );
        return MS::kSuccess;
    }

    bool verbose = argData.isFlagSet( "verbose" );

    int frameStart = 0;
    if ( argData.isFlagSet( "frameStart" ) )
    {
        argData.getFlagArgument( "frameStart", 0, frameStart );
    }

    int frameEnd = 0;
    if ( argData.isFlagSet( "frameEnd" ) )
    {
        argData.getFlagArgument( "frameEnd", 0, frameEnd );
    }

    // status = argData.getCommandArgument(0, argStr);
    // Get filenameArgument
    MString fileNameStr = args.asString( numberOfArguments-1, &status );

    // Okay, do it.
    Parameters params;
    params.fileName = fileNameStr.asChar();
    params.startFrame = frameStart;
    params.endFrame = frameEnd;
    params.verbose = verbose;
    params.polysAsSubds = false;
    params.deforming = true;
    params.allUserAttributes = true;
    params.allMayaAttributes = false;

    try
    {
        status = AbcExportSelected( params );
    }
    catch ( std::exception &exc )
    {
        MGlobal::displayError( exc.what() );
        status = MS::kFailure;
    }
    catch ( ... )
    {
        MGlobal::displayError( "AlembicSimpleAbcExport: UNKNOWN EXCEPTION" );
        status = MS::kFailure;
    }
   
    return status;
}
Exemplo n.º 25
0
static int parse_parameter ( ctx_t *ctx_p, uint16_t param_id, char *arg, paramsource_t paramsource )
{
	int ret = 0;
#ifdef _DEBUG_FORCE
	fprintf ( stderr, "Force-Debug: parse_parameter(): %i: %i = \"%s\"\n", paramsource, param_id, arg );
#endif

	switch ( paramsource ) {
		case PS_CONTROL:
		case PS_ARGUMENT:
			if ( param_id & OPTION_CONFIGONLY ) {
				syntax();
				return 0;
			}

			ctx_p->flags_set[param_id] = 1;
			break;

		case PS_CONFIG:
			if ( ctx_p->flags_set[param_id] )
				return 0;

			ctx_p->flags_set[param_id] = 1;
			break;

		case PS_DEFAULTS:
#ifdef VERYPARANOID
			if ( ctx_p->flags_set[param_id] ) {
				error ( "Parameter #%i is already set. No need in setting the default value.", param_id );
				return 0;
			}

#endif
			break;

		/*		case PS_REHASH:
					arg = ctx_p->flags_values_raw[param_id];
		#ifdef VERYPARANOID
					critical_on (arg == NULL);
		#endif

					debug(9, "Rehash setting %i -> \"%s\"", param_id, arg);
					break;*/
		case PS_CORRECTION:
			critical_on ( arg == NULL );
			debug ( 9, "Correcting setting %i -> \"%s\"", param_id, arg );
			break;

		default:
			error ( "Unknown parameter #%i source (value \"%s\").", param_id, arg != NULL ? arg : "" );
			break;
	}

	if ( ( arg != NULL ) /*&& (paramsource != PS_REHASH)*/ ) {
		if ( param_id != KVM_ARGS )
			arg = parameter_expand ( ctx_p, arg, 0, NULL, NULL, parameter_get, ctx_p );

		if ( ctx_p->flags_values_raw[param_id] != NULL )
			free ( ctx_p->flags_values_raw[param_id] );

		ctx_p->flags_values_raw[param_id] = arg;
	}

	switch ( param_id ) {
		case '?':
		case HELP:
			syntax();
			break;

		case SHOW_VERSION:
			version();
			break;

		case CONFIG_FILE:
			ctx_p->config_path	= *arg ? arg : NULL;
			break;

		case CONFIG_GROUP:
			ctx_p->config_group	= *arg ? arg : NULL;
			break;

		case CONFIG_GROUP_INHERITS:
			break;

		case VMS_MIN:
			ctx_p->vms_min		= ( unsigned int ) xstrtol ( arg, &ret );
			break;

		case VMS_MAX:
			ctx_p->vms_max		= ( unsigned int ) xstrtol ( arg, &ret );
			break;

		case VMS_SPARE_MIN:
			ctx_p->vms_spare_min	= ( unsigned int ) xstrtol ( arg, &ret );
			break;

		case VMS_SPARE_MAX:
			ctx_p->vms_spare_max	= ( unsigned int ) xstrtol ( arg, &ret );
			break;

		case LISTEN:
			strncpy ( ctx_p->listen_addr, arg, sizeof ( ctx_p->listen_addr ) - 1 );
			break;

		default:
			if ( arg == NULL )
				ctx_p->flags[param_id]++;
			else
				ctx_p->flags[param_id] = xstrtol ( arg, &ret );

#ifdef _DEBUG_FORCE
			fprintf ( stderr, "Force-Debug: flag %i is set to %i\n", param_id & 0xff, ctx_p->flags[param_id] );
#endif
			break;
	}

	return ret;
}
Exemplo n.º 26
0
/*
 * Karl Kleinpaste, 21oct1983.
 * Set up a one-word alias command, for use for special things.
 * This code is based on the mainline of process().
 */
void
aliasrun(int cnt, Char *s1, Char *s2)
{
    struct wordent w, *new1, *new2;	/* for holding alias name */
    struct command *t = NULL;
    jmp_buf_t osetexit;
    int status;
    size_t omark;

    getexit(osetexit);
    if (seterr) {
	xfree(seterr);
	seterr = NULL;	/* don't repeatedly print err msg. */
    }
    w.word = STRNULL;
    new1 = xcalloc(1, sizeof w);
    new1->word = Strsave(s1);
    if (cnt == 1) {
	/* build a lex list with one word. */
	w.next = w.prev = new1;
	new1->next = new1->prev = &w;
    }
    else {
	/* build a lex list with two words. */
	new2 = xcalloc(1, sizeof w);
	new2->word = Strsave(s2);
	w.next = new2->prev = new1;
	new1->next = w.prev = new2;
	new1->prev = new2->next = &w;
    }
    cleanup_push(&w, lex_cleanup);

    /* Save the old status */
    status = getn(varval(STRstatus));

    /* expand aliases like process() does. */
    alias(&w);
    /* build a syntax tree for the command. */
    t = syntax(w.next, &w, 0);
    cleanup_push(t, syntax_cleanup);
    if (seterr)
	stderror(ERR_OLD);

    psavejob();
    cleanup_push(&cnt, psavejob_cleanup); /* cnt is used only as a marker */

    /* catch any errors here */
    omark = cleanup_push_mark();
    if (setexit() == 0)
	/* execute the parse tree. */
	/*
	 * From: Michael Schroeder <*****@*****.**>
	 * was execute(t, tpgrp);
	 */
	execute(t, tpgrp > 0 ? tpgrp : -1, NULL, NULL, TRUE);
    /* reset the error catcher to the old place */
    cleanup_pop_mark(omark);
    resexit(osetexit);
    if (haderr) {
	haderr = 0;
	/*
	 * Either precmd, or cwdcmd, or periodic had an error. Call it again so
	 * that it is removed
	 */
	if (precmd_active)
	    precmd();
	if (postcmd_active)
	    postcmd();
#ifdef notdef
	/*
	 * XXX: On the other hand, just interrupting them causes an error too.
	 * So if we hit ^C in the middle of cwdcmd or periodic the alias gets
	 * removed. We don't want that. Note that we want to remove precmd
	 * though, cause that could lead into an infinite loop. This should be
	 * fixed correctly, but then haderr should give us the whole exit
	 * status not just true or false.
	 */
	else if (cwdcmd_active)
	    cwd_cmd();
	else if (beepcmd_active)
	    beep_cmd();
	else if (periodic_active)
	    period_cmd();
#endif /* notdef */
    }
    cleanup_until(&w);
    pendjob();
    /* Restore status */
    setv(STRstatus, putn((tcsh_number_t)status), VAR_READWRITE);
}
Exemplo n.º 27
0
/*ARGSUSED*/
void
dolist(Char **v, struct command *c)
{
    Char **globbed;
    int     i, k, ret = 0;
    struct stat st;

    USE(c);
    if (*++v == NULL) {
	struct Strbuf word = Strbuf_INIT;

	Strbuf_terminate(&word);
	cleanup_push(&word, Strbuf_cleanup);
	(void) t_search(&word, LIST, TW_ZERO, 0, STRNULL, 0);
	cleanup_until(&word);
	return;
    }
    v = glob_all_or_error(v);
    globbed = v;
    cleanup_push(globbed, blk_cleanup);
    for (k = 0; v[k] != NULL && v[k][0] != '-'; k++)
	continue;
    if (v[k]) {
	/*
	 * We cannot process a flag therefore we let ls do it right.
	 */
	Char *lspath;
	struct command *t;
	struct wordent cmd, *nextword, *lastword;
	Char   *cp;
	struct varent *vp;

	if (setintr) {
	    pintr_disabled++;
	    cleanup_push(&pintr_disabled, disabled_cleanup);
	}
	if (seterr) {
	    xfree(seterr);
	    seterr = NULL;
	}

	lspath = STRls;
	STRmCF[1] = 'C';
	STRmCF[3] = '\0';
	/* Look at listflags, to add -A to the flags, to get a path
	   of ls if necessary */
	if ((vp = adrof(STRlistflags)) != NULL && vp->vec != NULL &&
	    vp->vec[0] != STRNULL) {
	    if (vp->vec[1] != NULL && vp->vec[1][0] != '\0')
		lspath = vp->vec[1];
	    for (cp = vp->vec[0]; *cp; cp++)
		switch (*cp) {
		case 'x':
		    STRmCF[1] = 'x';
		    break;
		case 'a':
		    STRmCF[3] = 'a';
		    break;
		case 'A':
		    STRmCF[3] = 'A';
		    break;
		default:
		    break;
		}
	}

	cmd.word = STRNULL;
	lastword = &cmd;
	nextword = xcalloc(1, sizeof cmd);
	nextword->word = Strsave(lspath);
	lastword->next = nextword;
	nextword->prev = lastword;
	lastword = nextword;
	nextword = xcalloc(1, sizeof cmd);
	nextword->word = Strsave(STRmCF);
	lastword->next = nextword;
	nextword->prev = lastword;
#if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
	if (dspmbyte_ls) {
	    lastword = nextword;
	    nextword = xcalloc(1, sizeof cmd);
	    nextword->word = Strsave(STRmmliteral);
	    lastword->next = nextword;
	    nextword->prev = lastword;
	}
#endif
#ifdef COLOR_LS_F
	if (color_context_ls) {
	    lastword = nextword;
	    nextword = xcalloc(1, sizeof cmd);
	    nextword->word = Strsave(STRmmcolormauto);
	    lastword->next = nextword;
	    nextword->prev = lastword;
	}
#endif /* COLOR_LS_F */
	lastword = nextword;
	for (cp = *v; cp; cp = *++v) {
	    nextword = xcalloc(1, sizeof cmd);
	    nextword->word = quote(Strsave(cp));
	    lastword->next = nextword;
	    nextword->prev = lastword;
	    lastword = nextword;
	}
	lastword->next = &cmd;
	cmd.prev = lastword;
	cleanup_push(&cmd, lex_cleanup);

	/* build a syntax tree for the command. */
	t = syntax(cmd.next, &cmd, 0);
	cleanup_push(t, syntax_cleanup);
	if (seterr)
	    stderror(ERR_OLD);
	/* expand aliases like process() does */
	/* alias(&cmd); */
	/* execute the parse tree. */
	execute(t, tpgrp > 0 ? tpgrp : -1, NULL, NULL, FALSE);
	/* done. free the lex list and parse tree. */
	cleanup_until(&cmd);
	if (setintr)
	    cleanup_until(&pintr_disabled);
    }
    else {
	Char   *dp, *tmp;
	struct Strbuf buf = Strbuf_INIT;

	cleanup_push(&buf, Strbuf_cleanup);
	for (k = 0, i = 0; v[k] != NULL; k++) {
	    tmp = dnormalize(v[k], symlinks == SYM_IGNORE);
	    cleanup_push(tmp, xfree);
	    dp = Strend(tmp) - 1;
	    if (*dp == '/' && dp != tmp)
#ifdef apollo
		if (dp != &tmp[1])
#endif /* apollo */
		*dp = '\0';
	    if (stat(short2str(tmp), &st) == -1) {
		int err;

		err = errno;
		if (k != i) {
		    if (i != 0)
			xputchar('\n');
		    print_by_column(STRNULL, &v[i], k - i, FALSE);
		}
		haderr = 1;
		xprintf("%S: %s.\n", tmp, strerror(err));
		haderr = 0;
		i = k + 1;
		ret = 1;
	    }
	    else if (S_ISDIR(st.st_mode)) {
		Char   *cp;

		if (k != i) {
		    if (i != 0)
			xputchar('\n');
		    print_by_column(STRNULL, &v[i], k - i, FALSE);
		}
		if (k != 0 && v[1] != NULL)
		    xputchar('\n');
		xprintf("%S:\n", tmp);
		buf.len = 0;
		for (cp = tmp; *cp; cp++)
		    Strbuf_append1(&buf, (*cp | QUOTE));
		Strbuf_terminate(&buf);
		dp = &buf.s[buf.len - 1];
		if (
#ifdef WINNT_NATIVE
		    (*dp != (Char) (':' | QUOTE)) &&
#endif /* WINNT_NATIVE */
		    (*dp != (Char) ('/' | QUOTE))) {
		    Strbuf_append1(&buf, '/');
		    Strbuf_terminate(&buf);
		} else 
		    *dp &= TRIM;
		(void) t_search(&buf, LIST, TW_ZERO, 0, STRNULL, 0);
		i = k + 1;
	    }
	    cleanup_until(tmp);
	}
	cleanup_until(&buf);
	if (k != i) {
	    if (i != 0)
		xputchar('\n');
	    print_by_column(STRNULL, &v[i], k - i, FALSE);
	}
	if (ret)
	    stderror(ERR_SILENT);
    }

    cleanup_until(globbed);
}
Exemplo n.º 28
0
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
char           *pgmname;                /* prog name in host format  */
char           *pgm;                    /* less any extension (.ext) */
char            msgbuf[512];            /* message build work area   */
int             cckd_diag_rc = 0;       /* Program return code       */
char           *fn;                     /* File name                 */

CKDDASD_DEVHDR  devhdr;                 /* [C]CKD device hdr         */
CCKDDASD_DEVHDR cdevhdr;                /* Compressed CKD device hdr */
CKDDEV         *ckd=0;                  /* CKD DASD table entry      */
FBADEV         *fba=0;                  /* FBA DASD table entry      */

int             cmd_devhdr = 0;         /* display DEVHDR            */
int             cmd_cdevhdr = 0;        /* display CDEVHDR           */
int             cmd_l1tab = 0;          /* display L1TAB             */
int             cmd_l2tab = 0;          /* display L2TAB             */
int             cmd_trkdata = 0;        /* display track data        */
int             cmd_hexdump = 0;        /* display track data (hex)  */

int             cmd_offset = 0;         /* 1 = display data at       */
int             op_offset = 0;          /* op_offset of length       */
int             op_length = 0;          /* op_length                 */

int             cmd_cchh = 0;           /* 1 = display CCHH data     */
int             op_cc = 0;              /* CC = cylinder             */
int             op_hh = 0;              /* HH = head                 */

int             cmd_tt = 0;             /* 1 = display TT data       */
int             op_tt = 0;              /* relative track #          */

int             swapend;                /* 1 = New endianess doesn't
                                             match machine endianess */
int             n, trk=0, l1ndx=0, l2ndx=0;
off_t           l2taboff=0;             /* offset to assoc. L2 table */
int             ckddasd;                /* 1=CKD dasd  0=FBA dasd    */
int             heads=0;                /* Heads per cylinder        */
off_t           trkhdroff=0;            /* offset to assoc. trk hdr  */
int             imglen=0;               /* track length              */
char            pathname[MAX_PATH];     /* file path in host format  */
char           *strtok_str = NULL;

    /* Set program name */
    if ( argc > 0 )
    {
        if ( strlen(argv[0]) == 0 )
        {
            pgmname = strdup( UTILITY_NAME );
        }
        else
        {
            char path[MAX_PATH];
#if defined( _MSVC_ )
            GetModuleFileName( NULL, path, MAX_PATH );
#else
            strncpy( path, argv[0], sizeof( path ) );
#endif
            pgmname = strdup(basename(path));
#if !defined( _MSVC_ )
            strncpy( path, argv[0], sizeof(path) );
#endif
        }
    }
    else
    {
        pgmname = strdup( UTILITY_NAME );
    }

    pgm = strtok_r( strdup(pgmname), ".", &strtok_str);
    INITIALIZE_UTILITY( pgmname );

    /* Display the program identification message */
    MSGBUF( msgbuf, MSG_C( HHC02499, "I", pgm, "CCKD diagnostic program" ) );
    display_version (stderr, msgbuf+10, FALSE);

    /* parse the arguments */
    argc--;
    argv++ ;
    while (argc > 0) {
        if(**argv != '-') break;

        switch(argv[0][1]) {
            case 'v':  if (argv[0][2] != '\0') return syntax (pgm);
                       return 0;
            case 'd':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_devhdr = 1;
                       break;
            case 'c':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_cdevhdr = 1;
                       break;
            case '1':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_l1tab = 1;
                       break;
            case '2':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_l2tab = 1;
                       break;
            case 'a':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_cchh = 1;
                       argc--; argv++;
                       op_cc = offtify(*argv);
                       argc--; argv++;
                       op_hh = offtify(*argv);
                       break;
            case 'r':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_tt = 1;
                       argc--; argv++;
                       op_tt = offtify(*argv);
                       break;
            case 'o':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_offset = 1;
                       argc--;
                       argv++;
                       op_offset = offtify(*argv);
                       argc--;
                       argv++;
                       op_length = offtify(*argv);
                       break;
            case 't':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_trkdata = 1;
                       break;
            case 'x':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_hexdump = 1;
                       cmd_trkdata = 1;
                       break;
            case 'g':  if (argv[0][2] != '\0') return syntax (pgm);
                       debug = 1;
                       break;
            default:   return syntax (pgm);
        }
        argc--;
        argv++;
    }
    if (argc != 1) return syntax (pgm);
    fn = argv[0];

    /* open the file */
    hostpath(pathname, fn, sizeof(pathname));
    fd = HOPEN(pathname, O_RDONLY | O_BINARY);
    if (fd < 0) {
        fprintf(stderr,
                _("cckddiag: error opening file %s: %s\n"),
                fn, strerror(errno));
        return -1;
    }

    /*---------------------------------------------------------------*/
    /* display DEVHDR - first 512 bytes of dasd image                */
    /*---------------------------------------------------------------*/
    readpos(fd, &devhdr, 0, sizeof(devhdr));
    if (cmd_devhdr) {
        fprintf(stderr, "\nDEVHDR - %d (decimal) bytes:\n",
                (int)sizeof(devhdr));
        data_dump(&devhdr, sizeof(devhdr));
    }

    /*---------------------------------------------------------------*/
    /* Determine CKD or FBA device type                              */
    /*---------------------------------------------------------------*/
    if (memcmp(devhdr.devid, "CKD_C370", 8) == 0
       || memcmp(devhdr.devid, "CKD_S370", 8) == 0) {
        ckddasd = 1;
        ckd = dasd_lookup(DASD_CKDDEV, NULL, devhdr.devtype, 0);
        if (ckd == NULL) {
            fprintf(stderr,
                    "DASD table entry not found for devtype 0x%2.2X\n",
                    devhdr.devtype);
            clean();
            exit(5);
        }
    }
    else
        if (memcmp(devhdr.devid, "FBA_C370", 8) == 0
           || memcmp(devhdr.devid, "FBA_S370", 8) == 0) {
        ckddasd = 0;
        fba = dasd_lookup(DASD_FBADEV, NULL, devhdr.devtype, 0);
        if (fba == NULL) {
            fprintf(stderr,
                    "DASD table entry not found for "
                    "devtype 0x%2.2X\n",
                    DEFAULT_FBA_TYPE);
            clean();
            exit(6);
        }
    }
    else {
        fprintf(stderr, "incorrect header id\n");
        clean();
        return -1;
    }

    /*---------------------------------------------------------------*/
    /* Set up device characteristics                                 */
    /*---------------------------------------------------------------*/
    if (ckddasd) {
        heads = ((U32)(devhdr.heads[3]) << 24)
              | ((U32)(devhdr.heads[2]) << 16)
              | ((U32)(devhdr.heads[1]) << 8)
              | (U32)(devhdr.heads[0]);
        if (debug)
            fprintf(stderr,
                "\nHHC90000D DBG: %s device has %d heads/cylinder\n",
                ckd->name, heads);
    } 


    /*---------------------------------------------------------------*/
    /* display CDEVHDR - follows DEVHDR                              */
    /*---------------------------------------------------------------*/
    readpos(fd, &cdevhdr, CKDDASD_DEVHDR_SIZE, sizeof(cdevhdr));
    if (cmd_cdevhdr) {
        fprintf(stderr, "\nCDEVHDR - %d (decimal) bytes:\n",
                (int)sizeof(cdevhdr));
        data_dump(&cdevhdr, sizeof(cdevhdr));
    }

    /*---------------------------------------------------------------*/
    /* Find machine endian-ness                                      */
    /*---------------------------------------------------------------*/
    /* cckd_endian() returns 1 for big-endian machines               */
    swapend = (cckd_endian() !=
               ((cdevhdr.options & CCKD_BIGENDIAN) != 0));

    /*---------------------------------------------------------------*/
    /* display L1TAB - follows CDEVHDR                               */
    /*---------------------------------------------------------------*/
    /* swap numl1tab if needed */
    n = cdevhdr.numl1tab;
    if (swapend) cckd_swapend4((char *)&n);

    l1 = makbuf(n * CCKD_L1ENT_SIZE, "L1TAB");
    readpos(fd, l1, CCKD_L1TAB_POS, n * CCKD_L1ENT_SIZE);
    /* L1TAB itself is not adjusted for endian-ness                  */
    if (cmd_l1tab) {
        fprintf(stderr, "\nL1TAB - %d (0x%X) bytes:\n",
                (int)(n * CCKD_L1ENT_SIZE), (unsigned int)(n * CCKD_L1ENT_SIZE));
        data_dump(l1, n * CCKD_L1ENT_SIZE);
    }

    /*---------------------------------------------------------------*/
    /* display OFFSET, LENGTH data                                   */
    /*---------------------------------------------------------------*/
    if (cmd_offset) {
        bulk = makbuf(op_length, "BULK");
        readpos(fd, bulk, op_offset, op_length);
        fprintf(stderr,
            "\nIMAGE OFFSET %d (0x%8.8X) "
            "of length %d (0x%8.8X) bytes:\n",
            op_offset, op_offset, op_length, op_length);
        data_dump(bulk, op_length);
        free(bulk);
        bulk = NULL;
    }

    /*---------------------------------------------------------------*/
    /* FBA isn't supported here because I don't know much about FBA  */
    /*---------------------------------------------------------------*/
    if ( (!ckddasd) && ((cmd_cchh) || (cmd_tt)) ) {
        fprintf(stderr, "CCHH/reltrk not supported for FBA\n");
        clean();
        exit(3);
    }

    /*---------------------------------------------------------------*/
    /* Setup CCHH or relative track request                          */
    /*---------------------------------------------------------------*/
    if (ckddasd) {
        if (cmd_tt) {
            trk = op_tt;
            op_cc = trk / heads;
            op_hh = trk % heads;
        } else {
            trk = (op_cc * heads) + op_hh;
        }
        l1ndx = trk / cdevhdr.numl2tab;
        l2ndx = trk % cdevhdr.numl2tab;
        l2taboff = l1[l1ndx];
        if (swapend) cckd_swapend4((char *)&l2taboff);
    }

    /*---------------------------------------------------------------*/
    /* display CKD CCHH or relative track data                       */
    /*---------------------------------------------------------------*/
    if ((cmd_cchh) || (cmd_tt)) {
        fprintf(stderr,
                "CC %d HH %d = reltrk %d; "
                "L1 index = %d, L2 index = %d\n"
                "L1 index %d = L2TAB offset %d (0x%8.8X)\n",
                op_cc, op_hh, trk,
                l1ndx, l2ndx,
                l1ndx, (int)l2taboff, (int)l2taboff);
        l2 = makbuf(cdevhdr.numl2tab * sizeof(CCKD_L2ENT), "L2TAB");
        readpos(fd, l2, l2taboff,
                cdevhdr.numl2tab * sizeof(CCKD_L2ENT));
        if (cmd_l2tab) {
            fprintf(stderr,
                   "\nL2TAB - %d (decimal) bytes\n",
                   (int)(cdevhdr.numl2tab * sizeof(CCKD_L2ENT)));
            data_dump(l2, (cdevhdr.numl2tab * sizeof(CCKD_L2ENT)) );
        }
        fprintf(stderr, "\nL2 index %d = L2TAB entry %d bytes\n",
               l2ndx, (int)sizeof(CCKD_L2ENT) );
        data_dump(&l2[l2ndx], sizeof(CCKD_L2ENT) );
        trkhdroff = l2[l2ndx].pos;
        imglen = l2[l2ndx].len;
        if (swapend) {
            cckd_swapend4((char *)&trkhdroff);
            cckd_swapend4((char *)&imglen);
        }
        fprintf(stderr, "\nTRKHDR offset %d (0x%8.8X); "
                "length %d (0x%4.4X)\n",
                (int)trkhdroff, (int)trkhdroff, imglen, imglen);
        tbuf = makbuf(imglen, "TRKHDR+DATA");
        readpos(fd, tbuf, trkhdroff, imglen);
        fprintf(stderr, "\nTRKHDR track %d\n", trk);
        data_dump(tbuf, sizeof(CKDDASD_TRKHDR) );
        if (cmd_trkdata) showtrk(tbuf, imglen, trk, cmd_hexdump);
        free(l2); free(tbuf);
        l2 = NULL; tbuf = NULL;
    }

    /* Close file, exit */
    fprintf(stderr, "\n");
    clean();
    return cckd_diag_rc;
}
Exemplo n.º 29
0
MStatus AbcImport::doIt(const MArgList & args)
{
    MStatus status;

    MArgParser argData(syntax(), args, &status);

    MString filename("");
    MString connectRootNodes("");
    MString filterString("");
    MString excludeFilterString("");

    MObject reparentObj = MObject::kNullObj;

    bool    swap = false;
    bool    createIfNotFound = false;
    bool    removeIfNoUpdate = false;

    bool    debugOn = false;

    if (argData.isFlagSet("help"))
    {
        MGlobal::displayInfo(usage);
        return status;
    }

    if (argData.isFlagSet("debug"))
        debugOn = true;

    if (argData.isFlagSet("reparent"))
    {
        MString parent("");
        MDagPath reparentDagPath;
        status = argData.getFlagArgument("reparent", 0, parent);
        if (status == MS::kSuccess
            && getDagPathByName(parent, reparentDagPath) == MS::kSuccess)
        {
            reparentObj = reparentDagPath.node();
        }
        else
        {
            MString theWarning = parent;
            theWarning += MString(" is not a valid DagPath");
            printWarning(theWarning);
        }
    }

    if (!argData.isFlagSet("connect") && argData.isFlagSet("mode"))
    {
        MString modeStr;
        argData.getFlagArgument("mode", 0, modeStr);
        if (modeStr == "replace")
            deleteCurrentSelection();
        else if (modeStr == "open")
        {
            MFileIO fileIo;
            fileIo.newFile(true);
        }
    }
    else if (argData.isFlagSet("connect"))
    {
        swap = true;
        argData.getFlagArgument("connect", 0, connectRootNodes);

        if (argData.isFlagSet("createIfNotFound"))
        {
            createIfNotFound = true;
        }

        if (argData.isFlagSet("removeIfNoUpdate"))
            removeIfNoUpdate = true;
    }

    if (argData.isFlagSet("filterObjects"))
    {
        argData.getFlagArgument("filterObjects", 0, filterString);
    }

    if (argData.isFlagSet("excludeFilterObjects"))
    {
        argData.getFlagArgument("excludeFilterObjects", 0, excludeFilterString);
    }

    // if the flag isn't specified we'll only do stuff marked with the Maya
    // meta data
    bool recreateColorSets = false;
    if (argData.isFlagSet("recreateAllColorSets"))
    {
        recreateColorSets = true;
    }

    status = argData.getCommandArgument(0, filename);
    MString abcNodeName;
    if (status == MS::kSuccess)
    {
        {
            MString fileRule, expandName;
            MString alembicFileRule = "alembicCache";
            MString alembicFilePath = "cache/alembic";

            MString queryFileRuleCmd;
            queryFileRuleCmd.format("workspace -q -fre \"^1s\"",
                alembicFileRule);
            MString queryFolderCmd;
            queryFolderCmd.format("workspace -en `workspace -q -fre \"^1s\"`",
                alembicFileRule);

            // query the file rule for alembic cache
            MGlobal::executeCommand(queryFileRuleCmd, fileRule);
            if (fileRule.length() > 0)
            {
                // we have alembic file rule, query the folder
                MGlobal::executeCommand(queryFolderCmd, expandName);
            }

            // resolve the expanded file rule
            if (expandName.length() == 0)
            {
                expandName = alembicFilePath;
            }

            // get the path to the alembic file rule
            MFileObject directory;
            directory.setRawFullName(expandName);
            MString directoryName = directory.resolvedFullName();

            // resolve the relative path
            MFileObject absoluteFile;
            absoluteFile.setRawFullName(filename);
			absoluteFile.setResolveMethod(MFileObject::kInputFile);
#if MAYA_API_VERSION < 201300
            if (absoluteFile.resolvedFullName() !=
                absoluteFile.expandedFullName())
            {
#else
            if (!MFileObject::isAbsolutePath(filename)) {
#endif
                // this is a relative path
                MString absoluteFileName = directoryName + "/" + filename;
                absoluteFile.setRawFullName(absoluteFileName);
                filename = absoluteFile.resolvedFullName();
            }
            else
            {
                filename = absoluteFile.resolvedFullName();
            }
        }

        MFileObject fileObj;
        status = fileObj.setRawFullName(filename);
        if (status == MS::kSuccess && fileObj.exists())
        {
            ArgData inputData(filename, debugOn, reparentObj,
                swap, connectRootNodes, createIfNotFound, removeIfNoUpdate,
                recreateColorSets, filterString, excludeFilterString);
            abcNodeName = createScene(inputData);

            if (inputData.mSequenceStartTime != inputData.mSequenceEndTime &&
                inputData.mSequenceStartTime != -DBL_MAX &&
                inputData.mSequenceEndTime != DBL_MAX)
            {
                if (argData.isFlagSet("fitTimeRange"))
                {
                    MTime sec(1.0, MTime::kSeconds);
                    setPlayback(
                        inputData.mSequenceStartTime * sec.as(MTime::uiUnit()),
                        inputData.mSequenceEndTime * sec.as(MTime::uiUnit()) );
                }

                if (argData.isFlagSet("setToStartFrame"))
                {
                    MTime sec(1.0, MTime::kSeconds);
                    MGlobal::viewFrame( inputData.mSequenceStartTime *
                        sec.as(MTime::uiUnit()) );
                }
            }
        }
        else
        {
            MString theError("In AbcImport::doIt(), ");
            theError += filename;
            theError += MString(" doesn't exist");
            printError(theError);
        }
    }

    MPxCommand::setResult(abcNodeName);

    return status;
}
Exemplo n.º 30
0
MStatus PTCMapCmd::doIt( const MArgList& args)
{
    MStatus status = parseArgs( args );

    if( status != MS::kSuccess ) return status;

    MArgDatabase argData(syntax(), args);

    MAnimControl timeControl;
    MTime time = timeControl.currentTime();
    int frame =int(time.value());
    MString proj;
    MGlobal::executeCommand( MString ("string $p = `workspace -q -fn`"), proj );

    MString cache_path = proj + "/data";
    MString cache_name = "foo";
    MString cache_attrib;
    double cache_mindist = 0.1;
    int max_level = 3;
    double root_size = 32;
    MString dem_trans = "nil";
    double cloud_os = 0.05;
    MString key_trans = "nil";
    MString eye_trans = "nil";

    if (argData.isFlagSet("-p")) argData.getFlagArgument("-p", 0, cache_path);
    if (argData.isFlagSet("-n")) argData.getFlagArgument("-n", 0, cache_name);
    if (argData.isFlagSet("-a")) argData.getFlagArgument("-a", 0, cache_attrib);
    if (argData.isFlagSet("-mnd")) argData.getFlagArgument("-mnd", 0, cache_mindist);
    if (argData.isFlagSet("-ml")) argData.getFlagArgument("-ml", 0, max_level);
    if (argData.isFlagSet("-rs")) argData.getFlagArgument("-rs", 0, root_size);
    if (argData.isFlagSet("-t")) argData.getFlagArgument("-t", 0, dem_trans);
    if(argData.isFlagSet("-o")) argData.getFlagArgument("-o", 0, cloud_os);
    if(argData.isFlagSet("-tk")) argData.getFlagArgument("-tk", 0, key_trans);
    if(argData.isFlagSet("-te")) argData.getFlagArgument("-te", 0, eye_trans);

    float def_area = root_size;
    int last = 0;
    while(last < max_level-2) {
        def_area /= 2;
        last++;
    }

    def_area = 1.0f;

    //def_area *= def_area;

// get bounding box center
    MDagPath p_bbox;

    zWorks::getTypedPathByName(MFn::kTransform, dem_trans, p_bbox);
    MObject o_bbox = p_bbox.transform();

    float m_space[4][4];
    m_space[0][0]=1;
    m_space[0][1]=0;
    m_space[0][2]=0;
    m_space[1][0]=0;
    m_space[1][1]=1;
    m_space[1][2]=0;
    m_space[2][0]=0;
    m_space[2][1]=0;
    m_space[2][2]=1;
    m_space[3][0]=0;
    m_space[3][1]=0;
    m_space[3][2]=0;

    if(o_bbox.isNull()) MGlobal::displayWarning("Cannot find pmap dimension, use default space.");
    else zWorks::getTransformWorldNoScale(p_bbox.partialPathName(), m_space);

    XYZ root_center(m_space[3][0], m_space[3][1], m_space[3][2]);

// get key light dir
    MDagPath p_key;

    zWorks::getTypedPathByName(MFn::kTransform, key_trans, p_key);
    MObject o_key = p_key.transform();

    m_space[0][0]=1;
    m_space[0][1]=0;
    m_space[0][2]=0;
    m_space[1][0]=0;
    m_space[1][1]=1;
    m_space[1][2]=0;
    m_space[2][0]=0;
    m_space[2][1]=0;
    m_space[2][2]=1;
    m_space[3][0]=0;
    m_space[3][1]=0;
    m_space[3][2]=0;

    if(o_key.isNull()) MGlobal::displayWarning("Cannot find key camera, use default space.");
    else zWorks::getTransformWorldNoScale(p_key.partialPathName(), m_space);

    XYZ key_dir(m_space[2][0], m_space[2][1], m_space[2][2]);
    key_dir.normalize();

// get view dir
    MDagPath p_eye;

    zWorks::getTypedPathByName(MFn::kTransform, eye_trans, p_eye);
    MObject o_eye = p_eye.transform();

    m_space[0][0]=1;
    m_space[0][1]=0;
    m_space[0][2]=0;
    m_space[1][0]=0;
    m_space[1][1]=1;
    m_space[1][2]=0;
    m_space[2][0]=0;
    m_space[2][1]=0;
    m_space[2][2]=1;
    m_space[3][0]=0;
    m_space[3][1]=0;
    m_space[3][2]=0;

    if(o_eye.isNull()) MGlobal::displayWarning("Cannot find render camera, use default space.");
    else zWorks::getTransformWorldNoScale(p_eye.partialPathName(), m_space);

    XYZ view_dir(-m_space[2][0], -m_space[2][1], -m_space[2][2]);
    view_dir.normalize();

// additional attribs
    MStringArray attribArray;
    cache_attrib.split('.', attribArray);

    MSelectionList slist;
    MGlobal::getActiveSelectionList( slist );
    MItSelectionList list( slist, MFn::kParticle, &status );
    if (MS::kSuccess != status) {
        displayError( "Could not create selection list iterator");
        return status;
    }

    if (list.isDone()) {
        displayError( "No particles selected" );
        return MS::kSuccess;
    }

    MDagPath fDagPath;
    MObject component;
    unsigned npt = 0,acc = 0;
    for(; !list.isDone(); list.next()) {
        list.getDagPath (fDagPath, component);
        MFnParticleSystem ps( fDagPath );
        npt += ps.count();
    }

    if(npt < 1) {
        MGlobal::displayInfo(" zero particle: do nothing ");
        return MS::kSuccess;
    }

    std::list<AParticle *> particles;

    RGRID *buf = new RGRID[npt];
    unsigned *idxb = new unsigned[npt];
    float *opab = new float[npt];
    float *ageb = new float[npt];

    list.reset();
    for(; !list.isDone(); list.next()) {
        list.getDagPath (fDagPath, component);
        MFnParticleSystem ps( fDagPath );

        MVectorArray positions;
        ps.position( positions );

        MVectorArray velarr;
        ps.velocity( velarr );

        MIntArray ids;
        ps.particleIds(ids);

        MVectorArray cols;
        ps.rgb(cols);

        MDoubleArray opas;
        ps.opacity(opas);

        MDoubleArray ages;
        ps.opacity(ages);

        for(unsigned i=0; i<positions.length(); i++,acc++ ) {
            buf[acc].pos.x = positions[i].x;
            buf[acc].pos.y = positions[i].y;
            buf[acc].pos.z = positions[i].z;
            buf[acc].nor.x = velarr[i].x;
            buf[acc].nor.y = velarr[i].y;
            buf[acc].nor.z = velarr[i].z;
            buf[acc].area = def_area;

            if(ps.hasRgb()) {
                buf[acc].col.x = cols[i].x;
                buf[acc].col.y = cols[i].y;
                buf[acc].col.z = cols[i].z;
            }
            else buf[acc].col = XYZ(1,1,1);

            idxb[acc] = ids[i];

            if(ps.hasOpacity ()) opab[acc] = opas[i];
            else opab[acc] = 1.f;

            ageb[acc] = ages[i];

            AParticle *pt = new AParticle();
            pt->pos.x = positions[i].x;
            pt->pos.y = positions[i].y;
            pt->pos.z = positions[i].z;
            pt->r = def_area;

            particles.push_back(pt);
        }
    }
    /*
    	Z3DTexture* tree = new Z3DTexture();
    	tree->setGrid(buf, npt);
    	tree->constructTree(root_center, root_size, max_level);
    	tree->setGridIdData(idxb, npt);
    	tree->setGridOpacityData(opab, npt);
    	tree->setGridAgeData(ageb, npt);
    	MGlobal::displayInfo(MString(" num grid ")+ tree->getNumGrid());
    	MGlobal::displayInfo(MString(" num voxel ")+ tree->getNumVoxel());
    	MGlobal::displayInfo(MString(" num leaf ")+ tree->getNumLeaf());
    	MGlobal::displayInfo(MString(" max level ")+ tree->getMaxLevel());
    	MGlobal::displayInfo(" calculating voxel volume occlusion...");
    	tree->occlusionVolume(cloud_os, key_dir, view_dir);
    	MGlobal::displayInfo(" done");
    	MGlobal::displayInfo(" updating grid distance to neighbour...");
    	tree->distanceToNeighbour(cache_mindist);
    	MGlobal::displayInfo(" done");

    	char filename[512];
    	sprintf( filename, "%s/%s.%d.pmap", cache_path.asChar(), cache_name.asChar(), frame );
    	MGlobal::displayInfo(MString("PTCMap saved ") + filename);
    	tree->save(filename);

    	delete tree;
    	*/
    if(!particles.empty()) {
        GPUOctree *data = new GPUOctree();
        data->create(root_center, root_size, 8, particles);
        MGlobal::displayInfo(MString(" num voxel ")+ data->getNumVoxel()+ MString(" minvar ")+ data->getMinVariation()+ MString(" max level ")+ data->getMaxLevel()+ MString(" filter size ")+ def_area);

        char filename[512];
        sprintf( filename, "%s/%s.%d", cache_path.asChar(), cache_name.asChar(), frame );

        data->dumpIndirection(filename);

        delete data;
        particles.clear();
    }

    return MS::kSuccess;
}