1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>rawtxt2z.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center>
<hr><h1>rawtxt2z.cpp</h1><div class="fragment"><pre>00001 <font class="preprocessor">#include <ctype.h></font>
00002 <font class="preprocessor">#include <stdio.h></font>
00003 <font class="preprocessor">#include <fcntl.h></font>
00004 <font class="preprocessor">#include <errno.h></font>
00005 <font class="preprocessor">#include <stdlib.h></font>
00006
00007 <font class="preprocessor">#ifndef __GNUC__</font>
00008 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font>
00009 <font class="preprocessor">#else</font>
00010 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font>
00011 <font class="preprocessor">#endif</font>
00012 <font class="preprocessor"></font>
00013 <font class="preprocessor">#include <swcomprs.h></font>
00014
00015
00016 main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00017 {
00018 SWCompress *zobj;
00019 <font class="keywordtype">int</font> ifd, ofd, ixfd, oxfd;
00020 <font class="keywordtype">long</font> offset, loffset, lzoffset;
00021 <font class="keywordtype">short</font> size, lsize, lzsize;
00022 <font class="keywordtype">char</font> *tmpbuf;
00023
00024 <font class="keywordflow">if</font> (argc != 2) {
00025 fprintf(stderr, <font class="stringliteral">"usage: %s <datafilename>\n"</font>, argv[0]);
00026 exit(1);
00027 }
00028
00029 zobj = <font class="keyword">new</font> SWCompress();
00030
00031 <font class="preprocessor">#ifndef O_BINARY</font>
00032 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00034 <font class="preprocessor"></font>
00035 tmpbuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(argv[1]) + 9 ];
00036 ifd = open(argv[1], O_RDONLY|O_BINARY);
00037 sprintf(tmpbuf, <font class="stringliteral">"%s.vss"</font>, argv[1]);
00038 ixfd = open(tmpbuf, O_RDONLY|O_BINARY);
00039 sprintf(tmpbuf, <font class="stringliteral">"%s.zzz"</font>, argv[1]);
00040 ofd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
00041 sprintf(tmpbuf, <font class="stringliteral">"%s.zzz.vss"</font>, argv[1]);
00042 oxfd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
00043
00044 <font class="keyword">delete</font> [] tmpbuf;
00045
00046 printf(<font class="stringliteral">"\n"</font>);
00047
00048 <font class="keywordflow">while</font> (1) {
00049 <font class="keywordflow">if</font> (read(ixfd, &offset, 4) != 4)
00050 <font class="keywordflow">break</font>;
00051 <font class="keywordflow">if</font> (read(ixfd, &size, 2) != 2)
00052 <font class="keywordflow">break</font>;
00053
00054 <font class="keywordflow">if</font> ((offset == loffset) && (size == lsize)) {
00055 printf(<font class="stringliteral">"using previous offset,size\n"</font>, size);
00056 write(oxfd, &lzoffset, 4);
00057 write(oxfd, &lzsize, 2);
00058 }
00059 <font class="keywordflow">else</font> {
00060 printf(<font class="stringliteral">"%d -> "</font>, size);
00061 lsize = size;
00062 loffset = offset;
00063
00064 <font class="keywordflow">if</font> (size) {
00065 tmpbuf = (<font class="keywordtype">char</font> *) calloc(size + 1, 1);
00066 lseek(ifd, offset, SEEK_SET);
00067 read(ifd, tmpbuf, size);
00068 zobj->Buf(tmpbuf);
00069 zobj->zBuf(&size);
00070 free(tmpbuf);
00071 }
00072 offset = lseek(ofd, 0, SEEK_END);
00073 write(oxfd, &offset, 4);
00074 <font class="keywordflow">if</font> (size)
00075 write(ofd, zobj->zBuf(&size), size);
00076 lzoffset = offset;
00077 write(oxfd, &size, 2);
00078 lzsize = size;
00079 printf(<font class="stringliteral">"%d \n"</font>, size);
00080 }
00081 }
00082 <font class="keyword">delete</font> zobj;
00083 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>
|