linux more源码,急需 linux下 more 命令的源码!谢谢

急需 linux下 more 命令的源码!谢谢。

在http://ftp.gnu.org/gnu/coreutils/没有找到,请问哪儿有?谢谢!

|

在这个包里 util-linux-ng

http://www.kernel.org/pub/linux/utils/util-linux-ng/v2.14/util-linux-ng-2.14.1.tar.bz2

|

/* vi: set sw=4 ts=4: */

/*

* Mini more implementation for busybox

*

* Copyright (C) 1995, 1996 by Bruce Perens .

* Copyright (C) 1999-2004 by Erik Andersen

*

* Latest version blended together by Erik Andersen ,

* based on the original more implementation by Bruce, and code from the

* Debian boot-floppies team.

*

* Termios corrects by Vladimir Oleynik

*

* Licensed under GPLv2 or later, see file License in this tarball for details.

*/

#include "libbb.h"

#if ENABLE_FEATURE_USE_TERMIOS

#include

#endif /* FEATURE_USE_TERMIOS */

#if ENABLE_FEATURE_USE_TERMIOS

struct globals {

int cin_fileno;

struct termios initial_settings;

struct termios new_settings;

};

#define G (*(struct globals*)bb_common_bufsiz1)

#define INIT_G() ((void)0)

#define initial_settings (G.initial_settings)

#define new_settings     (G.new_settings    )

#define cin_fileno       (G.cin_fileno      )

#define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp)

#define getTermSettings(fd, argp) tcgetattr(fd, argp)

static void gotsig(int sig ATTRIBUTE_UNUSED)

{

bb_putchar('n');

setTermSettings(cin_fileno, &initial_settings);

exit(EXIT_FAILURE);

}

#else /* !FEATURE_USE_TERMIOS */

#define INIT_G() ((void)0)

#define setTermSettings(fd, argp) ((void)0)

#endif /* FEATURE_USE_TERMIOS */

#define CONVERTED_TAB_SIZE 8

int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;

int more_main(int argc ATTRIBUTE_UNUSED, char **argv)

{

int c = c; /* for gcc */

int lines;

int input = 0;

int spaces = 0;

int please_display_more_prompt;

struct stat st;

FILE *file;

FILE *cin;

int len;

int terminal_width;

int terminal_height;

INIT_G();

argv++;

/* Another popular pager, most, detects when stdout

* is not a tty and turns into cat. This makes sense. */

if (!isatty(STDOUT_FILENO))

return bb_cat(argv);

cin = fopen(CURRENT_TTY, "r");

if (!cin)

return bb_cat(argv);

#if ENABLE_FEATURE_USE_TERMIOS

cin_fileno = fileno(cin);

getTermSettings(cin_fileno, &initial_settings);

new_settings = initial_settings;

new_settings.c_lflag &= ~ICANON;

new_settings.c_lflag &= ~ECHO;

new_settings.c_cc[VMIN] = 1;

new_settings.c_cc[VTIME] = 0;

setTermSettings(cin_fileno, &new_settings);

bb_signals(0

+ (1  terminal_width);

if (c == 'n' || wrap) {

/* Then outputting this character

* will move us to a new line. */

if (++lines >= terminal_height || input == 'n')

please_display_more_prompt = 1;

len = 0;

}

if (c != 'n' && wrap) {

/* Then outputting this will also put a character on

* the beginning of that new line. Thus we first want to

* display the prompt (if any), so we skip the putchar()

* and go back to the top of the loop, without reading

* a new character. */

goto loop_top;

}

/* My small mind cannot fathom backspaces and UTF-8 */

putchar(c);

}

fclose(file);

fflush(stdout);

} while (*argv && *++argv);

end:

setTermSettings(cin_fileno, &initial_settings);

return 0;

}

busybox里的

|

/* more01.c  - version 0.1 of more

*        read and print 24 lines then pause for a few special commands

*/

#include

#define        PAGELEN        24

#define        LINELEN        512

void do_more(FILE *);

int  see_more();

int main( int ac , char *av[] )

{

FILE        *fp;

if ( ac == 1 )

do_more( stdin );

else

while ( --ac )

if ( (fp = fopen( *++av , "r" )) != NULL )

{

do_more( fp ) ;

fclose( fp );

}

else

exit(1);

return 0;

}

void do_more( FILE *fp )

/*

*  read PAGELEN lines, then call see_more() for further instructions

*/

{

char        line[LINELEN];

int        num_of_lines = 0;

int        see_more(), reply;

while ( fgets( line, LINELEN, fp ) ){                /* more input        */

if ( num_of_lines == PAGELEN ) {        /* full screen?        */

reply = see_more();                /* y: ask user  */

if ( reply == 0 )                /*    n: done   */

break;

num_of_lines -= reply;                /* reset count        */

}

if ( fputs( line, stdout )  == EOF )        /* show line        */

exit(1);                        /* or die        */

num_of_lines++;                                /* count it        */

}

}

int see_more()

/*

*        print message, wait for response, return # of lines to advance

*        q means no, space means yes, CR means one line

*/

{

int        c;

printf("33[7m more? 33[m");                /* reverse on a vt100        */

while( (c=getchar()) != EOF )                        /* get response        */

{

if ( c == 'q' )                        /* q -> N                */

return 0;

if ( c == ' ' )                        /* ' ' => next page        */

return PAGELEN;                /* how many to show        */

if ( c == 'n' )                /* Enter key => 1 line        */

return 1;

}

return 0;

}

==================================

*  more02.c  - version 0.2 of more

*        read and print 24 lines then pause for a few special commands

*      feature of version 0.2: reads from /dev/tty for commands

*/

#include

#define        PAGELEN        24

#define        LINELEN        512

void do_more(FILE *);

int see_more(FILE *);

int main( int ac , char *av[] )

{

FILE        *fp;

if ( ac == 1 )

do_more( stdin );

else

while ( --ac )

if ( (fp = fopen( *++av , "r" )) != NULL )

{

do_more( fp ) ;

fclose( fp );

}

else

exit(1);

return 0;

}

void do_more( FILE *fp )

/*

*  read PAGELEN lines, then call see_more() for further instructions

*/

{

char        line[LINELEN];

int        num_of_lines = 0;

int        see_more(FILE *), reply;

FILE        *fp_tty;

fp_tty = fopen( "/dev/tty", "r" );           /* NEW: cmd stream   */

if ( fp_tty == NULL )                           /* if open fails     */

exit(1);                           /* no use in running */

while ( fgets( line, LINELEN, fp ) ){                /* more input        */

if ( num_of_lines == PAGELEN ) {        /* full screen?        */

reply = see_more(fp_tty);  /* NEW: pass FILE *  */

if ( reply == 0 )                /*    n: done   */

break;

num_of_lines -= reply;                /* reset count        */

}

if ( fputs( line, stdout )  == EOF )        /* show line        */

exit(1);                        /* or die        */

num_of_lines++;                                /* count it        */

}

}

printf("33[7m more? 33[m");                /* reverse on a vt100        */

while( (c=getc(cmd)) != EOF )                /* NEW: reads from tty  */

{

if ( c == 'q' )                        /* q -> N                */

return 0;

if ( c == ' ' )                        /* ' ' => next page        */

return PAGELEN;                /* how many to show        */

if ( c == 'n' )                /* Enter key => 1 line        */

return 1;

}

return 0;

}

|

楼上的是引用Unix/Linux编程实践教程的源代码吧,这个书是作者自己写的不完整的,请问现在linux版的真实源代码在那?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值