/* * ex_copy -- :[line [,line]] co[py] line [flags] * Copy selected lines. * * PUBLIC: int ex_copy(SCR *, EXCMD *); */ int ex_copy(SCR *sp, EXCMD *cmdp) { CB cb; MARK fm1, fm2, m, tm; recno_t cnt; int rval; rval = 0; NEEDFILE(sp, cmdp); /* * It's possible to copy things into the area that's being * copied, e.g. "2,5copy3" is legitimate. Save the text to * a cut buffer. */ fm1 = cmdp->addr1; fm2 = cmdp->addr2; memset(&cb, 0, sizeof(cb)); TAILQ_INIT(&cb.textq); for (cnt = fm1.lno; cnt <= fm2.lno; ++cnt) if (cut_line(sp, cnt, 0, CUT_LINE_TO_EOL, &cb)) { rval = 1; goto err; } cb.flags |= CB_LMODE; /* Put the text into place. */ tm.lno = cmdp->lineno; tm.cno = 0; if (put(sp, &cb, NULL, &tm, &m, 1)) rval = 1; else { /* * Copy puts the cursor on the last line copied. The cursor * returned by the put routine is the first line put, not the * last, because that's the historic semantic of vi. */ cnt = (fm2.lno - fm1.lno) + 1; sp->lno = m.lno + (cnt - 1); sp->cno = 0; } err: text_lfree(&cb.textq); return (rval); }
// --------------------------------------------------------------------------- // // ----------- void bToolCut::action(int count){ bGenericGeoElement* o=get_obj(); if(!o){ return; } bGenericType* tp=_gapp->typesMgr()->get(o->getType()); bEventLog log(_gapp, getbundle(), kCutMessageID, GetSignature(this)); switch(tp->kind()){ case kBaseKindPolyline: cut_line(o); break; case kBaseKindPolygon: case kBaseKindRaster: cut_surf(o); break; default: break; } log.close(); }
/* Move text from the current linestruct into the cutbuffer. If * copy_text is TRUE, copy the text back into the linestruct afterward. * If cut_till_eof is TRUE, move all text from the current cursor * position to the end of the file into the cutbuffer. */ void do_cut_text( #ifndef NANO_TINY bool copy_text, bool cut_till_eof, bool undoing #else void #endif ) { #ifndef NANO_TINY linestruct *cb_save = NULL; /* The current end of the cutbuffer, before we add text to * it. */ size_t cb_save_len = 0; /* The length of the string at the current end of the cutbuffer, * before we add text to it. */ bool old_no_newlines = ISSET(NO_NEWLINES); #endif assert(openfile->current != NULL && openfile->current->data != NULL); /* If keep_cutbuffer is FALSE and the cutbuffer isn't empty, blow * away the text in the cutbuffer. */ if (!keep_cutbuffer && cutbuffer != NULL) { free_filestruct(cutbuffer); cutbuffer = NULL; #ifdef DEBUG fprintf(stderr, "Blew away cutbuffer =)\n"); #endif } #ifndef NANO_TINY if (copy_text) { if (cutbuffer != NULL) { /* If the cutbuffer isn't empty, save where it currently * ends. This is where we'll add the new text. */ cb_save = cutbottom; cb_save_len = strlen(cutbottom->data); } /* Set NO_NEWLINES to TRUE, so that we don't disturb the last * line of the file when moving text to the cutbuffer. */ SET(NO_NEWLINES); } #endif /* Set keep_cutbuffer to TRUE, so that the text we're going to move * into the cutbuffer will be added to the text already in the * cutbuffer instead of replacing it. */ keep_cutbuffer = TRUE; #ifndef NANO_TINY if (cut_till_eof) { /* If cut_till_eof is TRUE, move all text up to the end of the * file into the cutbuffer. */ cut_to_eof(); } else if (openfile->mark_set) { /* If the mark is on, move the marked text to the cutbuffer, and * turn the mark off. */ cut_marked(); openfile->mark_set = FALSE; } else if (ISSET(CUT_TO_END)) /* If the CUT_TO_END flag is set, move all text up to the end of * the line into the cutbuffer. */ cut_to_eol(); else #endif /* Move the entire line into the cutbuffer. */ cut_line(); #ifndef NANO_TINY if (copy_text) { /* Copy the text in the cutbuffer, starting at its saved end if * there is one, back into the linestruct. This effectively * uncuts the text we just cut without marking the file as * modified. */ if (cutbuffer != NULL) { if (cb_save != NULL) { cb_save->data += cb_save_len; copy_from_filestruct(cb_save); cb_save->data -= cb_save_len; } else copy_from_filestruct(cutbuffer); /* Set the current place we want to where the text from the * cutbuffer ends. */ openfile->placewewant = xplustabs(); } /* Set NO_NEWLINES back to what it was before, since we're done * disturbing the text. */ if (!old_no_newlines) UNSET(NO_NEWLINES); } else if (!undoing) update_undo(cut_till_eof ? CUT_EOF : CUT); /* Leave the text in the cutbuffer, and mark the file as * modified. */ if (!copy_text) #endif /* !NANO_TINY */ set_modified(); /* Update the screen. */ edit_refresh_needed = TRUE; #ifndef DISABLE_COLOR reset_multis(openfile->current, FALSE); #endif #ifdef DEBUG dump_filestruct(cutbuffer); #endif }
void burst() { int x, y; int r, c; int centerr, centerc; int centerx, centery; int line_size, radius; char cut; list_node_t *head, *n, *temp; clear_invert_map(); centerr = map.num_row/2; centerc = map.num_col/2; section_center(¢erx, ¢ery, centerr, centerc); radius = (map.sec_width > map.sec_height ? map.sec_width : map.sec_height)/4.0; radius = (radius == 0 ? 1 : radius ); line_size = (map.sec_width > map.sec_height ? map.sec_width : map.sec_height)/4.0; line_size = (line_size == 0 ? 1 : line_size); head = NULL; for( r = 0; r < map.num_row; r++ ) { for( c = 0; c < map.num_col; c++ ) { cut = 0; /* * if top left, top center, top right * or center * or bottom left, bottom center, bottom right */ if( (r == 0 && (c == 0 || c == centerc || c == map.num_col-1)) || (r == centerr && c == centerc) || (r == map.num_row-1 && (c == 0 || c == centerc || c == map.num_col-1))) cut = 1; else if( rand()%3 == 0 ) cut = 1; else cut = 0; if( cut == 1 ) { section_center(&x, &y, r, c); circlefill(map.map, x, y, radius, 255); printf("cutting(r,c): %d, %d\n", r, c); head = add_list_node(head, x, y); printf("after adding list node\n"); } } } for( n = head; n != NULL; n = temp ) { cut_line(n->x, n->y, centerx, centery, line_size); temp = n->next; free(n); printf("freeing node...\n"); } /* TODO: do i need this: cut outline around map... */ return; }