// move: void move(int order){ if(order == BALL1); if(order == BALL2){ findLine(); turnLeftLine(); moveLine(); } if(order == BALL3){ moveBack1(); turnLeft(); } if(order == BALL4){ moveBack2(); turnBack(); } if(order == STORAGE1){ turnBack(); moveBack(); turnLeft(); } if(order == STORAGE2){ findLine(); turnRight(); } }
bool_t CacheRec::getWord(word_t pos, word_t *dest){ int offset = 0;// may jump across lines if(pos+4>len) return FALSE; word_t i = findLine(pos, TRUE, &offset); int d = cB-offset; byte_t *start = contents+(i<<cb)+offset; if(d<4){// exceed memcpy((byte_t*)dest,start,d); //dump(stdout, i, 1); i = findLine(pos+d, TRUE); if(i<0){ printf("invalid pos\n"); return FALSE; } memcpy(((byte_t*)dest)+d, contents+(i<<cb), 4-d); //dump(stdout, i, 1); //printf("get cross-line word %.8x at pos %.4x\n", *dest, pos); }else{ *dest = *(word_t *)start; } #ifdef CHECK_CACHE if(checker){ int val; checker->getWord(pos, &val); if(*dest != val){ printf("CHECK failed at pos 0x%.4x: %.8x not %.8x\n", pos, val, *dest); dump(stdout,0,nlines); //*dest = val; //return FALSE; } } #endif return TRUE; }
bool_t CacheRec::setWord(word_t pos, word_t val){ int offset;// may jump across lines if(pos+4>len) return FALSE; word_t i = findLine(pos, TRUE, &offset); int d = cB-offset; byte_t *start = contents+((i<<cb)+offset); if(d<4){// exceed memcpy(start,(byte_t*)&val,d); dirty[i] = TRUE; //dump(stdout, i, 1); i = findLine(pos+d, TRUE); if(i<0){ printf("invalid pos\n"); return FALSE; } memcpy(contents+(i<<cb), ((byte_t*)&val)+d, 4-d); dirty[i] = TRUE; //dump(stdout, i, 1); //printf("set cross-line word %d at pos %d\n", val, pos); }else{ *(word_t *)start = val; dirty[i] = TRUE; } #ifdef CHECK_CACHE if(checker){ checker->setWord(pos, val); } #endif return TRUE; }
/* * Insert a new line with the specified text. * The line is inserted so as to become the specified line, * thus pushing any existing and further lines down one. * The inserted line is also set to become the current line. * Returns TRUE if successful. */ static int insertLine(int num, const char *data, int len) { LINE *newLp, *lp; if ((num < 1) || (num > lastNum + 1)) { bb_error_msg("inserting at bad line number"); return FALSE; } newLp = xmalloc(sizeof(LINE) + len - 1); memcpy(newLp->data, data, len); newLp->len = len; if (num > lastNum) lp = &lines; else { lp = findLine(num); if (lp == NULL) { free((char *) newLp); return FALSE; } } newLp->next = lp; newLp->prev = lp->prev; lp->prev->next = newLp; lp->prev = newLp; lastNum++; dirty = TRUE; return setCurNum(num); }
/* * Search for a line which contains the specified string. * If the string is "", then the previously searched for string * is used. The currently searched for string is saved for future use. * Returns the line number which matches, or 0 if there was no match * with an error printed. */ static NOINLINE int searchLines(const char *str, int num1, int num2) { const LINE *lp; int len; if (bad_nums(num1, num2, "search")) return 0; if (*str == '\0') { if (searchString[0] == '\0') { bb_error_msg("no previous search string"); return 0; } str = searchString; } if (str != searchString) strcpy(searchString, str); len = strlen(str); lp = findLine(num1); if (lp == NULL) return 0; while (num1 <= num2) { if (findString(lp, str, len, 0) >= 0) return num1; num1++; lp = lp->next; } bb_error_msg("can't find string \"%s\"", str); return 0; }
void line_follow_mm(int distance) { int reqCount = distance/5.338; int error = 0; ShaftCountLeft = 0; forward(); while(ShaftCountLeft < reqCount) { error = getError(); if(error > -100 && error < 100) { leftSpeed = forwardLeftSpeed - error*kp; rightSpeed = forwardRightSpeed + error*kp; velocity(leftSpeed, rightSpeed); } else if(error == -100) findLine(); } }
void commonController::lineChange( commonLineControl *line ) { /* RPCPubSub::publish( "LineControl", line->lineName, line->getState()?"set":"unset" ); // we also want time of change and time in state? */ commonLineControl * pttout = findLine( "PTTOut", false ); commonLineControl *pttin = findLine( "PTTIn", true ); commonLineControl *l1 = findLine( "L1", true ); commonLineControl *l2 = findLine( "L2", true ); if ( pttout && pttin && l1 && l2 ) { setLines( pttout->getState(), pttin->getState(), l1->getState(), l2->getState() ); } LineSet *ls = LineSet::GetLineSet(); ls->publish( line->lineName, line->getState() ); }
Rect2i Layout::getImageRect(std::size_t index) const { const std::pair<std::size_t, LineInfo> line = findLine(index); const int x = (index - line.first) % columns_ * cellStepX_; const int y = (index - line.first) / columns_ * cellStepY_ + line.second.cellTop; return Rect2i(x, y, x + imageWidth_, y + line.second.imageHeight); }
QString DiffView::stringAtLine(int lineno) { int pos; if ( (pos = findLine(lineno)) != -1 ) return items.at(pos)->line; else return QString(); }
/* * Print lines in a specified range. * The last line printed becomes the current line. * If expandFlag is TRUE, then the line is printed specially to * show magic characters. */ static int printLines(int num1, int num2, int expandFlag) { const LINE *lp; const char *cp; int ch, count; if (bad_nums(num1, num2, "print")) return FALSE; lp = findLine(num1); if (lp == NULL) return FALSE; while (num1 <= num2) { if (!expandFlag) { write(1, lp->data, lp->len); setCurNum(num1++); lp = lp->next; continue; } /* * Show control characters and characters with the * high bit set specially. */ cp = lp->data; count = lp->len; if ((count > 0) && (cp[count - 1] == '\n')) count--; while (count-- > 0) { ch = *cp++; if (ch & 0x80) { fputs("M-", stdout); ch &= 0x7f; } if (ch < ' ') { bb_putchar('^'); ch += '@'; } if (ch == 0x7f) { bb_putchar('^'); ch = '?'; } bb_putchar(ch); } fputs("$\n", stdout); setCurNum(num1++); lp = lp->next; } return TRUE; }
word_t CacheRec::invalidate(word_t pos, bool_t wb){ int i; if((i=findLine(pos))<0) return -1; if(wb && dirty[i]){/* write back */ commit(i); } valid[i] = FALSE; return i; }
/* * Delete lines from the given range. */ static BOOL deleteLines(NUM num1, NUM num2) { LINE * lp; LINE * nlp; LINE * plp; NUM count; if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { fprintf(stderr, "Bad line numbers for delete\n"); return FALSE; } lp = findLine(num1); if (lp == NULL) return FALSE; if ((curNum >= num1) && (curNum <= num2)) { if (num2 < lastNum) setCurNum(num2 + 1); else if (num1 > 1) setCurNum(num1 - 1); else curNum = 0; } count = num2 - num1 + 1; if (curNum > num2) curNum -= count; lastNum -= count; while (count-- > 0) { nlp = lp->next; plp = lp->prev; plp->next = nlp; nlp->prev = plp; lp->next = NULL; lp->prev = NULL; lp->len = 0; free(lp); lp = nlp; } dirty = TRUE; return TRUE; }
/* * Set the current line number. * Returns TRUE if successful. */ static int setCurNum(int num) { LINE *lp; lp = findLine(num); if (lp == NULL) return FALSE; curNum = num; curLine = lp; return TRUE; }
/* * Write the specified lines out to the specified file. * Returns TRUE if successful, or FALSE on an error with a message output. */ static int writeLines(const char * file, int num1, int num2) { LINE *lp; int fd, lineCount, charCount; if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { bb_error_msg("bad line range for write"); return FALSE; } lineCount = 0; charCount = 0; fd = creat(file, 0666); if (fd < 0) { perror(file); return FALSE; } printf("\"%s\", ", file); fflush(stdout); lp = findLine(num1); if (lp == NULL) { close(fd); return FALSE; } while (num1++ <= num2) { if (write(fd, lp->data, lp->len) != lp->len) { perror(file); close(fd); return FALSE; } charCount += lp->len; lineCount++; lp = lp->next; } if (close(fd) < 0) { perror(file); return FALSE; } printf("%d lines, %d chars\n", lineCount, charCount); return TRUE; }
/* * Insert a new line with the specified text. * The line is inserted so as to become the specified line, * thus pushing any existing and further lines down one. * The inserted line is also set to become the current line. * Returns TRUE if successful. */ static BOOL insertLine(NUM num, const char * data, LEN len) { LINE * newLp; LINE * lp; if ((num < 1) || (num > lastNum + 1)) { fprintf(stderr, "Inserting at bad line number\n"); return FALSE; } newLp = (LINE *) malloc(sizeof(LINE) + len - 1); if (newLp == NULL) { fprintf(stderr, "Failed to allocate memory for line\n"); return FALSE; } memcpy(newLp->data, data, len); newLp->len = len; if (num > lastNum) lp = &lines; else { lp = findLine(num); if (lp == NULL) { free((char *) newLp); return FALSE; } } newLp->next = lp; newLp->prev = lp->prev; lp->prev->next = newLp; lp->prev = newLp; lastNum++; dirty = TRUE; return setCurNum(num); }
void LineGraphEdge::drawLine(Widget w, const BoxRegion& exposed, const GraphGC& gc) const { // Get node starting points BoxPoint pos1 = from()->pos(); BoxRegion region1 = from()->region(gc); if (from()->selected()) { pos1 += gc.offsetIfSelected; region1.origin() += gc.offsetIfSelected; } BoxPoint pos2 = to()->pos(); BoxRegion region2 = to()->region(gc); if (to()->selected()) { pos2 += gc.offsetIfSelected; region2.origin() += gc.offsetIfSelected; } // If nodes overlap, don't draw the edge. if (region1 <= region2) return; // Get the line points BoxPoint l1, l2; findLine(pos1, pos2, region1, region2, l1, l2, gc); // If there is no edge (adjacent nodes), don't draw it. if (l1 == l2) return; XDrawLine(XtDisplay(w), XtWindow(w), gc.edgeGC, l1[X], l1[Y], l2[X], l2[Y]); // Draw annotation BoxPoint anno_pos = annotationPosition(gc); if (annotation() != 0 && anno_pos.isValid()) { annotation()->draw(w, anno_pos, exposed, gc); } // Get arrow angle double alpha = atan2(double(l1[Y] - l2[Y]), double(l1[X] - l2[X])); // Draw arrow head at L2 drawArrowHead(w, exposed, gc, l2, alpha); }
bool_t CacheRec::setByte(word_t pos, byte_t val){ int offset; word_t i = findLine(pos, TRUE, &offset); if(i>=0){ contents[(i<<cb)+offset] = val; dirty[i] = TRUE; #ifdef CHECK_CACHE if(checker){ checker->setByte(pos, val); } #endif }else{ return FALSE; // invalid pos } }
/* * Search for a line which contains the specified string. * If the string is NULL, then the previously searched for string * is used. The currently searched for string is saved for future use. * Returns the line number which matches, or 0 if there was no match * with an error printed. */ static NUM searchLines(const char * str, NUM num1, NUM num2) { const LINE * lp; int len; if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { fprintf(stderr, "Bad line numbers for search\n"); return 0; } if (*str == '\0') { if (searchString[0] == '\0') { fprintf(stderr, "No previous search string\n"); return 0; } str = searchString; } if (str != searchString) strcpy(searchString, str); len = strlen(str); lp = findLine(num1); if (lp == NULL) return 0; while (num1 <= num2) { if (findString(lp, str, len, 0) >= 0) return num1; num1++; lp = lp->next; } fprintf(stderr, "Cannot find string \"%s\"\n", str); return 0; }
/* * Delete lines from the given range. */ static int deleteLines(int num1, int num2) { LINE *lp, *nlp, *plp; int count; if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { bb_error_msg("bad line numbers for delete"); return FALSE; } lp = findLine(num1); if (lp == NULL) return FALSE; if ((curNum >= num1) && (curNum <= num2)) { if (num2 < lastNum) setCurNum(num2 + 1); else if (num1 > 1) setCurNum(num1 - 1); else curNum = 0; } count = num2 - num1 + 1; if (curNum > num2) curNum -= count; lastNum -= count; while (count-- > 0) { nlp = lp->next; plp = lp->prev; plp->next = nlp; nlp->prev = plp; lp->next = NULL; lp->prev = NULL; lp->len = 0; free(lp); lp = nlp; } dirty = TRUE; return TRUE; }
int main(void) { initIRSensor(); initMotor(); initGPIOLineSensor(); initServo(); SetServo(servo,0); stage = 0; //while(1){followLine();} //while(1){followWall();} //SetMotor(leftMotor, 1); SetMotor(rightMotor, 1); while(true){ LineSensorReadArray(gls, line); if (stage==0){ //start state if(line[0]<0.5&&line[1]<0.5&&line[2]<0.5&&line[3]<0.5&&line[4]<0.5&&line[5]<0.5&&line[6]<0.5&&line[7]<0.5) { followWall(); }else{ followLine(); } }else if(stage==1){ //once 90degree turn passed // SetMotor(leftMotor, 1); // SetMotor(rightMotor, -1); SetPin(PIN_F2, 1); followWall(); if (wallPresent()) {followWall();} else { findLine(); } SetPin(PIN_F2, 0); }else if (stage==2){ //once line found again after walled section SetPin(PIN_F1, 1); if((line[0]<0.5&&line[1]<0.5&&line[2]<0.5&&line[3]<0.5&&line[4]<0.5&&line[5]<0.5&&line[6]<0.5&&line[7]<0.5)|| (mostDark())) { //line[0]>0.5&&line[1]>0.5&&line[2]>0.5&&line[3]>0.5&&line[4]>0.5&&line[5]>0.5&&line[6]>0.5&&line[7]>0.5) findEnd(); }else{ followLine(); }; SetPin(PIN_F1, 0); }else{//end of course look for flag findObject(); break; } } }
// move: void move(int order){ if(order == 1){ mrp(LM, LM_SP_STR2, BALL_1_DIS); mrp(RM, RM_SP_STR2, BALL_1_DIS); bmd(LM); bmd(RM); ao(); } if(order == 2){ findLine(); turnLeftLine(); moveLine(); } if(order == 3){ } }
/* * Write the specified lines out to the specified file. * Returns TRUE if successful, or FALSE on an error with a message output. */ static int writeLines(const char *file, int num1, int num2) { LINE *lp; int fd, lineCount, charCount; if (bad_nums(num1, num2, "write")) return FALSE; lineCount = 0; charCount = 0; fd = creat(file, 0666); if (fd < 0) { bb_simple_perror_msg(file); return FALSE; } printf("\"%s\", ", file); fflush_all(); lp = findLine(num1); if (lp == NULL) { close(fd); return FALSE; } while (num1++ <= num2) { if (full_write(fd, lp->data, lp->len) != lp->len) { bb_simple_perror_msg(file); close(fd); return FALSE; } charCount += lp->len; lineCount++; lp = lp->next; } if (close(fd) < 0) { bb_simple_perror_msg(file); return FALSE; } printf("%d lines, %d chars\n", lineCount, charCount); return TRUE; }
/* * Print lines in a specified range. * The last line printed becomes the current line. * If expandFlag is TRUE, then the line is printed specially to * show magic characters. */ static int printLines(int num1, int num2, int expandFlag) { const LINE *lp; const char *cp; int ch, count; if (bad_nums(num1, num2, "print")) return FALSE; lp = findLine(num1); if (lp == NULL) return FALSE; while (num1 <= num2) { if (!expandFlag) { write(STDOUT_FILENO, lp->data, lp->len); setCurNum(num1++); lp = lp->next; continue; } /* * Show control characters and characters with the * high bit set specially. */ cp = lp->data; count = lp->len; if ((count > 0) && (cp[count - 1] == '\n')) count--; while (count-- > 0) { ch = (unsigned char) *cp++; fputc_printable(ch | PRINTABLE_META, stdout); } fputs("$\n", stdout); setCurNum(num1++); lp = lp->next; } return TRUE; }
task main() { gyroCal(); move(82, 25); turn(90, 20); findLine(-40, 25); move(15, 25); lower(); tmove(-2000, 30); // raise house raise(); findLine(40, 25); turn(90, 20); tmove(-2500, 30); move(7, 30); turn(90, 20); findLine(-40, 25); lower(); move(3, 25); raise(); //flip stove move(7, 30); turn(270, 25); tmove(-2000, 30); findLine(40, 30); move(5, 15); turn(70, 15); move(60, 30); turn(20, 15); tmove(2000, 25); move(-4, 20); turn(90, 15); findLine(40, 20); move(10, 15); // push sign findLine(-40, 20); move(-25, 30); turn(90, 20); tmove(-1500, 25); move(22, 20); turn(40, 20); move(40, 20); //herd food pmove(30, 20, 25); move(-5, 20); turn(70, 20); tmove(1500, 20); move(-2, 20); turn(90, 15); move(30, 20); lower(); move(20, 20); }
/* Class functions */ void startCustomer() { int task, id; int my_line = -1; bool isSen = Customers[id].isSenator; Acquire(DataLock); id = numActiveCustomers; numActiveCustomers++; Release(DataLock); /*implementation */ if (isSen) { } else { my_line = findLine('a', isSen, id); getAppFiled(my_line, id); numCustomers--; } Exit(0); }
int Solution::maxPoints(vector<Point>& points){ if(points.size()<=2)return points.size(); int result=2; for(int i=0;i<points.size()-2;i++){ int count=1; for(int j=i+1;j<points.size()-1;j++){ int temp=count+1; if(points[i].x==points[j].x && points[i].y==points[j].y){ count++; continue; } for(int k=j+1;k<points.size();k++){ if(findLine(points,i,j,k)) temp++; } if(temp>result)result=temp; } if(result<count+1) result=count+1; } return result; }
/* * Search for a line which contains the specified string. * If the string is NULL, then the previously searched for string * is used. The currently searched for string is saved for future use. * Returns the line number which matches, or 0 if there was no match * with an error printed. */ static int searchLines(const char *str, int num1, int num2) { const LINE *lp; int len; if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { bb_error_msg("bad line numbers for search"); return 0; } if (*str == '\0') { if (searchString[0] == '\0') { bb_error_msg("no previous search string"); return 0; } str = searchString; } if (str != searchString) strcpy(searchString, str); len = strlen(str); lp = findLine(num1); if (lp == NULL) return 0; while (num1 <= num2) { if (findString(lp, str, len, 0) >= 0) return num1; num1++; lp = lp->next; } bb_error_msg("cannot find string \"%s\"", str); return 0; }
/* * Delete lines from the given range. */ static void deleteLines(int num1, int num2) { LINE *lp, *nlp, *plp; int count; if (bad_nums(num1, num2, "delete")) return; lp = findLine(num1); if (lp == NULL) return; if ((curNum >= num1) && (curNum <= num2)) { if (num2 < lastNum) setCurNum(num2 + 1); else if (num1 > 1) setCurNum(num1 - 1); else curNum = 0; } count = num2 - num1 + 1; if (curNum > num2) curNum -= count; lastNum -= count; while (count-- > 0) { nlp = lp->next; plp = lp->prev; plp->next = nlp; nlp->prev = plp; free(lp); lp = nlp; } dirty = TRUE; }
BoxPoint LineGraphEdge::annotationPosition(const GraphGC &gc) const { if (from() == to()) { BoxRegion region = from()->region(gc); if (from()->selected()) region.origin() += gc.offsetIfSelected; LineGraphEdgeSelfInfo info(region, gc); return info.anno_pos; } BoxPoint pos1 = from()->pos(); BoxRegion region1 = from()->region(gc); BoxPoint pos2 = to()->pos(); BoxRegion region2 = to()->region(gc); BoxPoint l1, l2; findLine(pos1, pos2, region1, region2, l1, l2, gc); if (from()->isHint() && to()->isHint()) { // Between two hints -- don't draw anything return BoxPoint(); } if (to()->isHint()) { // Draw at hint position return to()->pos(); } // Draw at mid-distance return l1 + (l2 - l1) / 2; }
bool_t CacheRec::getByte(word_t pos, byte_t *dest){ int offset; word_t i = findLine(pos, TRUE, &offset); if(i>=0){ *dest = contents[(i<<cb)+offset]; #ifdef CHECK_CACHE if(checker){ byte_t val; checker->getByte(pos, &val); if( val != *dest){ printf("CHECK failed at pos 0x%.4x: %.2x not %.2x\n", pos, val, *dest); dump(stdout,0,nlines); //*dest = val; //return FALSE; } } #endif return TRUE; }else{ return FALSE; // invalid pos } }