#include "tdestr.h"
#include "common.h"
#include "tdefunc.h"
#include "define.h"
int mark_block( WINDOW *window )
{
int type;
int num;
long lnum;
register file_infos *file; /* 临时文件 */
register WINDOW *win; /* 把当前窗口指针放到一个临时寄存器里面 */
int rc;
win = window;
file = win->file_info;
if (win->rline > file->length || win->ll->len == EOF)
return( ERROR );
if (g_status.marked == FALSE) {
g_status.marked = TRUE;
g_status.marked_file = file;
}
if (g_status.command == MarkBox)
type = BOX;
else if (g_status.command == MarkLine)
type = LINE;
else if (g_status.command == MarkStream)
type = STREAM;
else
return( ERROR );
rc = OK;
/*
* 仅对于一个文件定义块。用户可以在这个文件的任何窗口进行操作。
*/
if (file == g_status.marked_file) {
/*
* 不管块的模式标识块的起始和中止位置
*/
if (file->block_type == NOTMARKED) {
file->block_ec = file->block_bc = win->rcol;
file->block_er = file->block_br = win->rline;
} else {
if (file->block_br > win->rline) {
file->block_br = win->rline;
if (file->block_bc < win->rcol && type != STREAM)
file->block_ec = win->rcol;
else
file->block_bc = win->rcol;
} else {
if (type != STREAM) {
file->block_ec = win->rcol;
file->block_er = win->rline;
} else {
if (win->rline == file->block_br &&
win->rline == file->block_er) {
if (win->rcol < file->block_bc)
file->block_bc = win->rcol;
else
file->block_ec = win->rcol;
} else if (win->rline == file->block_br)
file->block_bc = win->rcol;
else {
file->block_ec = win->rcol;
file->block_er = win->rline;
}
}
}
/*
* 如果用户标识的块的终止位置在起始位置前,那么交换两个位置。
*/
if (file->block_er < file->block_br) {
lnum = file->block_er;
file->block_er = file->block_br;
file->block_br = lnum;
}
/*
* 如果用户标识的块的终止列在起始列前,那么交换两个位置。
*/
if ((file->block_ec < file->block_bc) && (type != STREAM ||
(type == STREAM && file->block_br == file->block_er))) {
num = file->block_ec;
file->block_ec = file->block_bc;
file->block_bc = num;
}
}
/*
* 如果块类型已经被定义,但是如果用户使用混和模式,那么块的
* 类型被置为当前块的类型
*/
if (file->block_type != NOTMARKED) {
/*
* 如果块的类型是矩形块,那么要保证左上角小于右下脚
* 如果块的类型是stream块,那么保证起始列小于中止列
*/
if (type == BOX) {
if (file->block_ec < file->block_bc) {
num = file->block_ec;
file->block_ec = file->block_bc;
file->block_bc = num;
}
}
}
assert( file->block_er >= file->block_br );
file->block_type = type;
file->dirty = GLOBAL;
} else {
/*
* 已经定义好块
*/
error( WARNING, win->bottom_line, block1 );
rc = ERROR;
}
return( rc );
}
/*
* Name: unmark_block
* Class: primary editor function
* Purpose: To set all block information to NULL or 0
* Date: June 5, 1991
* Passed: arg_filler: variable to match array of function pointers prototype
* Notes: Reset all block variables if marked, otherwise return.
* If a marked block is unmarked then redraw the screen(s).
*/
int unmark_block( WINDOW *arg_filler )
{
register file_infos *marked_file;
if (g_status.marked == TRUE) {
marked_file = g_status.marked_file;
g_status.marked = FALSE;
g_status.marked_file = NULL;
marked_file->block_start = NULL;
marked_file->block_end = NULL;
marked_file->block_bc = marked_file->block_ec = 0;
marked_file->block_br = marked_file->block_er = 0l;
if (marked_file->block_type)
marked_file->dirty = GLOBAL;
marked_file->block_type = NOTMARKED;
}
return( OK );
}
/*
* Name: restore_marked_block
* Class: helper function
* Purpose: To restore block beginning and ending row after an editing function
* Date: June 5, 1991
* Passed: window: pointer to current window
* net_change: number of bytes added or subtracted
* Notes: If a change has been made before the marked block then the
* beginning and ending row need to be adjusted by the number of
* lines added or subtracted from file.
*/
void restore_marked_block( WINDOW *window, int net_change )
{
long length;
register file_infos *marked_file;
if (g_status.marked == TRUE && net_change != 0) {
marked_file = g_status.marked_file;
length = marked_file->length;
/*
* restore is needed only if a block is defined and window->file_info is
* same as marked file and there was a net change in file length.
*/
if (marked_file == window->file_info) {
/*
* if cursor is before marked block then adjust block by net change.
*/
if (marked_file->block_br > window->rline) {
marked_file->block_br += net_change;
marked_file->block_er += net_change;
marked_file->dirty = GLOBAL;
/*
* if cursor is somewhere in marked block don't restore, do redisplay
*/
} else if (marked_file->block_er >= window->rline)
marked_file->dirty = GLOBAL;
/*
* check for lines of marked block beyond end of file
*/
if (marked_file->block_br > length)
unmark_block( window );
else if (marked_file->block_er > length) {
marked_file->block_er = length;
marked_file->dirty = GLOBAL;
}
}
}
}
/*
* Name: prepare_block
* Class: helper function
* Purpose: To prepare a window/file for a block read, move or copy.
* Date: June 5, 1991
* Passed: window: pointer to current window
* file: pointer to file information.
* text_line: pointer to line in file to prepare.
* lend: line length.
* bc: beginning column of BOX.
* Notes: The main complication is that the cursor may be beyond the end
* of the current line, in which case extra padding spaces have
* to be added before the block operation can take place.
* this only occurs in BOX and STREAM operations.
* since we are padding a line, do not trim trailing space.
*/
int prepare_block( WINDOW *window, line_list_ptr ll, int bc )
{
register int pad = 0; /* amount of padding to be added */
register int len;
assert( bc >= 0 );
assert( bc < MAX_LINE_LENGTH );
assert( ll->len != EOF );
assert( g_status.copied == FALSE );
copy_line( ll );
detab_linebuff( );
len = g_status.line_buff_len;
pad = bc - len;
if (pad > 0) {
/*
* insert the padding spaces
*/
assert( pad >= 0 );
assert( pad < MAX_LINE_LENGTH );
memset( g_status.line_buff+len, ' ', pad );
g_status.line_buff_len += pad;
}
/*
* if mode.inflate_tabs, let's don't entab the line until we get
* thru processing this line, e.g. copying, numbering....
*/
return( un_copy_line( ll, window, FALSE ) );
}
/*
* Name: pad_dest_line
* Class: helper function
* Purpose: To prepare a window/file for a block move or copy.
* Date: June 5, 1991
* Passed: window: pointer to current window
* dest_file: pointer to file information.
* dest_line: pointer to line in file
没有合适的资源?快使用搜索试试~ 我知道了~
C语言经典示例.zip
共554个文件
c:248个
exe:206个
dat:52个
0 下载量 69 浏览量
2023-08-17
15:27:50
上传
评论
收藏 3.37MB ZIP 举报
温馨提示
C语言经典示例,包含200多个示例 ----- 毕业设计,课程设计,项目源码均经过助教老师测试,运行无误,欢迎下载交流 ----- 下载后请首先打开README.md文件(如有),某些链接可能需要魔法打开。 ----- 毕业设计,课程设计,项目源码均经过助教老师测试,运行无误,欢迎下载交流 ----- 下载后请首先打开README.md文件(如有),某些链接可能需要魔法打开。
资源推荐
资源详情
资源评论
收起资源包目录
C语言经典示例.zip (554个子文件)
SIMUL101.ASM 13KB
INT24.ASM 13KB
151.bmp 34KB
BLOCK.C 84KB
UTILS.C 73KB
ED.C 61KB
FILE.C 61KB
CONSOLE.C 48KB
FINDREP.C 42KB
WINDOW.C 35KB
REGX.C 32KB
CFGFILE.C 30KB
WORDWRAP.C 29KB
DIRLIST.C 28KB
220.C 27KB
TAB.C 24KB
TDECFG.C 23KB
MACRO.C 23KB
MICROCAD.C 22KB
DIFF.C 22KB
214.C 21KB
SORT.C 20KB
Library.c 18KB
CFGKEYS.C 14KB
215.C 14KB
CFGCOLOR.C 14KB
CFGMODES.C 13KB
211.C 12KB
HWIND.C 12KB
MAIN.C 11KB
MCPRINT.C 11KB
210.C 10KB
216.C 9KB
MCDRAW.C 8KB
212.C 8KB
41.c 6KB
213.C 6KB
PORT.C 6KB
207.C 6KB
84.c 6KB
50.C 6KB
163.C 6KB
TDEASM.C 5KB
107.c 5KB
60.c 5KB
208.C 5KB
148.C 5KB
71.c 5KB
66.C 5KB
54.c 5KB
67.c 4KB
36.c 4KB
209.C 4KB
119.C 4KB
69.c 4KB
12.c 4KB
CRITERR.C 4KB
65.C 4KB
39.C 3KB
115.C 3KB
161.C 3KB
72.c 3KB
111.c 3KB
116.C 3KB
64.c 3KB
153.C 3KB
151.C 3KB
70.c 3KB
108.c 2KB
114.c 2KB
144.C 2KB
98.C 2KB
100.C 2KB
154.C 2KB
62.c 2KB
55.c 2KB
112.c 2KB
CFGHELP.C 2KB
57.c 2KB
157.C 2KB
145.C 2KB
16.c 2KB
142.C 2KB
104.C 2KB
77.c 2KB
160.C 2KB
102.C 2KB
164.C 2KB
105.c 2KB
143.C 2KB
CFGMACRO.C 2KB
93.C 2KB
49.C 2KB
118.C 2KB
40.c 2KB
59.c 2KB
94.c 2KB
58.c 2KB
34.c 2KB
110.c 2KB
共 554 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Lau师傅
- 粉丝: 138
- 资源: 107
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Javascript的诊所管理系统设计源码
- 人工智能在电子信息管理系统中的应用与效率优化研究
- 详解protobuf-c之在C语言中如何使用repeated生成数组和字符串(包含配置pb-callback-t)
- Python 程序语言设计模式思路-并发模式:消费者模式:协调生产者和消费者之间的数据交换
- pythonA*算法(A-star algorithm),寻路算法
- guitest.zip
- udp_echo.v
- udp_echo_server.v
- python双向广度优先搜索算法(Bidirectional Breadth-First Search, BBFS),寻路算法
- python迭代加深算法(Iterative Deepening Depth-First Search, IDDFS),寻路算法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功