Injection of the "more" Unix command
I am trying to implement a command more
. I want to know how I can tell if there is a pipe. For example, if I type from the shell
cat file1 file2 | more
how can i handle this inside the implementation more?
And is the implementation implemented more
as open source?
Actually I was unable to achieve reading stdin. I managed to make more file.txt but not cat | more ..
I think I should first read from the user and place the buffer than print the buffer. my code contains:
if(argc == 1)
{
fgets(line, 255, 0);
printf("%s", line);
}
but it gives an error.
source to share
The bigger the syntax
more [options] [file_name]
If you do not provide a filename, the command takes more input from stdin; you can provide this input (via stdin) using a pipe like:
cat file.txt | more
This sends the output of the cat command into more . This is the same as doing:
more file.txt
You don't need to know specifically if there is a pipe or not; you just need to check if the filename was passed as an argument anymore . If so, then the input is considered the content of the file. If not, the input is assumed to come from stdin.
As far as source code is concerned, some searches will go a long way. Here are some older FreeBSD sources:
http://svnweb.freebsd.org/base/stable/2.0.5/usr.bin/more/
Or a more recent source from the Ubuntu repositories:
http://bazaar.launchpad.net/~vcs-imports/util-linux-ng/trunk/files/head:/text-utils/
source to share