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

📄 392-394.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-:An Archiving Package</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=12//--><!-- PAGES=392-394//--><!-- UNASSIGNED1//--><!-- UNASSIGNED2//--><CENTER><TABLE BORDER><TR><TD><A HREF="388-392.html">Previous</A></TD><TD><A HREF="../ewtoc.html">Table of Contents</A></TD><TD><A HREF="395-398.html">Next</A></TD></TR></TABLE></CENTER><P><BR></P><H3><A NAME="Heading9"></A><FONT COLOR="#000077">Generating the File List</FONT></H3><P>One of the basic requirements of CARMAN is that it be able to handle lists of files, so that it can perform operations on select groups of files. Every one of the seven CARMAN commands accepts a list of files as an argument, so we need to have a general purpose way to build and manage a list of files. The list function should also be able to accommodate at least some level of wild card pattern matching as well.</P><P>Wild card matching needs to be done a little differently under MS-DOS and UNIX. First of all, there are actually two types of wild card matching taking place in CARMAN. File specifications on the command line with the &#145;Add&#146; command, including wild cards, specify external files that are going to be added to the CAR file. File specifications for all of the other commands refer to files stored inside the CAR file. Thus we have to handle these two types of file lists using slightly different methods.</P><P>To complicate further, UNIX and MS-DOS differ significantly in the way their command lines handle wild card file specifications. Under either operating system, if we want to add all the C files in a directory to an archive, we would type a similar command:</P><!--  CODE SNIP //--><PRE>carman a c_files.car *.c</PRE><!--  END CODE SNIP //--><P>Under UNIX, the command interpreter, or shell program, expands the list of wild card file names before the program ever sees it. This means that by the time CARMAN is invoked, it is presented with a command line that might look something like this:</P><!--  CODE SNIP //--><PRE>carman a c_files.car test.c io.c foo.c bar.c</PRE><!--  END CODE SNIP //--><P>This is one of the nice features of UNIX; an application program doesn&#146;t have to worry about wild card expansion of files from the command line because the shell takes care of the work.</P><P>Under MS-DOS, matters are a little more complicated. Wild card expansion is thought of as being the province of an application program, not the command-line interpreter. So code that builds the file name list has to perform the expansion manually using C run-time library functions. Even worse, the function names and structure definitions used to expand wild card listings have not been standardized among compiler vendors, so that each new compiler needs a slightly different implementation.</P><P>In CARMAN, the list of the file names is found in an array called FileList[]. FileList is an array of character pointers which is set up via a routine called BuildFileList(). BuildFileList() is called right after the command line is parsed, and is passed a list of command-line arguments, along with a count.</P><P>BuildFileList() normally just copies the arguments passed to it into the FileList[] array. If there are no command-line arguments, FileList[0] is set to &#145;*&#146;, so that all file names in the archive will be matched as they are processed. This has the effect of converting a command like &#147;CARMAN L TEST.CAR&#148; to &#147;CARMAN L TEST.CAR *&#148;.</P><P>BuildFileList() changes its mode of operation if the user has specified that the command is &#145;A,&#146; to add files, and the operating system is MS-DOS. Under these circumstances, a special routine is called to expand a potential wild-card file specification into a list of file names, with the results all being stored in the FileList[].</P><!--  CODE //--><PRE>void BuildFileList( argc, argv, command )int argc;char *argv[];int command;{ int i; int count; count = 0; if ( argc == 0 )    FileList[ count++ ] = "*"; else {    for ( i = 0 ; &lt; argc ; i++ ) {#ifdef MSDOS      if ( command == 'A' )       count = ExpandAndMassageMSDOSFileNames (count, argv[ i ]);      else       MassageMSDOSFileName( count++, argv[ i ] );#endif#ifndef MSDOS  FileList[ count ] = malloc( strlen( argv[ i ] ) + 2);  if ( FileList[ count ] == NULL )    FatalError( "Ran out of memory storing file names" );  strcpy( FileList[ count++ ], argv[ i ];#endif  if ( count &gt; 99 )    FatalError( "Too many file names" );  } } FileList[ count ] = NULL;}</PRE><!--  END CODE //--><P>In addition, a special routine called MassageMSDOSFileName() is called to normalize all MS-DOS file names. MS-DOS has a couple of complications in its file system. First of all, file names are case insensitive, meaning that &#147;FOO.BAR&#148; and &#147;foo.bar&#148; both refer to the same file, despite the fact that their names are different. Secondly, the 8&#43;3 file naming convention means that &#147;FOO&#148; and &#147;FOO.&#148; both refer to the same file, even though one has a trailing &#145;.&#146; character and the other doesn&#146;t.</P><P>Massage MSDOSFileName() gets around this problem by performing two operations on file names. First of all, uppercase characters in file names on the command line are all converted to lowercase, to avoid ambiguities created by case mismatches. Secondly, any file that doesn&#146;t have an extension or a &#145;.&#146; in the name has a &#145;.&#146; character appended to the end of its name. Note that if the file name contains a &#145;*&#146; or &#145;?&#146; character, meaning it is a wild card, the &#145;.&#146; character is not appended to a file name with no extension.</P><P><BR></P><CENTER><TABLE BORDER><TR><TD><A HREF="388-392.html">Previous</A></TD><TD><A HREF="../ewtoc.html">Table of Contents</A></TD><TD><A HREF="395-398.html">Next</A></TD></TR></TABLE></CENTER></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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