⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zlibhelp.c

📁 unix下的界面工具
💻 C
字号:
/*****************************************************************************/
/*            DEMO PROGRAM FOR ZLIB VERSION 1.0 - BROWSE FUNCTION            */
/* ------------------------------------------------------------------------- */
/*  Author : Shih Ho ( 何  轼 )                                              */
/*  Date   : August 14, 1995                                                 */
/*****************************************************************************/

#include <stdio.h>
#include <string.h>
#include <zlib.h>

/*===========================================================================*/
/* Constant Definition                                                       */
/*---------------------------------------------------------------------------*/
#define KEY_SIZE    20
#define REF_SIZE    64
#define REF_LINE    13
#define REC_SIZE    ( REF_LINE * ( REF_SIZE + 1 ) + ( KEY_SIZE + 1 ) )
#define BROWSE_ROWS 4
#define BROWSE_COLS 3

/*===========================================================================*/
/* Function Definition                                                       */
/*---------------------------------------------------------------------------*/
static void DispLine( int );
static int  Refresh();

/*===========================================================================*/
/* Data Area                                                                 */
/*---------------------------------------------------------------------------*/
static FILE *fp;                /* Text file handler for IO                  */
static int  RecNo;              /* Record number of the first line on screen */
static int  RecPtr;             /* Being located record number               */
static int  RecCnt;             /* Record count of the text file             */
static int  RefFlag;            /* Refresh flag                              */
static char Buf[80];            /* String buffer                             */

/*===========================================================================*/
/* Local Function - Set Record Number                                        */
/*---------------------------------------------------------------------------*/
static int SetRecord( int n )
{
  if( n < 0 || n >= RecCnt )
    return( -1 );
  RecPtr = n;
  return( 0 );
}

/*===========================================================================*/
/* Local Function - Display Browse Screen                                    */
/*---------------------------------------------------------------------------*/
static void DispScreen()
{
  int i;

  ZWprintf( 0, 0,
      "┏━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓" );
  ZWprintf( 1, 0, "┃%s│%s│%s┃",
      " 公用函数类型及名称 ", " 公用函数类型及名称 ", " 公用函数类型及名称 " );
  ZWprintf( 2, 0,
      "┠──────────┼──────────┼──────────┨" );
  for( i = 0; i < BROWSE_ROWS; i ++ )
    ZWprintf( i + 3, 0,
        "┃%*s│%*s│%*s┃", KEY_SIZE, "", KEY_SIZE, "", KEY_SIZE, "" );
  ZWprintf( BROWSE_ROWS + 3, 0,
      "┠──────────┴──────────┴──────────┨" );
  for( i = 0; i < REF_LINE; i ++ )
    ZWprintf( i + BROWSE_ROWS + 4, 0, "┃%-*s┃", REF_SIZE, "" );
  ZWprintf( REF_LINE + BROWSE_ROWS + 4, 0, 
      "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛" );
}

/*===========================================================================*/
/* Local Function - Display A Key Line                                       */
/*---------------------------------------------------------------------------*/
static int GetLine( int n )
{
  if( n == 0 )
    RecNo = RecPtr;
  return( 0 );
}

/*===========================================================================*/
/* Local Function - Goto Specified Record                                    */
/*---------------------------------------------------------------------------*/
static int SpecLine( int n )
{
  return( SetRecord( RecNo + n ) );
}

/*===========================================================================*/
/* Local Function - Goto First Record                                        */
/*---------------------------------------------------------------------------*/
static int FirstLine()
{
  return( SetRecord( 0 ) );
}

/*===========================================================================*/
/* Local Function - Goto Last Recrod                                         */
/*---------------------------------------------------------------------------*/
static int LastLine()
{
  return( SetRecord( RecCnt - 1 ) );
}

/*===========================================================================*/
/* Local Function - Goto Previous Record                                     */
/*---------------------------------------------------------------------------*/
static int PrevLine()
{
  return( SetRecord( RecPtr - 1 ) );
}

/*===========================================================================*/
/* Local Function - Goto Next Record                                         */
/*---------------------------------------------------------------------------*/
static int NextLine()
{
  return( SetRecord( RecPtr + 1 ) );
}

/*===========================================================================*/
/* Local Function - Cursor Line Change                                       */
/*---------------------------------------------------------------------------*/
static void CursorChange()
{
  RefFlag = 1;
}

