aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/comments_2zcom_2rawtxt2z_8cpp-source.html
blob: 00c50fef992de9ad86ddf5894d95a4f6ba005fab (plain) (blame)
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> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>rawtxt2z.cpp</h1><div class="fragment"><pre>00001 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00002 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00003 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00004 <font class="preprocessor">#include &lt;errno.h&gt;</font>
00005 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00006 
00007 <font class="preprocessor">#ifndef __GNUC__</font>
00008 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00009 <font class="preprocessor">#else</font>
00010 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00011 <font class="preprocessor">#endif</font>
00012 <font class="preprocessor"></font>
00013 <font class="preprocessor">#include &lt;swcomprs.h&gt;</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 &lt;datafilename&gt;\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, &amp;offset, 4) != 4)
00050                         <font class="keywordflow">break</font>;
00051                 <font class="keywordflow">if</font> (read(ixfd, &amp;size, 2) != 2)
00052                         <font class="keywordflow">break</font>;
00053 
00054                 <font class="keywordflow">if</font> ((offset == loffset) &amp;&amp; (size == lsize)) {
00055                         printf(<font class="stringliteral">"using previous offset,size\n"</font>, size);
00056                         write(oxfd, &amp;lzoffset, 4);
00057                         write(oxfd, &amp;lzsize, 2);
00058                 }
00059                 <font class="keywordflow">else</font> {
00060                         printf(<font class="stringliteral">"%d -&gt; "</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-&gt;Buf(tmpbuf);
00069                                 zobj-&gt;zBuf(&amp;size);
00070                                 free(tmpbuf);
00071                         }
00072                         offset = lseek(ofd, 0, SEEK_END);
00073                         write(oxfd, &amp;offset, 4);
00074                         <font class="keywordflow">if</font> (size) 
00075                                 write(ofd, zobj-&gt;zBuf(&amp;size), size);
00076                         lzoffset = offset;
00077                         write(oxfd, &amp;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>