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

📄 050-054.html

📁 The primary purpose of this book is to explain various data-compression techniques using the C progr
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>The Data Compression Book-:The Dawn Age: Minimum Redundancy Coding</TITLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><SCRIPT><!--function displayWindow(url, width, height) {        var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes');}//--></SCRIPT></HEAD><BODY  BGCOLOR="#FFFFFF" VLINK="#DD0000" TEXT="#000000" LINK="#DD0000" ALINK="#FF0000"><TD WIDTH="540" VALIGN="TOP"><!--  <CENTER><TABLE><TR><TD><FORM METHOD="GET" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-foldocsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE="Glossary Search"></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD><TD><IMG SRC="http://www.itknowledge.com/images/dotclear.gif" WIDTH="15"   HEIGHT="1"></TD><TD><FORM METHOD="POST" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-subscriptionsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE="  Book Search  "></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="backlink" TYPE="hidden" VALUE="http://search.itknowledge.com:80/excite/AT-subscriptionquery.html"><INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD></TR></TABLE></CENTER> --><!-- ISBN=1558514341//--><!-- TITLE=The Data Compression Book-//--><!-- AUTHOR=Mark Nelson//--><!-- PUBLISHER=IDG Books Worldwide, Inc.//--><!-- IMPRINT=M & T Books//--><!-- CHAPTER=3//--><!-- PAGES=050-054//--><!-- UNASSIGNED1//--><!-- UNASSIGNED2//--><CENTER><TABLE BORDER><TR><TD><A HREF="046-050.html">Previous</A></TD><TD><A HREF="../ewtoc.html">Table of Contents</A></TD><TD><A HREF="054-057.html">Next</A></TD></TR></TABLE></CENTER><P><BR></P><H4 ALIGN="LEFT"><A NAME="Heading8"></A><FONT COLOR="#000077">MAIN-C.C</FONT></H4><P>There are a few expectations about how MAIN-C.C will run. MAIN-C.C is called to compress an input file supplied on the command line and send the compressed output to another file, also supplied on the command line. Thus, the basic command-line invocation of MAIN-C.C is MAIN-C input-file output-file. If the user invokes MAIN-C.C without any arguments, a simple usage statement prints out. The usage statement includes the usage string supplied by the compression module.</P><P>If two likely looking file names are on the command line, MAIN-C.C tries to open them both. The input file is opened as a standard file specified in STDIO.H, using fopen(). The output file is opened as a BIT_FILE, as defined in BITIO.H. If either file doesn&#146;t open, an error message is printed out and the program exits. If both files open, the next step is to call the compression routine.</P><P>MAIN-C.C expects the compression routine to be named CompressFile(). This routine is called with four arguments. The first two are pointers to the file structure for the input file and a pointer to the BIT_FILE structure for the output file. Finally, the updated values for argc and argv are passed to the compression routine. The values for argc and argv will have been adjusted to go past argv[0], which should be the program name, as well as argv[1] and argv[2], the names of the input and output files. The compression program can then scan the remaining arguments for any arguments specific to that particular compression routine. After the compression routine has finished, it returns to MAIN-C.C, which closes down the files and exits.</P><P>MAIN-E.C is the converse program to MAIN-C.C. It takes two arguments as well, but this time the input file is the compressed file and the output file is destined to be the uncompressed clear text file. Just like MAIN-C.C, it checks to be sure there are at least two arguments, then tries to open the two files. If there aren&#146;t two arguments, a usage message is printed. If either of the files fails to open, an error message is printed. MAIN-E.C is listed below.</P><!--  CODE //--><PRE>/***********************Start of MAIN-E.C***********************/* This driver program tests compression algorithms.  To cut back on* repetitive code, this version of main is used with all the expansion* routines.  The main() routine supplied here checks for valid input and* output files, opens them, then calls the compression routine.**/#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt;#include &lt;string.h&gt;#include "bitio.h"#include "errhand.h"#include "main.h"#ifdef__STDC__void usage_exit( char *prog_name );#elsevoid usage_exit();#endifint main( argc, argv )int argc;char *argv[];&#123;     FILE *output;     BIT_FILE *input;     setbuf( stdout, NULL );     if  ( argc &lt; 3 )        usage_exit( argv[ 0 ] );     input = OpenInputBitFile( argv[ 1 ] );     if ( input == NULL )          fatal_error( "Error opening %s for input\n", argv[ 1 ]     output = fopen( argv[ 2 ], "wb" );     if ( output == NULL )          fatal_error( "Error opening %s for output\n", argv[ 2 ]     printf( "\nExpanding %s to %s for output\n", argv[ 2 ] );     printf( "Using %\n", CompressionName );     argc -= 3;     argv &#43;= 3;     ExpandFile( input, output, argc, argv );     CloseInputBitFile( input );     fclose( output );     putc( '\n', stdout );     return( 0 );&#125;/** This routine wants to print out the usage message called for when the* program is run with no parameters.  The first part of the Usage state* ment is supposed to be just the programname. argv[ 0 ] generally holds* the fully qualified path name of the program being run.*/void usage_exit( prog_name )char *prog_name;&#125;     char *short_name;     char *extension;     short_name = strrchr( prog_name, '\\' );     if ( short_name = = NULL )          short_name = = strrchr( prog_name, '/' );     if ( short_name = = NULL )          short_name = strrchr( prog_name, ':' );     if ( short_name != NULL )         short_name&#43;&#43;;     else        short_name = prog_name;     extension = strrchr( short_name, '.' );     if ( extension != NULL )          *extension = '\0';     printf( "\nUsage: %s %s\n", short_name, Usage );     exit( 0 );&#125;/********************** End of MAIN-E.C**************************/</PRE><!--  END CODE //--><H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">ERRHAND.C</FONT></H4><P>One additional routine helps simplify the code. A production version of a program generally needs a somewhat sophisticated error-handling mechanism. In particular, it is important to let the end user know what is happening, clean up any files that may have been only partially processed, and restore any system settings that may have been changed.</P><P>In this book, our interest in compression concentrates on testing for accuracy, speed, and compression ratios. Because of this, we have created a simple universal fatal-error handler. The error handler is defined in ERRHAND.H:</P><!--  CODE //--><PRE>/********************** Start of ERRHAND.H **********************/     #ifndef _ERRHAND_H     #define _ERRHAND_H     #ifdef ___STDC___     void fatal_error( char *fmt, ... );     #else /* ___STDC___ */     void fatal_error();     #endif /* ___STDC___ */     #endif /* _ERRHAND_H *//********************** End of ERRHAND.H *************************/</PRE><!--  END CODE //--><P>The fatal-error handler is called when an unrecoverable error occurs in the program. It has the same syntax as printf, which means it can be passed a format string and arguments to format and print out.</P><!--  CODE //--><PRE>/************************ Start of ERRHAND.C ***********************/#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt;#include &lt;stdarg.h&gt;#include "errhand.h"#ifdef __STDC__void fatal_error( char *fmt, ... )#else#ifdef __UNIX__void fatal_error( fmt )char *fmt;va_dcl#elsevoid fatal_error( fmt )#endif#endif&#123;     va_list argptr;     va_start( argptr, fmt );     printf( "Fatal error: " );     vprintf( fmt, argptr  );     va_end( argptr );     exit( -1 );&#125;/************************ End of ERRHAND.C ***********************/</PRE><!--  END CODE //--><P><BR></P><CENTER><TABLE BORDER><TR><TD><A HREF="046-050.html">Previous</A></TD><TD><A HREF="../ewtoc.html">Table of Contents</A></TD><TD><A HREF="054-057.html">Next</A></TD></TR></TABLE></CENTER></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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