listing_9_13.c

来自「This source code has been tested under O」· C语言 代码 · 共 81 行

C
81
字号
/*************************************************************************                                                                    ****  listing_9_13.c                                                    ****                                                                    ****  File Browser, Edition 1. This program uses a Scrolled Text        ****  widget to replace more(1). It accepts a single file on the        ****  command line, and displays the contents of that file in the       ****  text widget.                                                      ****                                                                    *************************************************************************/#include <stdio.h>#include <Xm/Text.h>void	LoadFile();			/* FORWARD Definition	      */Widget	appshell,			/* Application Shell	      */	the_text;			/* The text widget            */void main( argc, argv )    int     argc;    char    *argv[];{    appshell = XtInitialize( argv[0], "Listing_9_13", NULL, 0, &argc, argv );    if (argc != 2)        {	fprintf( stderr, "\nbrowser: Usage:\n" );	fprintf( stderr, "         browser FILENAME\n" );	exit( 1 );	}    the_text = XmCreateScrolledText( appshell, "TheText", NULL, 0 );    XtManageChild( the_text );    LoadFile( argv[1] );    XtRealizeWidget( appshell );    XtMainLoop();}/***** LoadFile( fname )****** This function opens the file and loads it into the text widget.**/void LoadFile( fname )    char    	*fname;{    FILE	*infile;    long    	fsize;    char    	*lclptr;    infile = fopen( fname, "r" );    if (infile == NULL)        {	perror( "browser: unable to open input file" );	exit( 2 );	}    fseek( infile, 0, 2 );    fsize = ftell( infile );    rewind( infile );    lclptr = (char *)XtMalloc( fsize + 1 );    fread( lclptr, sizeof(char), fsize, infile );    lclptr[fsize] = '\0';    XmTextSetString( the_text, lclptr );    XtFree( lclptr );    fclose( infile );}

⌨️ 快捷键说明

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