static void term_osd_update(struct MPContext *mpctx) { int num_parts = 0; char *parts[3] = {0}; if (!mpctx->opts->use_terminal) return; if (mpctx->term_osd_subs && mpctx->term_osd_subs[0]) parts[num_parts++] = mpctx->term_osd_subs; if (mpctx->term_osd_text && mpctx->term_osd_text[0]) parts[num_parts++] = mpctx->term_osd_text; if (mpctx->term_osd_status && mpctx->term_osd_status[0]) parts[num_parts++] = mpctx->term_osd_status; char *s = join_lines(mpctx, parts, num_parts); if (strcmp(mpctx->term_osd_contents, s) == 0 && mp_msg_has_status_line(mpctx->global)) { talloc_free(s); } else { talloc_free(mpctx->term_osd_contents); mpctx->term_osd_contents = s; mp_msg(mpctx->statusline, MSGL_STATUS, "%s", s); } }
/*** Remove the char under the cursor ***/ void del(Project p, BYTE word) { if(p->nbc < p->edited->size) { ULONG nbc = word ? forward_word(p->edited,p->nbc)-1 : p->nbc; rem_chars(&p->undo, p->edited, p->nbc, nbc); REDRAW_CURLINE(p); inv_curs(p, TRUE); } else if(p->edited->next) { /* Join current and next line: */ if( join_lines(&p->undo, p->edited, p->edited->next) ) { REDRAW_CURLINE(p); /* Is it needed to scroll display? */ if(p->ycurs < gui.botcurs) scroll_up(p,p->edited->next,p->ycurs,p->left_pos); /* Redraw the cursor: */ inv_curs(p,TRUE); p->max_lines--; prop_adj(p); } else ThrowError(Wnd, ErrMsg(ERR_NOMEM)); } }
/*** Remove the char before the cursor ***/ void back_space(Project p, BYTE word) { if(p->nbc!=0) { ULONG nbc = word ? backward_word(p->edited,p->nbc-1) : p->nbc-1; rem_chars(&p->undo, p->edited, nbc, p->nbc-1); /* Set cursor position and redraws it */ inv_curs(p,FALSE); REDRAW_CURLINE(p); p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc=nbc); p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left; if( (nbc = center_horiz(p)) != p->left_pos ) scroll_xy(p, nbc, p->top_line, FALSE); inv_curs(p,TRUE); draw_info( p ); } else if(p->edited->prev != NULL) { p->edited = p->edited->prev; p->nbc = p->edited->size; /* Join previous and current line */ if( join_lines(&p->undo, p->edited, p->edited->next) ) { /* Move cursor to the end of previous line */ p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc); p->max_lines--; p->nbl--; /* Require to scroll the display? */ inv_curs(p, FALSE); if(p->ycurs>gui.topcurs) scroll_up(p, p->edited->next, p->ycurs-=YSIZE, center_horiz(p)); else p->top_line--, p->show = p->edited, p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left; SetAPen(RP, pen.fg); REDRAW_CURLINE(p); /* Redraw the cursor: */ inv_curs(p,TRUE); draw_info(p); prop_adj(p); } else ThrowError(Wnd, ErrMsg(ERR_NOMEM)); } }
static int update_list(int count) { struct COOR *new_ptr1, *new_ptr2, *new_ptr3; G_debug(3, "update_list: count:%d row:%d col:%d", count, row, col - 1); switch (count) { case 0: G_debug(1, "Isolated cell (%d,%d)", row, col); break; case 1: /* begin or end line */ if (ml) h_ptr = end_line(h_ptr, 0); if (tl) v_list[col].left = end_line(v_list[col].left, 0); if (tc) v_list[col].center = end_line(v_list[col].center, 0); if (tr) v_list[col].right = end_line(v_list[col].right, 0); if (mr) h_ptr = start_line(0); if (br) v_list[col + 1].left = start_line(0); if (bc) v_list[col].center = start_line(0); if (bl) v_list[col - 1].right = start_line(0); break; case 2: /* straight or bent line */ if (tl != 0 && br != 0) { /* slanted line (\) */ v_list[col + 1].left = v_list[col].left; v_list[col].left = NULL; } else if (tr != 0 && bl != 0) { /* slanted line (/) */ v_list[col - 1].right = v_list[col].right; v_list[col].right = NULL; } /* first take care of the cases where both non-zero neighbours are in a upper-left corner (cw from ml to tr) */ else if (ml != 0 && tc != 0) { /* bend (_|) */ join_lines(h_ptr, v_list[col].center); h_ptr = v_list[col].center = NULL; } else if (ml != 0 && tr != 0) { /* bend (_/) */ join_lines(h_ptr, v_list[col].right); h_ptr = v_list[col].left = NULL; } else if (tl != 0 && tr != 0) { /* bend (\/) */ join_lines(v_list[col].left, v_list[col].right); v_list[col].left = v_list[col].right = NULL; } else if (tl != 0 && tc != 0) /* bend (\|) */ v_list[col].center = end_line(v_list[col].center, 1); else if (tr != 0 && tc != 0) /* bend |/ */ v_list[col].center = end_line(v_list[col].center, 1); else if (tl != 0 && ml != 0) h_ptr = end_line(h_ptr, 1); /* now take care of the cases when non-zero neighbours are next to nonzero neighbours in a top-left corner */ else if (bl != 0 && ml != 0) v_list[col].center = start_line(1); else if (tr != 0 && mr != 0) h_ptr = start_line(1); else if (!((tc != 0 && bc != 0) || (ml != 0 && mr != 0))) /* if not horiz or vertical line */ { /* one of the non zero neighbours is in the top left corner, and the other one is one of bl - mr, not next to the first one */ if (ml || tl || tc || tr) { /* old line bends toward *//* new area */ new_ptr1 = get_ptr(); if (ml) { /* join new to where came from */ if (h_ptr == NULL) G_debug(1, "h_ptr is NULL!"); /* this should never happen by the logic of algorithm */ extend_line(h_ptr, new_ptr1); h_ptr = NULL; } else if (tl) { if (v_list[col].left == NULL) G_debug(1, "v_list[col].left is NULL!"); /* this should never happen by the logic of algorithm */ extend_line(v_list[col].left, new_ptr1); v_list[col].left = NULL; } else if (tc) { if (v_list[col].center == NULL) G_debug(1, "v_list[col].center is NULL!"); /* this should never happen by the logic of algorithm */ extend_line(v_list[col].center, new_ptr1); v_list[col].center = NULL; } else { /* tr */ if (v_list[col].right == NULL) G_debug(1, "v_list[col].right is NULL!"); /* this should never happen by the logic of algorithm */ extend_line(v_list[col].right, new_ptr1); v_list[col].right = NULL; } if (mr) /* find out where going */ /* tr is 0 here */ h_ptr = new_ptr1; else if (br) v_list[col + 1].left = new_ptr1; else if (bc) v_list[col].center = new_ptr1; else /* bl, ml is 0 here */ v_list[col - 1].right = new_ptr1; } else { /* lower-left */ /* if the non-zero neigbours are adjacent */ if (mr && br) h_ptr = start_line(1); else if ((br && bc) || (bl && bc)) v_list[col].center = start_line(1); else /* the non-zero neigbours are not adjacent */ { /* starting in middle of line */ new_ptr1 = get_ptr(); new_ptr2 = get_ptr(); new_ptr3 = get_ptr(); new_ptr1->fptr = new_ptr2; new_ptr1->bptr = new_ptr3; new_ptr3->bptr = new_ptr2->bptr = new_ptr1; if (mr && bc) { h_ptr = new_ptr2; v_list[col].center = new_ptr3; } else if (mr && bl) { h_ptr = new_ptr2; v_list[col - 1].right = new_ptr3; } else if (bl && br) { v_list[col - 1].right = new_ptr3; v_list[col + 1].left = new_ptr2; } } /* starting in the middle of the line */ } } else if (value_flag) { /* horizontal or vertical line */ int ml_val, mc_val, mr_val; /* horiz */ int tc_val, bc_val; /* vert */ ml_val = mc_val = mr_val = tc_val = bc_val = 0; /* only CELL supported */ if (data_type == CELL_TYPE) { ml_val = ((CELL *) middle)[col - 1]; mc_val = ((CELL *) middle)[col]; mr_val = ((CELL *) middle)[col + 1]; tc_val = ((CELL *) top)[col]; bc_val = ((CELL *) bottom)[col]; } if ((mc && mr) && mc_val != mr_val) { /* break the horizontal line */ h_ptr = end_line(h_ptr, 1); h_ptr = start_line(1); } else if ((mc && bc) && mc_val != bc_val) { /* break the vertical line */ v_list[col].center = end_line(v_list[col].center, 1); v_list[col].center = start_line(1); } if ((mc && ml) && mc_val != ml_val) { h_ptr->bptr->val = mc_val; } else if ((mc && tc) && mc_val != tc_val) { v_list[col].center->bptr->val = mc_val; } } break; case 3: if (ml || tl || tc || (tr && !mr)) { if (ml) /* stop horz. and vert. lines */ h_ptr = end_line(h_ptr, 1); if (tc) v_list[col].center = end_line(v_list[col].center, 1); /* stop diag lines if no horz,vert */ if ((tl) && (!ml) && (!tc)) v_list[col].left = end_line(v_list[col].left, 1); if ((tr) && (!mr) && (!tc)) v_list[col].right = end_line(v_list[col].right, 1); } if (mr) /* start horz. and vert */ h_ptr = start_line(1); if (bc) v_list[col].center = start_line(1); /* start diag if no horz,vert */ if ((br) && (!mr) && (!bc)) v_list[col + 1].left = start_line(1); if ((bl) && (!ml) && (!bc)) v_list[col - 1].right = start_line(1); break; case 4: if (ml) /* end horz. and vert lines */ h_ptr = end_line(h_ptr, 1); if (tc) v_list[col].center = end_line(v_list[col].center, 1); /* end diag lines only if no horz,vert */ if ((tl) && (!ml) && (!tc)) v_list[col].left = end_line(v_list[col].left, 1); if ((tr) && (!mr) && (!tc)) v_list[col].right = end_line(v_list[col].right, 1); if (mr) /* start horz. and vert */ h_ptr = start_line(1); if (bc) v_list[col].center = start_line(1); /* start diag if no horz,vert */ if ((br) && (!mr) && (!bc)) v_list[col + 1].left = start_line(1); if ((bl) && (!ml) && (!bc)) if (bl) v_list[col - 1].right = start_line(1); break; case 5: /* G_message(_("crowded cell %xH (%d,%d) -continuing"),count,row,col); */ /* I think 5 neighbours is nor crowded, so we shouldn't worry the user Olga */ if (ml) /* end horz. and vert lines */ h_ptr = end_line(h_ptr, 1); if (tc) v_list[col].center = end_line(v_list[col].center, 1); /* end diag lines only if no horz,vert */ if ((tl) && (!ml) && (!tc)) v_list[col].left = end_line(v_list[col].left, 1); if ((tr) && (!mr) && (!tc)) v_list[col].right = end_line(v_list[col].right, 1); if (mr) /* start horz. and vert */ h_ptr = start_line(1); if (bc) v_list[col].center = start_line(1); /* start diag if no horz,vert */ if ((br) && (!mr) && (!bc)) v_list[col + 1].left = start_line(1); if ((bl) && (!ml) && (!bc)) v_list[col - 1].right = start_line(1); break; case 6: /* the same as case 5 */ G_debug(1, "Crowded cell %xH (%d,%d), continuing", count, row, col); if (ml) /* end horz. and vert lines */ h_ptr = end_line(h_ptr, 1); if (tc) v_list[col].center = end_line(v_list[col].center, 1); /* end diag lines only if no horz,vert */ if ((tl) && (!ml) && (!tc)) v_list[col].left = end_line(v_list[col].left, 1); if ((tr) && (!mr) && (!tc)) v_list[col].right = end_line(v_list[col].right, 1); if (mr) /* start horz. and vert */ h_ptr = start_line(1); if (bc) v_list[col].center = start_line(1); /* start diag if no horz,vert */ if ((br) && (!mr) && (!bc)) v_list[col + 1].left = start_line(1); if ((bl) && (!ml) && (!bc)) v_list[col - 1].right = start_line(1); break; default: G_message(_("Crowded cell at (%f, %f): row %d, col %d, count %d"), Rast_col_to_easting((double)col - .5, &cell_head), Rast_row_to_northing((double)row + .5, &cell_head), row, col - 1, count); G_fatal_error(_("Raster map is not thinned properly.\nPlease run r.thin.")); } /* switch count */ return 0; }
/* execute the next command in command buffer; return error status */ static int exec_command( const char ** const ibufpp, const int prev_status, const bool isglobal ) { const char * fnp; int gflags = 0; int addr, c, n; const int addr_cnt = extract_addr_range( ibufpp ); if( addr_cnt < 0 ) return ERR; *ibufpp = skip_blanks( *ibufpp ); c = *(*ibufpp)++; switch( c ) { case 'a': if( !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( !append_lines( ibufpp, second_addr, isglobal ) ) return ERR; break; case 'c': if( first_addr == 0 ) first_addr = 1; if( second_addr == 0 ) second_addr = 1; if( !check_current_addr( addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( !delete_lines( first_addr, second_addr, isglobal ) || !append_lines( ibufpp, current_addr(), isglobal ) ) return ERR; break; case 'd': if( !check_current_addr( addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( !delete_lines( first_addr, second_addr, isglobal ) ) return ERR; inc_current_addr(); break; case 'e': if( modified() && !scripted() && prev_status != EMOD ) return EMOD; /* fall through */ case 'E': if( unexpected_address( addr_cnt ) || unexpected_command_suffix( **ibufpp ) ) return ERR; fnp = get_filename( ibufpp ); if( !fnp || !delete_lines( 1, last_addr(), isglobal ) || !close_sbuf() ) return ERR; if( !open_sbuf() ) return FATAL; if( fnp[0] && fnp[0] != '!' ) set_def_filename( fnp ); if( traditional() && !fnp[0] && !def_filename[0] ) { set_error_msg( "No current filename" ); return ERR; } if( read_file( fnp[0] ? fnp : def_filename, 0 ) < 0 ) return ERR; reset_undo_state(); set_modified( false ); break; case 'f': if( unexpected_address( addr_cnt ) || unexpected_command_suffix( **ibufpp ) ) return ERR; fnp = get_filename( ibufpp ); if( !fnp ) return ERR; if( fnp[0] == '!' ) { set_error_msg( "Invalid redirection" ); return ERR; } if( fnp[0] ) set_def_filename( fnp ); printf( "%s\n", strip_escapes( def_filename ) ); break; case 'g': case 'v': case 'G': case 'V': if( isglobal ) { set_error_msg( "Cannot nest global commands" ); return ERR; } n = ( c == 'g' || c == 'G' ); /* mark matching lines */ if( !check_addr_range( 1, last_addr(), addr_cnt ) || !build_active_list( ibufpp, first_addr, second_addr, n ) ) return ERR; n = ( c == 'G' || c == 'V' ); /* interactive */ if( ( n && !get_command_suffix( ibufpp, &gflags ) ) || !exec_global( ibufpp, gflags, n ) ) return ERR; break; case 'h': case 'H': if( unexpected_address( addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( c == 'H' ) verbose = !verbose; if( ( c == 'h' || verbose ) && errmsg[0] ) fprintf( stderr, "%s\n", errmsg ); break; case 'i': if( second_addr == 0 ) second_addr = 1; if( !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( !append_lines( ibufpp, second_addr - 1, isglobal ) ) return ERR; break; case 'j': if( !check_addr_range( current_addr(), current_addr() + 1, addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( first_addr != second_addr && !join_lines( first_addr, second_addr, isglobal ) ) return ERR; break; case 'k': n = *(*ibufpp)++; if( second_addr == 0 ) { invalid_address(); return ERR; } if( !get_command_suffix( ibufpp, &gflags ) || !mark_line_node( search_line_node( second_addr ), n ) ) return ERR; break; case 'l': case 'n': case 'p': if( c == 'l' ) n = GLS; else if( c == 'n' ) n = GNP; else n = GPR; if( !check_current_addr( addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) || !display_lines( first_addr, second_addr, gflags | n ) ) return ERR; gflags = 0; break; case 'm': if( !check_current_addr( addr_cnt ) || !get_third_addr( ibufpp, &addr ) ) return ERR; if( addr >= first_addr && addr < second_addr ) { set_error_msg( "Invalid destination" ); return ERR; } if( !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( !move_lines( first_addr, second_addr, addr, isglobal ) ) return ERR; break; case 'P': case 'q': case 'Q': if( unexpected_address( addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( c == 'P' ) prompt_on = !prompt_on; else if( modified() && !scripted() && c == 'q' && prev_status != EMOD ) return EMOD; else return QUIT; break; case 'r': if( unexpected_command_suffix( **ibufpp ) ) return ERR; if( addr_cnt == 0 ) second_addr = last_addr(); fnp = get_filename( ibufpp ); if( !fnp ) return ERR; if( !isglobal ) clear_undo_stack(); if( !def_filename[0] && fnp[0] != '!' ) set_def_filename( fnp ); if( traditional() && !fnp[0] && !def_filename[0] ) { set_error_msg( "No current filename" ); return ERR; } addr = read_file( fnp[0] ? fnp : def_filename, second_addr ); if( addr < 0 ) return ERR; if( addr ) set_modified( true ); break; case 's': if( !command_s( ibufpp, &gflags, addr_cnt, isglobal ) ) return ERR; break; case 't': if( !check_current_addr( addr_cnt ) || !get_third_addr( ibufpp, &addr ) || !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( !copy_lines( first_addr, second_addr, addr ) ) return ERR; break; case 'u': if( unexpected_address( addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) || !undo( isglobal ) ) return ERR; break; case 'w': case 'W': n = **ibufpp; if( n == 'q' || n == 'Q' ) ++*ibufpp; if( unexpected_command_suffix( **ibufpp ) ) return ERR; fnp = get_filename( ibufpp ); if( !fnp ) return ERR; if( addr_cnt == 0 && last_addr() == 0 ) first_addr = second_addr = 0; else if( !check_addr_range( 1, last_addr(), addr_cnt ) ) return ERR; if( !def_filename[0] && fnp[0] != '!' ) set_def_filename( fnp ); if( traditional() && !fnp[0] && !def_filename[0] ) { set_error_msg( "No current filename" ); return ERR; } addr = write_file( fnp[0] ? fnp : def_filename, ( c == 'W' ) ? "a" : "w", first_addr, second_addr ); if( addr < 0 ) return ERR; if( addr == last_addr() ) set_modified( false ); else if( modified() && !scripted() && n == 'q' && prev_status != EMOD ) return EMOD; if( n == 'q' || n == 'Q' ) return QUIT; break; case 'x': if( second_addr < 0 || last_addr() < second_addr ) { invalid_address(); return ERR; } if( !get_command_suffix( ibufpp, &gflags ) ) return ERR; if( !isglobal ) clear_undo_stack(); if( !put_lines( second_addr ) ) return ERR; break; case 'y': if( !check_current_addr( addr_cnt ) || !get_command_suffix( ibufpp, &gflags ) || !yank_lines( first_addr, second_addr ) ) return ERR; break; case 'z': first_addr = 1; if( !check_addr_range( first_addr, current_addr() + ( traditional() || !isglobal ), addr_cnt ) ) return ERR; if( **ibufpp > '0' && **ibufpp <= '9' ) { if( parse_int( &n, *ibufpp, ibufpp ) ) set_window_lines( n ); else return ERR; } if( !get_command_suffix( ibufpp, &gflags ) || !display_lines( second_addr, min( last_addr(), second_addr + window_lines() ), gflags ) ) return ERR; gflags = 0; break; case '=': if( !get_command_suffix( ibufpp, &gflags ) ) return ERR; printf( "%d\n", addr_cnt ? second_addr : last_addr() ); break; case '!': if( unexpected_address( addr_cnt ) ) return ERR; fnp = get_shell_command( ibufpp ); if( !fnp ) return ERR; if( system( fnp + 1 ) < 0 ) { set_error_msg( "Can't create shell process" ); return ERR; } if( !scripted() ) printf( "!\n" ); break; case '\n': first_addr = 1; if( !check_addr_range( first_addr, current_addr() + ( traditional() || !isglobal ), addr_cnt ) || !display_lines( second_addr, second_addr, 0 ) ) return ERR; break; case '#': while( *(*ibufpp)++ != '\n' ) ; break; default : set_error_msg( "Unknown command" ); return ERR; } if( gflags && !display_lines( current_addr(), current_addr(), gflags ) ) return ERR; return 0; }