The more command has three uses:
1.more filename
2.command | More
3.more < filename
This example is used when using./more_1 execution can also copy more_1 to/bin file, equivalent to adding a new command
more_1.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define LINE_LENGTH 512#define page_length 24int See_more (file* fp_cmd) {if (Fp_cmd = = NULL) printf ("Error stop\n"); Char ch; printf ("\033[7m more? \033[m ");//vt100 programming, detailed reference on-line while ((ch = getc (fp_cmd)) = NULL)//Read {if (ch = = ' Q ') return 0 from the terminal; if (ch = = ") return page_length;; if (ch = = ' \ n ') return 1; } return 0;} void Do_more (file* fp) {int line_num = 0; Char Line_buf[line_length]; int reply; File* Fp_tty; if (Fp_tty = fopen ("/dev/tty", "r") = = NULL)//parentheses are used, no amplification will be wrong perror ("open TTY error!\n"); while (Fgets (LINE_BUF,LINE_LENGTH,FP)) {if (Line_num = = page_length) {reply = See_more (Fp_tty); if (reply = = 0) break; if (reply = = page_length) line_num = 0; if (reply = = 1) liNe_num--; } if (fputs (line_buf,stdout) = = EOF) exit (-1); line_num++; } fclose (Fp_tty);} int main (int argc,char* argv[]) {file* fp; if (argc = = 1) {printf ("Usage:more [-DFLPCSU] [+linenum | +/pattern] name1 name2 ... \ n "); Exit (0); } else {while (--ARGC) {fp = fopen (* ++argv, "R"); if (fp! = NULL) {do_more (FP); Fclose (FP); } else Perror ("Open eror!\n"); } }}
Legacy issue: Anti-white display with case input bounce display
Percent display
To press ENTER to execute
We'll do it later.
Simple implementation of Linux programming more commands