_more.h

来自「Unix shell是unix的命令解释程序」· C头文件 代码 · 共 74 行

H
74
字号
#include<sys/stat.h>#include<sys/types.h>#include<sys/wait.h>#include<unistd.h>#include<stdlib.h>#include<stdio.h>#include<string.h>#include<signal.h>#include<dirent.h>void _more(char *str){	char c[4];	long pos[100];	int i=0,n=0;	FILE *file=fopen(str,"r+");		if(file==NULL)	{		printf("can not open file %s\n",str);		return;	}	char buf[80];	int tag=1;		for(i=0;i<23;i++)	{		if(!fgets(buf,80,file))			{			tag=0;			break;		}		else			fputs(buf,stdout);	}		pos[n] = ftell(file);	printf("pos[%d] : %d\n",n,pos[n]);	n = n+1;	printf("%s","input \'b\' to quit:");	while( fgets(c,4,stdin) && tag)	{		if(c[0] == 'b' || c[0] == 'B')		{			if(n == 1 || n == 2)			{				fseek(file,0,SEEK_SET);				n=0;			}			else{				fseek(file,pos[n-3],SEEK_SET);				n=n-2;			}					}		for(i=0;i<23;i++)		{			if(!fgets(buf,80,file))			{																																	tag=0;									break;}	else			{				fputs(buf,stdout);			}					}			pos[n] = ftell(file);		printf("pos[%d] : %d\n",n,pos[n]);		n = n+1;		c[0] = 0;		printf("%s","input \'b\' to quit:");	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?