1#include <stdio.h>2#include <stdlib.h>3 4 #definePagelen 245 #defineLinelen 5126 7 intSee_more (file*);8 voidDo_more (file*);9 Ten intMainintAcChar*av[]) One { AFILE *FP; - if(ac==1) - Do_more (stdin); the //printf ("%s", "Please input file name.\n"); - Else - { - while(--AC) + if(Fp=fopen (*++av,"R"))!=NULL) - { + Do_more (FP); A fclose (FP); at } - } - - - } - in voidDo_more (file*FP) - { to intnum_of_lines=0; + CharLine[linelen]; - intreply; the //int See_more (); *file*Fp_tty; $Fp_tty=fopen ("/dev/tty","R");Panax Notoginseng if(Fp_tty==null) Exit (1); - while(Fgets (LINE,LINELEN,FP)) the { + if(num_of_lines==Pagelen) A { thereply=See_more (fp_tty); + if(reply==0) - Break; $num_of_lines-=reply; $ } - if(fputs (line,stdout) = =EOF) -Exit1); thenum_of_lines++; - }Wuyi the } - Wu intSee_more (file*cmd) - { About intC; $ //printf ("\033[7m more? \033[m "); -printf"\033[32;49;1m [more?] \033[39;49;0m"); - //033[32;49;1m [more?] \033[39;49;0m - while((c=getc (cmd))! =EOF) A { + if(c=='Q') the return 0; - $ if(c=='\ n') the return 1; the the if(c==' ') the returnPagelen; - } in}
Implement more Commands yourself