/*===========================================================================*/
/* Data Area                                                                 */
/*---------------------------------------------------------------------------*/
static ZWINDOW Window = {
  1, 2, 22, 76, ZW_BOX, " ZLIB公用函数使用说明 "
};
static ZBUTTON Button[] = {
  {  0,  0, 0, 0, 0,        UP,    0, 0 },
  {  0,  0, 0, 0, 0,        DOWN,  0, 0 },
  {  0,  0, 0, 0, 0,        LEFT,  0, 0 },
  {  0,  0, 0, 0, 0,        RIGHT, 0, 0 },
  {  0,  0, 0, 0, 0,        HOME,  0, 0 },
  {  0,  0, 0, 0, 0,        END,   0, 0 },
  {  0,  0, 0, 0, 0,        PGUP,  0, 0 },
  {  0,  0, 0, 0, 0,        PGDN,  0, 0 },
  {  1, 69, 1, 6, 0,        '8',   0, 0 },
  {  3, 69, 1, 6, 0,        '2',   0, 0 },
  {  5, 69, 1, 6, 0,        '4',   0, 0 },
  {  7, 69, 1, 6, 0,        '6',   0, 0 },
  { 10, 69, 1, 6, 0,        '7',   0, 0 },
  { 12, 69, 1, 6, 0,        '1',   0, 0 },
  { 14, 69, 1, 6, 0,        '9',   0, 0 },
  { 16, 69, 1, 6, 0,        '3',   0, 0 },
  { 20, 69, 1, 6, "5-退出", '5',   0, 0 }
};
static ZSCREEN Screen = {
  sizeof( Button ) / sizeof( ZBUTTON ), Button, 0, 0, Refresh
};
static ZBROWSE Browse = {
  &Window, &Screen, BROWSE_ROWS, BROWSE_COLS, 0, 0,
  DispScreen, 0, 0, GetLine, 0, DispLine,
  SpecLine, FirstLine, LastLine, PrevLine, NextLine,
  0, CursorChange, 0
};

/*===========================================================================*/
/* Local Function - Display A Key Line                                       */
/*---------------------------------------------------------------------------*/
static void DispLine( int n )
{
  if( n >= Browse.lc )
    strcpy( Buf, "" );
  else{
    fseek( fp, ( RecNo + n ) * REC_SIZE, SEEK_SET );
    fgets( Buf, KEY_SIZE + 1, fp );
  }
  ZWprintf( n / BROWSE_COLS + 3, ( n % BROWSE_COLS ) * ( KEY_SIZE + 2 ) + 2,
      "%-*s", KEY_SIZE, Buf );
}

/*===========================================================================*/
/* Local Function - Refresh Detail                                           */
/*---------------------------------------------------------------------------*/
static int Refresh()
{
  int i;

  if( RefFlag ){
    RefFlag = 0;
    for( i = 0; i < REF_LINE; i ++ ){
      fseek( fp, ( RecNo + Browse.cl ) * REC_SIZE + i * ( REF_SIZE + 1 )
          + ( KEY_SIZE + 1 ), SEEK_SET );
      fgets( Buf, REF_SIZE + 1, fp );
      ZWprintf( i + BROWSE_ROWS + 4, 2, "%-*s", REF_SIZE, Buf );
    }
    ZWlocate( Browse.cl / BROWSE_COLS + 3,
        ( Browse.cl % BROWSE_COLS ) * ( KEY_SIZE + 2 ) + 2 );
  }
  return( 0 );
}

/*===========================================================================*/
/* Main Program                                                              */
/*---------------------------------------------------------------------------*/
void main()
{
  int r;

  if( Zinit( 0, 0 ) != 0 )
    printf( "Failed on initialize environment!\n" );
  else{
    if( ( fp = fopen( "zlib.txt", "r" ) ) == NULL )
      Zerror( 10, 28, "待演示文本操作失败!" );
    else{
      fseek( fp, 0, SEEK_END );
      RecCnt = ftell( fp ) / REC_SIZE;
      fseek( fp, 0, SEEK_SET );
      RefFlag = 0;
      r = Zbrowse( &Browse );
      fclose( fp );
      if( r == 0 )
        Zerror( 10, 30, "浏览器演示失败!" );
    }
    Zexit();
  }
}

/*****************************************************************************/

⌨️ 快捷键说明

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