void TEditor::setCurPtr( ushort p, uchar selectMode ) { ushort anchor; if( (selectMode & smExtend) == 0 ) anchor = p; else if( curPtr == selStart ) anchor = selEnd; else anchor = selStart; if( p < anchor ) { if( (selectMode & smDouble) != 0 ) { p = prevLine(nextLine(p)); anchor = nextLine(prevLine(anchor)); } setSelect(p, anchor, True); } else { if( (selectMode & smDouble) != 0 ) { p = nextLine(p); anchor = prevLine(nextLine(anchor)); } setSelect(anchor, p, False); } }
/* * eatSpace: increment mark over all whitespace until we hit a * character which is not whitespace. This ignores line breaks. */ static char *eatSpace( i_mark *mark, bool reverse ) { char *s; s = ptrFromMark( mark ); if( s == NULL ) { return( NULL ); } while( charType( *s, true ) == BLOCK_WHITESPACE ) { if( reverse ) { s = decrementMark( mark ); } else { s = incrementMark( mark ); } if( s == NULL ) { if( EditFlags.OperatorWantsMove ) { return( NULL ); } if( reverse ) { s = prevLine( mark ); } else { s = nextLine( mark ); } if( s == NULL ) { break; } } } return( s ); } /* eatSpace */
QScrollBar *ZLQtViewWidget::addScrollBar(QGridLayout *layout, Qt::Orientation orientation, int x, int y) { QScrollBar *scrollBar = new QScrollBar(orientation, myFrame); layout->addWidget(scrollBar, x, y); scrollBar->hide(); if (orientation == Qt::Vertical) { connect(scrollBar, SIGNAL(sliderMoved(int)), this, SLOT(onVerticalSliderMoved(int))); connect(scrollBar, SIGNAL(nextLine()), this, SLOT(onVerticalSliderStepNext())); connect(scrollBar, SIGNAL(nextPage()), this, SLOT(onVerticalSliderPageNext())); connect(scrollBar, SIGNAL(prevLine()), this, SLOT(onVerticalSliderStepPrevious())); connect(scrollBar, SIGNAL(prevPage()), this, SLOT(onVerticalSliderPagePrevious())); } else {
void EigenGraspDlg::setSlaveLayout( int nGrasps ) { mainLayout = new QVBoxLayout(mSlave, 5); QLabel *valueLabel = new QLabel(QString("Value:"), mSlave); QLabel *amplLabel = new QLabel(QString("Amplitude:"), mSlave); QLabel *fixedLabel = new QLabel(QString("Fixed"), mSlave); QHBoxLayout *fakeRow = new QHBoxLayout(mainLayout,-1); fakeRow->addSpacing(400); QHBoxLayout *labelRow = new QHBoxLayout(mainLayout,-1); labelRow->addSpacing(5); labelRow->addWidget(valueLabel,0); labelRow->addWidget(amplLabel,1,Qt::AlignHCenter); labelRow->addWidget(fixedLabel,0); labelRow->addSpacing(5); mainLayout->addLayout(labelRow); for (int i=0; i<nGrasps; i++) { QHBoxLayout *graspRow = new QHBoxLayout(mainLayout,10); QLabel *eigenValue = new QLabel(QString("0.0"), mSlave); QScrollBar *bar = new QScrollBar(Qt::Horizontal, mSlave); bar->setRange( -SLIDER_STEPS, SLIDER_STEPS ); bar->setPageStep(5000); bar->setLineStep(1000); bar->setValue(0); QCheckBox *box = new QCheckBox(mSlave); graspRow->addSpacing(15); graspRow->addWidget(eigenValue,0); graspRow->addWidget(bar,1); graspRow->addWidget(box,0); graspRow->addSpacing(15); mValueList.push_back(eigenValue); mBarList.push_back(bar); mCheckList.push_back(box); connect(bar,SIGNAL(sliderMoved(int)), this, SLOT(eigenGraspChanged()) ); //comment this one out //connect(bar,SIGNAL(valueChanged(int)), this, SLOT(eigenGraspChanged()) ); connect(bar,SIGNAL(nextLine()), this, SLOT(eigenGraspChanged()) ); connect(bar,SIGNAL(prevLine()), this, SLOT(eigenGraspChanged()) ); connect(bar,SIGNAL(nextPage()), this, SLOT(eigenGraspChanged()) ); connect(bar,SIGNAL(prevPage()), this, SLOT(eigenGraspChanged()) ); connect(bar,SIGNAL(sliderReleased()), this, SLOT(eigenGraspChanged()) ); connect(box,SIGNAL(clicked()), this, SLOT(fixBoxChanged()) ); } mainLayout->addSpacing(20); }
/*! Attempts to read a line and returns an LByteArray containing the line. This wraps around readOneLine and provides a hack to do additional unwrapping for a malformed vCard where a space is not added to the start of the line continuation. Some malformed vCards we get look like this: (Case 1) ORG:A B C (CRLF-SPACE wrapping is employed for the first time, then the space is subsequently omitted). But a valid vCard can be weirdly wrapped without the CRLF-SPACE, if it's quoted-printable and ends in an equals, eg. (Case 2) ORG;ENCODING=QUOTED-PRINTABLE:A= B= C Unwrap in Case 1 but not in Case 2 - leave that for the QP-decoder in QVR::unencode */ LByteArray LineReader::readLine() { QByteArray colon(VersitUtils::encode(':', mCodec)); QByteArray equals(VersitUtils::encode('=', mCodec)); if (!mPushedLines.isEmpty()) { LByteArray retval(mPushedLines.pop()); return retval; } readOneLine(&mBuffer); // Hack: read the next line and see if it's a continuation of this line while (true) { int prevStart = mBuffer.mStart; int prevEnd = mBuffer.mEnd; // readOneLine only appends to mBuffer so these saved offsets should remain valid readOneLine(&mBuffer); // Get an LByteArray of the previous line. This should be fast because copying the // LByteArray copies the QByteArray, which is implicitly shared LByteArray prevLine(mBuffer.mData, prevStart, prevEnd); if (mBuffer.isEmpty() || mBuffer.contains(colon) || prevLine.endsWith(equals)) { // Normal, the next line is empty, or a new property, or it's been wrapped using // QUOTED-PRINTABLE. Rewind it back one line so it gets read next time round. mBuffer.setBounds(prevStart, prevEnd); break; } else { // Some silly vCard generator has probably wrapped a line without prepending a space // Join the previous line with this line by deleting the characters between prevEnd and // mStart (eg. any newline characters) int crlfLen = mBuffer.mStart-prevEnd; mBuffer.mData.remove(prevEnd, crlfLen); mBuffer.setBounds(prevStart, mBuffer.mEnd - crlfLen); } } mBuffer.dropOldData(); mOdometer += mBuffer.size(); return mBuffer; }
/* * MarkEndOfNextWordForward - find a pointer to the start of the next * word (in the backwards direction) */ vi_rc MarkStartOfNextWordBackward( i_mark *result, i_mark *curr, bool big ) { char *s; btype block_type; noWrap = false; *result = *curr; s = decrementMark( result ); if( s == NULL ) { s = prevLine( result ); if( s == NULL ) { return( ERR_NOT_THAT_MANY_WORDS ); } if( EditFlags.Modeless ) { incrementMark( result ); return ERR_NO_ERR; } } s = eatSpace( result, true ); if( s == NULL ) { return( ERR_NOT_THAT_MANY_WORDS ); } /* * because we are looking at the previous character in the following loop, * we have to be careful in case we are sitting at the start of a line. */ if( result->column > 1 ) { block_type = charType( *s, big ); while( charType( *(s - 1), big ) == block_type ) { s = decrementMark( result ); if( s == NULL || result->column == 1 ) { break; } } } return( ERR_NO_ERR ); } /* MarkStartOfNextWordBackward */
ushort TEditor::lineMove( ushort p, int count ) { ushort i = p; p = lineStart(p); int pos = charPos(p, i); while( count != 0 ) { i = p; if( count < 0 ) { p = prevLine(p); count++; } else { p = nextLine(p); count--; } } if( p != i ) p = charPtr(p, pos); return p; }
void editfile( struct options *options, list_ref list ){ char stdinline[1024]; char *operand = NULL; int stdincount = 0; int lineCount = 0; char *linepos = NULL; for(;;){ if(!options->s_opt_silent) printf("%s: ", progname); linepos = fgets( stdinline, sizeof stdinline, stdin ); if( linepos == NULL ) break; if(options->e_opt_echo && !options->s_opt_silent) printf("%s",stdinline); linepos = strchr( stdinline, '\n' ); if( linepos == NULL || stdinline[0] == '\0' ){ badline( stdincount, stdinline ); }else{ *linepos = '\0'; operand=stdinline+1; switch( stdinline[0] ){ case '$': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } lastLine(list, options); break; case '*': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } printAll(list, options); break; case '.': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } printCurr(list, options); break; case '0': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } firstLine(list, options); break; case '<': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } prevLine(list, options); break; case '>': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } nextLine(list, options); break; case '@': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } debugdump_list( list ); break; case 'a': insertAfter(list, operand, options); break; case 'd': if(stdinline[1] != '\0') { badline(stdincount, stdinline); break; } deleteLine(list, options); break; case 'i': insertBefore(list, operand, options); break; case 'r': lineCount = readFile(list, operand, options); if(lineCount>=0 && !options->s_opt_silent) printf("%s: %d lines read.\n", progname, lineCount); break; case 'w': lineCount = writeFile(list, operand, options); if(lineCount>=0 && !options->s_opt_silent) printf("%s: %d lines written to %s\n", progname, lineCount, operand); break; default : badline( stdincount, stdinline ); }; }; ++stdincount; }; if(!options->s_opt_silent) printf("\n"); }
int main(int argc, const char *ppArgv[]) { std::shared_ptr<FILE> spfOutput(stdout, fclose_checked); const char *pszInputFile = nullptr; bool bLaserMode = false; unsigned int uiLinesOut = 0; // // Parse command-line arguments: // -o outputfile // -i inputfile // -l or -laser = laser-mode std::string strAppName(ppArgv[0]); #ifdef _WIN32 std::string::size_type szSlash = strAppName.rfind('\\'); #else std::string::size_type szSlash = strAppName.rfind('/'); #endif if (szSlash != strAppName.npos) { strAppName.erase(0, szSlash); } // // Turn on laser mode if the executable name contains the word laser, e.g. gcodeoptlaser std::transform(strAppName.begin(), strAppName.end(), strAppName.begin(), ::tolower); if (strAppName.npos != strAppName.find("laser")) { bLaserMode = true; } for (int iArg = 1; iArg < argc; ++iArg) { const std::string strOption(ppArgv[iArg]); if (strOption == "-o" && iArg < (argc - 1) && spfOutput.get() == stdout) { spfOutput.reset(fopen(ppArgv[iArg + 1], "wt"), fclose); if (nullptr == spfOutput) { fprintf(stderr, "Error %i opening %hs\n", errno, ppArgv[iArg + 1]); return 0; } ++iArg; } else if (strOption == "-laser" || strOption == "-l") { bLaserMode = true; } else if (strOption == "-i" && pszInputFile == nullptr && iArg < (argc - 1)) { if (false == FileExists(ppArgv[iArg + 1])) { return 0; } pszInputFile = ppArgv[iArg + 1]; ++iArg; } else if (pszInputFile == nullptr && FileExists(strOption)) { pszInputFile = ppArgv[iArg]; } else { fprintf(stderr, "Unknown command-line argument: %hs\n", strOption.c_str()); return 0; } } if (pszInputFile == nullptr) { fprintf(stderr, "USAGE: %hs inputfile [-o outputfile][-laser|-l][-x|-y|-xy]\n", ppArgv[0]); return 0; } std::shared_ptr<FILE> spFile(fopen(ppArgv[1], "rt"), fclose); if (spFile.get() == nullptr) { fprintf(stderr, "Error %i opening %hs\n", errno, ppArgv[1]); return 1; } unsigned int uiLine = 0; std::deque<GCodeSet> vCurrentSets; bool bInPrologue = true; bool bInEpilogue = false; GCodeSet gcCurrent(0.0f, 0.0f, 0.0f); std::string strPreviousLine; double dCurrentZ = 0.0f; double dCurrentX = 0.0f; double dCurrentY = 0.0f; double dLastZ = 0.0f; double dLastX = 0.0f; double dLastY = 0.0f; unsigned int uiSets = 0; bool bCutterEngaged = false; // // Add an attribution fprintf(spfOutput.get(), "(Optimized by %hs)\n(Written by Andrew L. Sandoval)\n", strAppName.c_str()); // Read file and break into sections... while (!feof(spFile.get())) { std::array<char, 2048> szLine = { }; if (nullptr == fgets(&szLine[0], szLine.size(), spFile.get())) { continue; } ++uiLine; std::string strLine(&szLine[0]); std::string strLineCodes(strLine); std::string::size_type szLE = strLineCodes.find_first_of("\r\n"); if (szLE != strLineCodes.npos) { strLineCodes.erase(szLE); } PreviousLine prevLine(strPreviousLine, strLine); std::string::size_type szX = strLine.find(" X"); std::string::size_type szY = strLine.find(" Y"); std::string::size_type szZ = strLine.find(" Z"); if (strLine.length() > 1 && strLine[0] == 'G' && strLine[1] == '0') { bCutterEngaged = false; } else if (strLine.length() > 2 && strLine[0] == 'G' && strLine[1] == '1' && false == isdigit(strLine[2])) // Don't clobber G17 { bCutterEngaged = true; } else if (bInPrologue) { if (strLineCodes == "M3" && bLaserMode) { fprintf(spfOutput.get(), "(M3 - removed in laser mode)\n"); } else { fprintf(spfOutput.get(), strLine.c_str()); } ++uiLinesOut; continue; // Stay in prologue until a G0/G1 } // // From here on, past prologue // // Check for start of epilogue (before we much with M5's) if (strLine.find("M5") == 0 || strLine.find("M30") == 0) { // sort and flush last set, in epilogue -- sort and output vCurrentSets vCurrentSets.push_back(gcCurrent); OptimizeAndOutputSets(vCurrentSets, uiLinesOut, spfOutput.get()); gcCurrent.Reset(); vCurrentSets.clear(); // Only supporting one tool currently, so first spindle stop means prologue... bInEpilogue = true; bInPrologue = false; if (dCurrentZ < 0.0f && bLaserMode == false) { fprintf(stderr, "WARNING!!!! Program Ends with cutter down, Z = %.02f\n", dCurrentZ); } } if (bInEpilogue) { fprintf(spfOutput.get(), strLine.c_str()); ++uiLinesOut; continue; } // // G0 w/Z or G1 w/Z // If Laser Mode, change any G0 Z to an M5 (laser off) // If Laser Mode, change and G1 Z to M3 (laser on) if (strLine[0] == 'G' && szZ != strLine.npos) { if (bCutterEngaged) { dLastZ = dCurrentZ; dCurrentZ = atof(strLine.c_str() + szZ + 2); gcCurrent.SetZStart(dCurrentZ); if (dLastZ != dCurrentZ) { // sort and flush last set, new depth -- sort and output vCurrentSets // This line will end up in gcCurrent so it can be ignored OptimizeAndOutputSets(vCurrentSets, uiLinesOut, spfOutput.get()); vCurrentSets.clear(); } } if (bLaserMode) { // G0 Z (replace with M3 - shut off laser) // G1 Z (replace with M5) if (bCutterEngaged == false) { // Moving with laser disengaged strLine = "M5 (laser off - was "; strLine += strLineCodes; strLine += ")\n"; } else { strLine = "M3 (laser on - was "; strLine += strLineCodes; strLine += ")\n"; } if (bInPrologue) // Only place this should happen... { fprintf(spfOutput.get(), strLine.c_str()); } } } // // G0 w/X or G1 w/X if (strLine[0] == 'G' && // Cutter engaged or not, move to X szX != strLine.npos) { // Update current position for tracking end position of set dLastX = dCurrentX; dCurrentX = atof(strLine.c_str() + szX + 2); } // // G0 w/Y or G1 w/Y if (strLine[0] == 'G' && // Cutter engaged or not, move to Y szY != strLine.npos) { // Update current position for tracking end position of set dLastY = dCurrentY; dCurrentY = atof(strLine.c_str() + szY + 2); } // // G0 X - start of a set if (strLine.find("G0 X") == 0) // Rapid Linear Motion, cutter not engaged { bInPrologue = false; bInEpilogue = false; // NOTE: Though x and y will be the end of the G0 rapid linear motion, it is the start of a set // where cutting begins! // Error if the depth is not positive!!! // Start of a new set... if (szX == strLine.npos || szY == strLine.npos) { fprintf(stderr, "Critical Error: expected a G0 line to contain X and Y axis settings on line #%u: %hs\n", uiLine, strLine.c_str()); return 0; } // // Update the last set's end point: gcCurrent.SetZEnd(dLastZ); gcCurrent.SetXEnd(dLastX); gcCurrent.SetYEnd(dLastY); if (gcCurrent.GetLines().empty() == false) { vCurrentSets.push_back(gcCurrent); } // A new set is started with a G0 X // When a G1 Z to a new depth is encountered all previous sets can be sorted and output // Same for epilogue start // // Record new set's start point and update references gcCurrent.Reset(dCurrentX, dCurrentY, dCurrentZ); // Current Z may change on next line ++uiSets; } // // Part of a set... if (bInPrologue == true) { continue; } gcCurrent.LineVector().push_back(strLine); } fprintf(stderr, "Output Lines: %lu\n", uiLinesOut); fprintf(stderr, "Input Lines: %lu\n", uiLine); return 0; }
void KviIrcView::mouseMoveEvent(QMouseEvent * e) { bool bCursorOverMarker = checkMarkerArea(e->pos()); if(m_bMouseIsDown && (e->buttons() & Qt::LeftButton)) // m_bMouseIsDown MUST BE true...(otherwise the mouse entered the window with the button pressed ?) { if(m_iSelectTimer == 0) m_iSelectTimer = startTimer(KVI_IRCVIEW_SELECT_REPAINT_INTERVAL); //scroll the ircview if the user is trying to extend a selection near the ircview borders int curY = e->pos().y(); if(curY < KVI_IRCVIEW_VERTICAL_BORDER) { prevLine(); } else if(curY > (height() - KVI_IRCVIEW_VERTICAL_BORDER)) { nextLine(); } KviIrcViewLine *tempLine=getVisibleLineAt(e->pos().y()); if(tempLine) { m_pSelectionEndLine = tempLine; int iTmp=getVisibleCharIndexAt(m_pSelectionEndLine, e->pos().x(), e->pos().y()); if(iTmp > -1) m_iSelectionEndCharIndex = iTmp; } return; } if(m_iSelectTimer) { killTimer(m_iSelectTimer); m_iSelectTimer = 0; } int yPos = e->pos().y(); int rectTop; int rectHeight; QRect rctLink; KviIrcViewWrappedBlock * newLinkUnderMouse = getLinkUnderMouse(e->pos().x(),yPos,&rctLink); rectTop = rctLink.y(); rectHeight = rctLink.height(); if(newLinkUnderMouse != m_pLastLinkUnderMouse) { m_pLastLinkUnderMouse = newLinkUnderMouse; if(m_pLastLinkUnderMouse) { if(rectTop < 0)rectTop = 0; if((rectTop + rectHeight) > height())rectHeight = height() - rectTop; if(m_iLastLinkRectHeight > -1) { // prev link int top = (rectTop < m_iLastLinkRectTop) ? rectTop : m_iLastLinkRectTop; int lastBottom = m_iLastLinkRectTop + m_iLastLinkRectHeight; int thisBottom = rectTop + rectHeight; QRect r(0,top,width(),((lastBottom > thisBottom) ? lastBottom : thisBottom) - top); repaint(r); } else { // no prev link QRect r(0,rectTop,width(),rectHeight); repaint(r); } m_iLastLinkRectTop = rectTop; m_iLastLinkRectHeight = rectHeight; } else { if(m_iLastLinkRectHeight > -1) { // There was a previous bottom rect QRect r(0,m_iLastLinkRectTop,width(),m_iLastLinkRectHeight); repaint(r); m_iLastLinkRectTop = -1; m_iLastLinkRectHeight = -1; } } } if(bCursorOverMarker || m_pLastLinkUnderMouse) setCursor(Qt::PointingHandCursor); else setCursor(Qt::ArrowCursor); }