日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux---More命令 初级实现

發布時間:2024/6/14 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux---More命令 初级实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Linux: more
已實現:more filename , quit不需要回車
未實現:command | more 重定向 ,顯示百分比
Waiting。。。

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("\033[7m more?\033[m"); 52 while( (c=getchar())!=EOF ){ 53 if( c=='q' ){ 54 return 0; 55 } 56 if( c==' ' ){ 57 return PAGELEN; 58 } 59 if( c=='\n' ){ 60 return 1; 61 } 62 } 63 system ("stty -F /dev/tty -cbreak");/*恢復終端屬性為需要回車*/ 64 return 0; 65 } View Code

?

轉載于:https://www.cnblogs.com/xxx0624/p/3360130.html

總結

以上是生活随笔為你收集整理的Linux---More命令 初级实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。