1 / 16

Gzip 简介及命令行参数导读

Gzip 简介及命令行参数导读. 吴廷鹏 060912. 提纲. Gzip 简介 Gzip 各文件的主要功能 Gzip 命令行参数用法 Gzip 命令行参数处理导读 实验一. Gzip 简介. GZIP 是一个用于压缩的工具,比起其他的压缩工具,它有更好的压缩效果并可以获得源码。 GZIP 最早由 Jean-loup Gailly 和 Mark Adler 创建,用于 UNIX 系统的文件压缩。我们在 Linux 中经常会用到后缀为 .gz 的文件,它们就是 GZIP 格式的。现今已经成为 Internet 上使用非常普遍的一种数据压缩格式。 原理

quanda
Download Presentation

Gzip 简介及命令行参数导读

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Gzip简介及命令行参数导读 吴廷鹏 060912

  2. 提纲 • Gzip简介 • Gzip各文件的主要功能 • Gzip命令行参数用法 • Gzip命令行参数处理导读 • 实验一

  3. Gzip简介 • GZIP是一个用于压缩的工具,比起其他的压缩工具,它有更好的压缩效果并可以获得源码。GZIP最早由Jean-loup Gailly和Mark Adler创建,用于UNIX系统的文件压缩。我们在Linux中经常会用到后缀为.gz的文件,它们就是GZIP格式的。现今已经成为Internet上使用非常普遍的一种数据压缩格式。 • 原理 ftp://pb0511:pb0511@202.38.79.124:221/gzip

  4. Gzip各文件的主要功能 • Gzip.c: 程序入口 • Deflate.c: 实现文件压缩功能的函数集合,提供对文件压缩的支持 • Inflate.c: 实现文件解压功能的函数集合,提供对文件解压的支持 • Zip.c: 将文件压缩成gzip格式 • Unzip: 解压gzip或pkzip格式的文件 • Unlzh.c:解压lzh格式的文件 • Unlzw.c:解压lzw格式的文件 • Unpack.c:解压pack格式的文件

  5. Gzip各文件的主要功能 • Bits.c: 提供对位操作的支持 • Getopt.c: 提供对参数解析的支持 • Trees.c: huffman树相关的操作集合,包括创建新树选择树的类型等 • Tailor.c、Tailor.h: 配置文件,用于支持多种编译环境 • Util.c: 工具函数集合,包括对缓冲区的操作,错误处理,文件名的处理等。

  6. Gzip各文件的主要功能 • Gzip的实现原理分析和文件中各函数的主要功能详解参见 ftp://pb0511:pb0511@202.38.79.124:221/gzip

  7. -a --ascii ascii text; convert end-of-lines using local conventions -c --stdout write on standard output, keep original files unchanged -d --decompress decompress -f --force force overwrite of output file and compress links -h --help give this help -l --list list compressed file contents -L --license display software license -n --no-name do not save or restore the original name and time stamp -N --name save or restore the original name and time stamp -q --quiet suppress all warnings -S .suf use suffix .suf on compressed files -t --test test compressed file integrity -v --verbose verbose mode -V --version display version number -1 --fast compress faster -9 --best compress better Gzip命令行参数用法

  8. Gzip命令行参数用法 • Gzip命令的基本用法: >gzip test.txt 生成test.gz的压缩文件,同时不再保留test.txt >gzip -d test.gz 解压test.gz,生成test.txt文件 • 基本用法的缺点: 压缩文件覆盖原文件

  9. Gzip命令行参数用法 • -c: 不改变原文件,将压缩结果标准输出 >gzip –c test.txt • 不改变原文件,同时创建压缩文件 >gzip –c test.txt > test.txz

  10. Gzip命令行参数用法 • -f: 覆盖已经存在的输出文件 • -l: 给出压缩文件大小及压缩率信息 • -L: Gzip的软件许可证信息 • -q: 忽略所有的警告提示 • -S: 指定压缩文件后缀 • -t: 测试压缩文件的完整性 • -v: 给出文件名和压缩率信息 • -V: 给出Gzip的版本信息 • -1: 快速压缩模式 • -9: 最佳压缩模式

  11. Gzip命令行参数处理导读 程序所在位置: Gzip.c的main函数中。 argc: 参数的个数 argv: 指向字符串的指针数组 >gzip.exe –d –N test.txz 0 1 2 3 集成环境中输入的第一个参数是argv[1] int main (argc, argv) int argc; char *argv[];

  12. Gzip命令行参数处理导读 basename是util.c中的函数,用于取文件名 progname=basename(“d:\gzipproj\gzip.exe”); progname值为”gzip.exe” progname = basename(argv[0]); proglen = strlen(progname); /* Suppress .exe for MSDOS, OS/2 and VMS: */ if (proglen > 4 && strequ(progname+proglen-4, ".exe")) { progname[proglen-4] = '\0'; }

  13. while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789", longopts, (int *)0)) != EOF) { switch (optc) { case 'c': to_stdout = 1; break; case 'd': decompress = 1; break; case 'h': case 'H': case '?': help(); do_exit(OK); break; case 'l': list = decompress = to_stdout = 1; break; case 'L': license(); do_exit(OK); break; case 'N': no_name = no_time = 0; break; case 'q': quiet = 1; verbose = 0; break; …… } } 可选参数的提取: getopt_long() 可选参数对程序的影响:变量值的改变 >gzip.exe –d –N –q test.txz 解析命令行参数的具体细节可参Getopt.c中函数_getopt_internal()的注释部分

  14. 实验一 • 目的 1.熟悉VC、BC等编程环境,学会单步跟踪、调试自己的程序; 2.了解project的创建、使用以及意义; 3.熟练定义含指向结构体自身的指针域的结构体类型 4.熟练使用C中的动态分配与释放函数(malloc, realloc, free); 5.熟悉带参数的main函数的编写与运行; 6.类C的引用参数在C中的变换处理; 7.利用输入导向,从文件中获取输入数据。 8.深入理解线性表的特性,掌握它在不同存储结构、不同约定下,其 本操作的实现方法与差异

  15. 实验内容 • 下载Gzip的源代码,选择一个C开发工具,编译运行Gzip • 下载ch2.rar并阅读其中的代码。利用ch2.rar中的内容完成自己的实验。 • 阅读《数据结构题集》P79 1.2约瑟夫环,理解约瑟夫环的定义。编写一个程序,该程序根据输入的命令行参数创建一个单循环链表表示的约瑟夫环,然后输出约瑟夫环出列的顺序。命令行格式:〈可执行程序名〉〈人数n〉〈初始的报数上限m〉〈密码1〉 …… 〈密码n〉

  16. Thanks!

More Related