示例#1
0
main( int argc, char *argv[] ) {
    Stack myStack;
    initStack( &myStack);
    int flag = 0;
    int numRead, sumRead;
    char stdCh, temp, *line, *lntemp, *errStr;
    char openSet[5] = "<{[(";
    line = (char*)malloc( sizeof(char)*MAXLINELEN);
    errStr = (char*)malloc( sizeof(char)*MAXERRLEN);

    if( argc >= 2 && argv[1][1] == 'd')
        flag = 1; // set the debug mode

    while( fgets( line, 300, stdin) != NULL) {
        lntemp = line; // used to advance scanf
        sumRead = 0; // used to print to err message, if needed
        while( 0 < sscanf( lntemp, "%c%n", &stdCh, &numRead) ) {
            lntemp += numRead;
            sumRead += numRead;
            if( stdCh == 'q') // quit
                return 0;
            else if( strchr( openSet, stdCh) != NULL) // open brack
                push( &myStack, stdCh, flag);
            else if( strchr( openSet, invBrack(stdCh) ) != NULL) { // close brack
                if( isEmpty( myStack) ) {
                    sprintf( errStr, "%*c:Missing Here", sumRead, invBrack( stdCh) );
                    break; //exit (parse line)
                }
                else { // could match the stack elem, could not
                    temp = pop( &myStack, flag);
                    if( invBrack(stdCh) != temp) {
                        sprintf( errStr, "%*c:Expected Here", sumRead, invBrack( temp));
                        break; // exit (parse line)
                    }
                    //else the chars match! no other work needed
                }
            }
        } //end while (parse line)
        printf("%s", line);
        if( *errStr != '\0')
            printf("%s\n", errStr);
        else
            printf("Expression is balanced\n");
        resetStack( &myStack);
        resetLine( &errStr);
        printf("\n");
    }//end while (line from stdin)


    free(errStr);
    free(line);
    return 0;
}
ccTracePolylineTool::ccTracePolylineTool(ccPickingHub* pickingHub, QWidget* parent)
	: ccOverlayDialog(parent)
	, Ui::TracePolyLineDlg()
	, m_polyTip(0)
	, m_polyTipVertices(0)
	, m_poly3D(0)
	, m_poly3DVertices(0)
	, m_done(false)
	, m_pickingHub(pickingHub)
{
	assert(pickingHub);

	setupUi(this);
	setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);

	connect(saveToolButton, SIGNAL(clicked()), this, SLOT(exportLine()));
	connect(resetToolButton, SIGNAL(clicked()), this, SLOT(resetLine()));
	connect(continueToolButton, SIGNAL(clicked()), this, SLOT(continueEdition()));
	connect(validButton, SIGNAL(clicked()), this, SLOT(apply()));
	connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
	connect(widthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onWidthSizeChanged(int)));

	//add shortcuts
	addOverridenShortcut(Qt::Key_Escape); //escape key for the "cancel" button
	addOverridenShortcut(Qt::Key_Return); //return key for the "apply" button
	connect(this, SIGNAL(shortcutTriggered(int)), this, SLOT(onShortcutTriggered(int)));

	m_polyTipVertices = new ccPointCloud("Tip vertices");
	m_polyTipVertices->reserve(2);
	m_polyTipVertices->addPoint(CCVector3(0, 0, 0));
	m_polyTipVertices->addPoint(CCVector3(1, 1, 1));
	m_polyTipVertices->setEnabled(false);

	m_polyTip = new ccPolyline(m_polyTipVertices);
	m_polyTip->setForeground(true);
	m_polyTip->setTempColor(ccColor::green);
	m_polyTip->set2DMode(true);
	m_polyTip->reserve(2);
	m_polyTip->addPointIndex(0, 2);
	m_polyTip->setWidth(widthSpinBox->value() < 2 ? 0 : widthSpinBox->value()); //'1' is equivalent to the default line size
	m_polyTip->addChild(m_polyTipVertices);

	validButton->setEnabled(false);
}
示例#3
0
DisplayWidget::DisplayWidget(QWidget *parent) : QTextEdit(parent)
{

  setReadOnly(true);
  setTabChangesFocus(true);
  setOverwriteMode(true);

  setAlignment(Qt::AlignCenter);
  resetLine();

  append(tr("Welcome to the Free Group Calculator!\n"));
  setAlignment(Qt::AlignLeft);

  setFontFamily("Monaco");
  setFontPointSize(12.0);
  append(tr("[%1 %2]:>").arg(Input).arg(lineNumber));
  moveCursor(QTextCursor::End);

}
void ccTracePolylineTool::exportLine()
{
	if (!m_poly3D)
	{
		return;
	}

	if (m_associatedWin)
	{
		m_associatedWin->removeFromOwnDB(m_poly3D);
	}

	unsigned overSampling = static_cast<unsigned>(oversampleSpinBox->value());
	if (overSampling > 1)
	{
		ccPolyline* poly = polylineOverSampling(overSampling);
		if (poly)
		{
			delete m_poly3D;
			m_segmentParams.clear();
			m_poly3DVertices = 0;
			m_poly3D = poly;
		}
	}

	m_poly3D->enableTempColor(false);
	m_poly3D->setDisplay(m_associatedWin); //just in case
	if (MainWindow::TheInstance())
	{
		MainWindow::TheInstance()->addToDB(m_poly3D);
	}
	else
	{
		assert(false);
	}

	m_poly3D = 0;
	m_segmentParams.clear();
	m_poly3DVertices = 0;

	resetLine(); //to update the GUI
}
void ccTracePolylineTool::closePolyLine(int, int)
{
	if (!m_poly3D || (QApplication::keyboardModifiers() & Qt::ControlModifier)) //CTRL + right click = panning
	{
		return;
	}

	unsigned vertCount = m_poly3D->size();
	if (vertCount < 2)
	{
		//discard this polyline
		resetLine();
	}
	else
	{
		//hide the tip
		if (m_polyTip)
		{
			m_polyTip->setEnabled(false);
		}
		//update the GUI
		validButton->setEnabled(true);
		saveToolButton->setEnabled(true);
		resetToolButton->setEnabled(true);
		continueToolButton->setEnabled(true);
		if (m_pickingHub)
		{
			m_pickingHub->removeListener(this);
		}
		m_associatedWin->setPickingMode(ccGLWindow::NO_PICKING); //no more picking
		m_done = true;

		if (m_associatedWin)
		{
			m_associatedWin->redraw(true, false);
		}
	}
}
示例#6
0
char	*getHeaderLine(int fd, int *line, char mod)
{
  char	*tmp;
  int	line_tmp;

  line_tmp = *line;
  while ((++line_tmp) && (tmp = get_next_line(fd)))
    {
      epurLine(tmp);
      if (tmp[0] != '#' && tmp[0] != '.' && tmp[0] != ' ' && tmp[0] != '\t')
	return ((*line)++, NULL);
#ifdef	DEBUG
      write(1, "Line : ", 7);
      write(1, tmp, my_strlen(tmp));
      write(1, "\n", 1);
#endif
      if (tmp[0] == '.' && (*line = line_tmp))
	return (tmp);
      free(tmp);
    }
  if (mod)
    resetLine(fd, *line);
  return ((*line)++, NULL);
}
bool ccTracePolylineTool::start()
{
	assert(m_polyTip);
	assert(!m_poly3D);

	if (!m_associatedWin)
	{
		ccLog::Warning("[Trace Polyline Tool] No associated window!");
		return false;
	}

	m_associatedWin->setUnclosable(true);
	m_associatedWin->addToOwnDB(m_polyTip);
	if (m_pickingHub)
	{
		m_pickingHub->removeListener(this);
	}
	m_associatedWin->setPickingMode(ccGLWindow::NO_PICKING);
	m_associatedWin->setInteractionMode(	ccGLWindow::TRANSFORM_CAMERA()
										|	ccGLWindow::INTERACT_SIG_RB_CLICKED
										|	ccGLWindow::INTERACT_CTRL_PAN
										|	ccGLWindow::INTERACT_SIG_MOUSE_MOVED);
	m_associatedWin->setCursor(Qt::CrossCursor);

	snapSizeSpinBox->blockSignals(true);
	snapSizeSpinBox->setValue(s_defaultPickingRadius);
	snapSizeSpinBox->blockSignals(false);

	oversampleSpinBox->blockSignals(true);
	oversampleSpinBox->setValue(s_overSamplingCount);
	oversampleSpinBox->blockSignals(false);

	resetLine(); //to reset the GUI

	return ccOverlayDialog::start();
}
void ccTracePolylineTool::cancel()
{
	resetLine();

	stop(false);
}