【Linux开发习作】more命令的编写(1)

简介: 作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ /* * ===================================================================================== * * Filename: more01.

 作者:gnuhpc 
出处:http://www.cnblogs.com/gnuhpc/

/*
* =====================================================================================
*
* Filename: more01.c
*
* Description: A User Version of Command more
*
* Version: 1.0
* Created: 12/03/2008 06:36:56 PM
* Revision: none
* Compiler: gcc
*
* Author: Futuredaemon (BUPT),gnuhpc@gmail.com
* Company: BUPT_UNITED
*
* =====================================================================================
*/

#include <stdlib.h>
#include <stdio.h>


#define PAGELEN 24 /*The number of pape to be printed */
#define LINELEN 512 /*The length of Line to be printed */

void do_more(FILE *);
int see_more(FILE *);

int main ( int argc, char *argv[] )
{
FILE *fp; /* File Descriptor */
if ( argc ==1 ) /* If no files exist,use the keyboard */
do_more(stdin);
else
while(--argc)
if((fp=fopen(*++argv,"r"))!=NULL)
{
do_more(fp);
fclose(fp);
}
else
exit(1);
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */

void do_more(FILE *fp)
{
char line[LINELEN];
int num_of_lines=0;
int reply;
FILE *fp_tty;
fp_tty = fopen( "/dev/tty" , "r");
if (fp_tty==NULL)
exit(1);

while(fgets( line,LINELEN,fp))
{
if( num_of_lines == PAGELEN)
{
reply = see_more(fp_tty);
if( reply == 0)
break;
num_of_lines-=reply;
}

if( fputs (line,stdout)==EOF)
exit(1);
num_of_lines++;
}

}

int see_more(FILE *cmd)
{
int c;
printf("/033[7m more? /033[m");
while((c=getc(cmd))!=EOF)
{
//printf("This is a test!");
if(c == 'q')
return 0;
if(c == ' ')
return PAGELEN;
if(c == '/n')
return 1;
}
return 0;
}


               作者:gnuhpc
               出处:http://www.cnblogs.com/gnuhpc/
               除非另有声明,本网站采用知识共享“署名 2.5 中国大陆”许可协议授权。


分享到:

目录
相关文章
|
5天前
|
Linux 编译器 Android开发
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
在Linux环境下,本文指导如何交叉编译x265的so库以适应Android。首先,需安装cmake和下载android-ndk-r21e。接着,下载x265源码,修改crosscompile.cmake的编译器设置。配置x265源码,使用指定的NDK路径,并在配置界面修改相关选项。随后,修改编译规则,编译并安装x265,调整pc描述文件并更新PKG_CONFIG_PATH。最后,修改FFmpeg配置脚本启用x265支持,编译安装FFmpeg,将生成的so文件导入Android工程,调整gradle配置以确保顺利运行。
24 1
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
|
5天前
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
|
15天前
|
NoSQL Linux Shell
常用的 Linux 命令
常用的 Linux 命令
36 9
|
2天前
|
监控 Linux Windows
50个必知的Linux命令技巧,你都掌握了吗?(下)
50个必知的Linux命令技巧,你都掌握了吗?(下)
|
2天前
|
Linux Shell Windows
Linux 常用基本命令
Linux 常用基本命令
|
3天前
|
Ubuntu Linux Shell
linux免交互登陆远程主机并执行命令(密钥对和Expect)
linux免交互登陆远程主机并执行命令(密钥对和Expect)
|
3天前
|
Linux
【Linux】常用命令
【Linux】常用命令
24 0
|
3天前
|
安全 Ubuntu Linux
Linux 网络操作命令Telnet
Linux 网络操作命令Telnet
16 0
Linux 网络操作命令Telnet
|
4天前
|
Linux 数据安全/隐私保护
Linux常用命令实例带注释
Linux常用命令实例带注释
30 0
|
4天前
|
Linux 开发工具 数据安全/隐私保护
Linux(19)常用解压命令记录
Linux(19)常用解压命令记录
9 0