Linux: more
已实现:more filename , quit不需要回车
未实现:command | more 重定向 ,显示百分比
Waiting。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* 2 Linux: more 3 已实现:more filename , quit不需要回车 4 未实现:command | more 重定向 ,显示百分比 5 Waiting。。。 6 */ 7 #include<stdio.h> 8 #define PAGELEN 24 9 #define LINELEN 512 10 void do_more( FILE * ); 11 int see_more(); 12 int main( int ac,char *av[] ){ 13 FILE * fp; 14 if( ac==1 ) 15 do_more( stdin ); 16 else{ 17 while( --ac ) 18 if( (fp=fopen(* ++av,"r"))!=NULL ){ 19 do_more( fp ); 20 fclose( fp ); 21 } 22 else{ 23 exit( 1 ); 24 } 25 } 26 return 0; 27 } 28 29 void do_more( FILE *fp ){ 30 char line[ LINELEN ]; 31 int num_of_lines = 0; 32 int see_more(),reply; 33 while( fgets( line,LINELEN,fp ) ){ 34 if( num_of_lines == PAGELEN ){ 35 reply = see_more(); 36 if( reply == 0 ){ 37 break; 38 } 39 num_of_lines -= reply ; 40 } 41 if( fputs( line,stdout )==EOF ){ 42 exit( 1 ); 43 }/* 标准输入输出 */ 44 num_of_lines ++; 45 } 46 } 47 48 int see_more(){ 49 int c; 50 system ("stty -F /dev/tty cbreak");/*打开/dev/tty作为输入终端,并且控制属性为不需要回车*/ 51 printf("